Documentation
¶
Index ¶
- func DeleteWorkflow(ctx context.Context, client apiclient.Client, namespace, name string, ...) error
- func GetWorkflowStatus(ctx context.Context, client apiclient.Client, namespace, name string, ...) (*v1alpha1.WorkflowStatus, error)
- func ListWorkflows(ctx context.Context, client apiclient.Client, namespace, labelSelector string, ...) ([]v1alpha1.Workflow, error)
- func NewClient(ctx context.Context, config *Config) (context.Context, apiclient.Client, error)
- func NewClientWithOptions(ctx context.Context, opts ...Option) (context.Context, apiclient.Client, error)
- func SubmitAndWait(ctx context.Context, client apiclient.Client, wf *v1alpha1.Workflow, ...) (*v1alpha1.Workflow, error)
- func SubmitWorkflow(ctx context.Context, client apiclient.Client, wf *v1alpha1.Workflow, ...) (*v1alpha1.Workflow, error)
- type Config
- type Option
- func WithArgoServer(url, authToken string) Option
- func WithArgoServerHTTP1(http1 bool) Option
- func WithArgoServerInsecure(insecure bool) Option
- func WithArgoServerOpts(opts ServerOpts) Option
- func WithConfig(config *Config) Option
- func WithContext(context string) Option
- func WithInCluster(inCluster bool) Option
- func WithKubeConfig(path string) Option
- func WithOTelConfig(otelConfig *otel.Config) Option
- type ServerOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteWorkflow ¶ added in v2.2.4
func DeleteWorkflow(ctx context.Context, client apiclient.Client, namespace, name string, cfg *otel.Config) error
DeleteWorkflow deletes a workflow by name.
Example:
err := argo.DeleteWorkflow(ctx, client, "argo", "my-workflow-abc123", otelConfig)
if err != nil {
return err
}
func GetWorkflowStatus ¶ added in v2.2.4
func GetWorkflowStatus(ctx context.Context, client apiclient.Client, namespace, name string, cfg *otel.Config) (*v1alpha1.WorkflowStatus, error)
GetWorkflowStatus retrieves the current status of a workflow.
Example:
status, err := argo.GetWorkflowStatus(ctx, client, "argo", "my-workflow-abc123", otelConfig)
if err != nil {
return err
}
fmt.Printf("Workflow phase: %s\n", status.Phase)
func ListWorkflows ¶ added in v2.2.4
func ListWorkflows(ctx context.Context, client apiclient.Client, namespace, labelSelector string, cfg *otel.Config) ([]v1alpha1.Workflow, error)
ListWorkflows lists workflows in a namespace with optional label selector.
Example:
// List all workflows workflows, err := argo.ListWorkflows(ctx, client, "argo", "", otelConfig) // List workflows with label workflows, err := argo.ListWorkflows(ctx, client, "argo", "app=myapp", otelConfig)
func NewClient ¶
NewClient creates a new Argo Workflows client from the given configuration. It returns the updated context and client, or an error if the connection fails.
The client can connect to Argo Workflows in two modes: 1. Via Kubernetes API (default) - uses kubeconfig or in-cluster config 2. Via Argo Server - uses HTTP/HTTPS connection
Example (default kubeconfig):
ctx, client, err := argo.NewClient(ctx, argo.DefaultConfig())
if err != nil {
return err
}
defer client.Close()
Example (in-cluster):
ctx, client, err := argo.NewClient(ctx, argo.InClusterConfig())
Example (Argo Server):
cfg := argo.ServerConfig("https://argo-server:2746", "Bearer token")
ctx, client, err := argo.NewClient(ctx, cfg)
func NewClientWithOptions ¶
func NewClientWithOptions(ctx context.Context, opts ...Option) (context.Context, apiclient.Client, error)
NewClientWithOptions creates a new Argo Workflows client using functional options. This provides a more flexible way to configure the client.
Example:
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithKubeConfig("/custom/path/kubeconfig"),
argo.WithContext("production"),
argo.WithOTelConfig(otelConfig),
)
func SubmitAndWait ¶ added in v2.2.4
func SubmitAndWait(ctx context.Context, client apiclient.Client, wf *v1alpha1.Workflow, cfg *otel.Config, timeout time.Duration) (*v1alpha1.Workflow, error)
SubmitAndWait submits a workflow and waits for it to complete. It polls the workflow status at regular intervals and returns when the workflow reaches a terminal state (Succeeded, Failed, or Error).
Example:
wf, err := builder.NewWorkflowBuilder("backup", "argo").
Add(backupStep).
Build()
if err != nil {
return err
}
completed, err := argo.SubmitAndWait(ctx, client, wf, otelConfig, 10*time.Minute)
if err != nil {
return err
}
if completed.Status.Phase == v1alpha1.WorkflowSucceeded {
fmt.Println("Workflow completed successfully")
}
func SubmitWorkflow ¶ added in v2.2.4
func SubmitWorkflow(ctx context.Context, client apiclient.Client, wf *v1alpha1.Workflow, cfg *otel.Config) (*v1alpha1.Workflow, error)
SubmitWorkflow submits a workflow to Argo with OpenTelemetry tracing. This is a convenience wrapper around the Argo API client with better error handling and automatic observability.
Example:
wf, err := builder.NewWorkflowBuilder("deploy", "argo").
Add(deployStep).
Build()
if err != nil {
return err
}
created, err := argo.SubmitWorkflow(ctx, client, wf, otelConfig)
if err != nil {
return err
}
fmt.Printf("Workflow %s submitted\n", created.Name)
Types ¶
type Config ¶
type Config struct {
// KubeConfigPath specifies the path to kubeconfig file.
// Empty string means:
// - Use in-cluster config if InCluster is true
// - Use default kubeconfig location (~/.kube/config) if InCluster is false
KubeConfigPath string `yaml:"kubeConfigPath" mapstructure:"kubeConfigPath"`
// Context specifies the kubeconfig context to use.
// Empty string means use the current context.
Context string `yaml:"context" mapstructure:"context"`
// InCluster indicates whether to use in-cluster Kubernetes configuration.
// When true, the client will use the service account token mounted in the pod.
InCluster bool `yaml:"inCluster" mapstructure:"inCluster"`
// ArgoServerOpts configures connection to Argo Server (alternative to direct k8s API).
// If URL is set, the client will connect via Argo Server instead of k8s API.
ArgoServerOpts ServerOpts `yaml:"argoServer" mapstructure:"argoServer"`
// OTelConfig enables OpenTelemetry instrumentation (optional).
OTelConfig *otel.Config `yaml:"-"`
}
Config represents the configuration for connecting to Argo Workflows. It supports multiple connection modes: - Kubernetes API (in-cluster or with kubeconfig) - Argo Server (HTTP/HTTPS with optional authentication)
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with sensible defaults. By default, it uses: - Out-of-cluster mode (InCluster = false) - Default kubeconfig location (~/.kube/config) - Current context from kubeconfig
func InClusterConfig ¶
func InClusterConfig() *Config
InClusterConfig returns a Config for in-cluster usage. This is useful when the client runs inside a Kubernetes pod.
func ServerConfig ¶ added in v2.2.3
ServerConfig returns a Config for connecting via Argo Server. This is an alternative to direct Kubernetes API access.
type Option ¶
Option is a functional option for configuring Argo client.
func WithArgoServer ¶
WithArgoServer configures the client to connect via Argo Server instead of Kubernetes API. This is an alternative connection mode that uses HTTP/HTTPS.
Example:
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithArgoServer("https://argo-server:2746", "Bearer token"),
)
func WithArgoServerHTTP1 ¶
WithArgoServerHTTP1 forces HTTP/1.1 instead of HTTP/2 for Argo Server connection. This can be useful for debugging or compatibility reasons.
Example:
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithArgoServer("https://argo-server:2746", "Bearer token"),
argo.WithArgoServerHTTP1(true),
)
func WithArgoServerInsecure ¶
WithArgoServerInsecure enables insecure mode for Argo Server connection. This disables TLS certificate verification. WARNING: This should only be used in development/testing environments.
Example:
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithArgoServer("http://argo-server:2746", ""),
argo.WithArgoServerInsecure(true),
)
func WithArgoServerOpts ¶
func WithArgoServerOpts(opts ServerOpts) Option
WithArgoServerOpts sets the complete ServerOpts configuration. This is useful when you want to configure all Argo Server options at once.
Example:
serverOpts := argo.ServerOpts{
URL: "https://argo-server:2746",
AuthToken: "Bearer token",
InsecureSkipVerify: false,
HTTP1: false,
}
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithArgoServerOpts(serverOpts),
)
func WithConfig ¶
WithConfig applies a complete Config to the client. This is useful when you have a pre-built configuration from a config file.
Example:
config := &argo.Config{
KubeConfigPath: "/custom/kubeconfig",
Context: "production",
}
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithConfig(config),
)
func WithContext ¶
WithContext sets the kubeconfig context to use. If not set, the current context from kubeconfig will be used.
Example:
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithContext("production"),
)
func WithInCluster ¶
WithInCluster enables in-cluster configuration mode. When true, the client will use the service account token mounted in the pod. This is useful when running inside a Kubernetes cluster.
Example:
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithInCluster(true),
)
func WithKubeConfig ¶
WithKubeConfig sets the path to the kubeconfig file. If not set, the default location (~/.kube/config) will be used.
Example:
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithKubeConfig("/custom/path/to/kubeconfig"),
)
func WithOTelConfig ¶
WithOTelConfig enables OpenTelemetry instrumentation for the Argo client. This allows tracing and monitoring of workflow operations.
Example:
otelConfig := otel.NewConfig("my-service").
WithTracerProvider(tracerProvider).
WithMeterProvider(meterProvider)
ctx, client, err := argo.NewClientWithOptions(ctx,
argo.WithOTelConfig(otelConfig),
)
type ServerOpts ¶ added in v2.2.3
type ServerOpts struct {
// URL is the Argo Server base URL (e.g., "https://argo-server:2746")
URL string `yaml:"url" mapstructure:"url"`
// AuthToken is the bearer token for authentication (optional)
AuthToken string `yaml:"authToken" mapstructure:"authToken"`
// InsecureSkipVerify disables TLS certificate verification (not recommended for production)
InsecureSkipVerify bool `yaml:"insecureSkipVerify" mapstructure:"insecureSkipVerify"`
// HTTP1 forces HTTP/1.1 instead of HTTP/2
HTTP1 bool `yaml:"http1" mapstructure:"http1"`
}
ServerOpts contains Argo Server connection options. This is used when connecting via Argo Server HTTP API instead of direct Kubernetes API.