forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiclient.go
67 lines (59 loc) · 2.6 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
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
NewWorkflowTemplateServiceClient() workflowtemplatepkg.WorkflowTemplateServiceClient
NewClusterWorkflowTemplateServiceClient() clusterworkflowtmplpkg.ClusterWorkflowTemplateServiceClient
NewInfoServiceClient() (infopkg.InfoServiceClient, error)
}
type Opts struct {
ArgoServerOpts ArgoServerOpts
InstanceID string
AuthSupplier func() string
// DEPRECATED: use `ClientConfigSupplier`
ClientConfig clientcmd.ClientConfig
ClientConfigSupplier func() clientcmd.ClientConfig
}
func (o Opts) String() string {
return fmt.Sprintf("(argoServerOpts=%v,instanceID=%v)", o.ArgoServerOpts, o.InstanceID)
}
// 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
},
})
}
func NewClientFromOpts(opts Opts) (context.Context, Client, error) {
log.WithField("opts", opts).Debug("Client options")
if opts.ArgoServerOpts.URL != "" && opts.InstanceID != "" {
return nil, nil, fmt.Errorf("cannot use instance ID with Argo Server")
}
if opts.ArgoServerOpts.HTTP1 {
return newHTTP1Client(opts.ArgoServerOpts.GetURL(), opts.AuthSupplier(), opts.ArgoServerOpts.InsecureSkipVerify)
} else if opts.ArgoServerOpts.URL != "" {
return newArgoServerClient(opts.ArgoServerOpts, opts.AuthSupplier())
} else {
if opts.ClientConfigSupplier != nil {
opts.ClientConfig = opts.ClientConfigSupplier()
}
return newArgoKubeClient(opts.ClientConfig, instanceid.NewService(opts.InstanceID))
}
}