| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package client
- import (
- "context"
- "github.com/argoproj/argo-workflows/v3/pkg/apiclient"
- "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflow"
- "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflowtemplate"
- "github.com/pkg/errors"
- "k8s.io/client-go/tools/clientcmd"
- "os"
- )
- type Client struct {
- ctx context.Context
- client apiclient.Client
- workflowTemplateService workflowtemplate.WorkflowTemplateServiceClient
- workflowService workflow.WorkflowServiceClient
- }
- func NewClient(kubeConfigEnv string) (*Client, error) {
- err := os.Setenv("KUBECONFIG", kubeConfigEnv)
- if err != nil {
- return nil, errors.New(err.Error())
- }
- apiClientCtx, apiClient, err := apiclient.NewClientFromOpts(apiclient.Opts{
- ArgoServerOpts: apiclient.ArgoServerOpts{},
- ClientConfigSupplier: func() clientcmd.ClientConfig {
- return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(clientcmd.NewDefaultClientConfigLoadingRules(), nil)
- },
- Context: context.Background(),
- })
- if err != nil {
- return nil, errors.New(err.Error())
- }
- workflowTemplateService, err := apiClient.NewWorkflowTemplateServiceClient()
- if err != nil {
- return nil, errors.New(err.Error())
- }
- return &Client{
- ctx: apiClientCtx,
- client: apiClient,
- workflowTemplateService: workflowTemplateService,
- workflowService: apiClient.NewWorkflowServiceClient(),
- }, nil
- }
|