-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
apiclient.go
90 lines (79 loc) · 3.31 KB
/
apiclient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package apiclient
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/tools/clientcmd"
clusterworkflowtmplpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/clusterworkflowtemplate"
cronworkflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/cronworkflow"
infopkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/info"
workflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflow"
workflowarchivepkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflowarchive"
workflowtemplatepkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflowtemplate"
"github.com/argoproj/argo-workflows/v3/util/instanceid"
)
type Client interface {
NewArchivedWorkflowServiceClient() (workflowarchivepkg.ArchivedWorkflowServiceClient, error)
NewWorkflowServiceClient() workflowpkg.WorkflowServiceClient
NewCronWorkflowServiceClient() (cronworkflowpkg.CronWorkflowServiceClient, error)
NewWorkflowTemplateServiceClient() (workflowtemplatepkg.WorkflowTemplateServiceClient, error)
NewClusterWorkflowTemplateServiceClient() (clusterworkflowtmplpkg.ClusterWorkflowTemplateServiceClient, error)
NewInfoServiceClient() (infopkg.InfoServiceClient, error)
}
type Opts struct {
ArgoServerOpts ArgoServerOpts
InstanceID string
AuthSupplier func() string
// DEPRECATED: use `ClientConfigSupplier`
ClientConfig clientcmd.ClientConfig
ClientConfigSupplier func() clientcmd.ClientConfig
Offline bool
OfflineFiles []string
Context context.Context
}
func (o Opts) String() string {
return fmt.Sprintf("(argoServerOpts=%v,instanceID=%v)", o.ArgoServerOpts, o.InstanceID)
}
func (o *Opts) GetContext() context.Context {
if o.Context == nil {
o.Context = context.Background()
}
return o.Context
}
// DEPRECATED: use NewClientFromOpts
func NewClient(argoServer string, authSupplier func() string, clientConfig clientcmd.ClientConfig) (context.Context, Client, error) {
return NewClientFromOpts(Opts{
ArgoServerOpts: ArgoServerOpts{URL: argoServer},
AuthSupplier: authSupplier,
ClientConfigSupplier: func() clientcmd.ClientConfig {
return clientConfig
},
Context: context.Background(),
})
}
func NewClientFromOpts(opts Opts) (context.Context, Client, error) {
log.WithField("opts", opts).Debug("Client options")
if opts.Offline {
return newOfflineClient(opts.OfflineFiles)
}
if opts.ArgoServerOpts.URL != "" && opts.InstanceID != "" {
return nil, nil, fmt.Errorf("cannot use instance ID with Argo Server")
}
if opts.ArgoServerOpts.HTTP1 {
if opts.AuthSupplier == nil {
return nil, nil, fmt.Errorf("AuthSupplier cannot be empty when connecting to Argo Server")
}
return newHTTP1Client(opts.ArgoServerOpts.GetURL(), opts.AuthSupplier(), opts.ArgoServerOpts.InsecureSkipVerify, opts.ArgoServerOpts.Headers, opts.ArgoServerOpts.HTTP1Client)
} else if opts.ArgoServerOpts.URL != "" {
if opts.AuthSupplier == nil {
return nil, nil, fmt.Errorf("AuthSupplier cannot be empty when connecting to Argo Server")
}
return newArgoServerClient(opts.ArgoServerOpts, opts.AuthSupplier())
} else {
if opts.ClientConfigSupplier != nil {
opts.ClientConfig = opts.ClientConfigSupplier()
}
ctx, client, err := newArgoKubeClient(opts.GetContext(), opts.ClientConfig, instanceid.NewService(opts.InstanceID))
return ctx, client, err
}
}