template

package
v2.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container is a WorkflowSource that creates a container-based workflow step. It provides a fluent API for configuring containers with common options like commands, arguments, environment variables, and resource requests.

Example:

deploy := template.NewContainer("deploy", "myapp:v1").
    Command("deploy.sh").
    Args("--env", "production").
    Env("DATABASE_URL", "postgres://...").
    CPU("1000m").
    Memory("512Mi")

func NewContainer

func NewContainer(name, image string, opts ...ContainerOption) *Container

NewContainer creates a new container workflow source.

Parameters:

  • name: Step name (used in workflow step definition)
  • image: Container image (e.g., "alpine:latest", "myapp:v1")
  • opts: Optional configuration functions

Example:

container := template.NewContainer("deploy", "myapp:v1",
    template.WithCommand("deploy.sh"),
    template.WithArgs("--env", "production"),
    template.WithOTelConfig(otelConfig))

func (*Container) Args

func (c *Container) Args(args ...string) *Container

Args sets the container arguments. Can be called multiple times or with multiple arguments.

Example:

container.Args("--port", "8080", "--host", "0.0.0.0")

func (*Container) CPU

func (c *Container) CPU(request string, limit ...string) *Container

CPU sets CPU request and limit.

Example:

container.CPU("500m")  // request and limit
container.CPU("500m", "1000m")  // request and limit separately

func (*Container) Command

func (c *Container) Command(cmd ...string) *Container

Command sets the container command (entrypoint override). Can be called multiple times or with multiple arguments.

Example:

container.Command("python", "app.py")
// or
container.Command("python").Command("app.py")

func (*Container) ContinueOn

func (c *Container) ContinueOn(continueOn *v1alpha1.ContinueOn) *Container

ContinueOn sets the step to continue on specific conditions.

Example:

container.ContinueOn(&v1alpha1.ContinueOn{
    Failed: true,  // continue even if step fails
})

func (*Container) Env

func (c *Container) Env(name, value string) *Container

Env adds an environment variable to the container.

Example:

container.Env("DATABASE_URL", "postgres://...").
    Env("LOG_LEVEL", "debug")

func (*Container) EnvFrom

func (c *Container) EnvFrom(name string, source corev1.EnvVarSource) *Container

EnvFrom adds an environment variable from a source (ConfigMap or Secret).

Example:

container.EnvFrom("API_KEY", corev1.EnvVarSource{
    SecretKeyRef: &corev1.SecretKeySelector{
        LocalObjectReference: corev1.LocalObjectReference{Name: "api-secrets"},
        Key: "api-key",
    },
})

func (*Container) ImagePullPolicy

func (c *Container) ImagePullPolicy(policy corev1.PullPolicy) *Container

ImagePullPolicy sets the image pull policy.

Example:

container.ImagePullPolicy(corev1.PullAlways)

func (*Container) Memory

func (c *Container) Memory(request string, limit ...string) *Container

Memory sets memory request and limit.

Example:

container.Memory("256Mi")  // request and limit
container.Memory("256Mi", "512Mi")  // request and limit separately

func (*Container) Steps

func (c *Container) Steps() ([]v1alpha1.WorkflowStep, error)

Steps implements WorkflowSource interface.

func (*Container) Templates

func (c *Container) Templates() ([]v1alpha1.Template, error)

Templates implements WorkflowSource interface.

func (*Container) VolumeMount

func (c *Container) VolumeMount(name, mountPath string, readOnly bool) *Container

VolumeMount adds a volume mount to the container.

Example:

container.VolumeMount("config", "/etc/config", true)

func (*Container) When

func (c *Container) When(condition string) *Container

When sets a conditional expression for when this step should run.

Example:

container.When("{{workflow.status}} == Succeeded")

func (*Container) WithRetry

func (c *Container) WithRetry(retry *v1alpha1.RetryStrategy) *Container

WithRetry sets a retry strategy for this specific step.

Example:

container.WithRetry(&v1alpha1.RetryStrategy{
    Limit: intstr.FromInt(3),
    RetryPolicy: "Always",
})

func (*Container) WorkingDir

func (c *Container) WorkingDir(dir string) *Container

WorkingDir sets the working directory for the container.

Example:

container.WorkingDir("/app")

type ContainerOption

type ContainerOption func(*Container)

ContainerOption is a functional option for configuring Container.

func WithArgs

func WithArgs(args ...string) ContainerOption

WithArgs sets the container arguments.

func WithCPU

func WithCPU(request string, limit ...string) ContainerOption

WithCPU sets CPU request and limit.

func WithCommand

func WithCommand(cmd ...string) ContainerOption

WithCommand sets the container command.

func WithEnv

func WithEnv(name, value string) ContainerOption

WithEnv adds an environment variable.

func WithImagePullPolicy

func WithImagePullPolicy(policy corev1.PullPolicy) ContainerOption

WithImagePullPolicy sets the image pull policy.

func WithMemory

func WithMemory(request string, limit ...string) ContainerOption

WithMemory sets memory request and limit.

func WithOTelConfig

func WithOTelConfig(cfg *otel.Config) ContainerOption

WithOTelConfig enables OpenTelemetry instrumentation.

func WithWhen

func WithWhen(condition string) ContainerOption

WithWhen sets a conditional expression.

func WithWorkingDir

func WithWorkingDir(dir string) ContainerOption

WithWorkingDir sets the working directory.

type HTTP

type HTTP struct {
	// contains filtered or unexported fields
}

HTTP is a WorkflowSource that creates an HTTP request workflow step. It's useful for making API calls, health checks, or webhooks.

Example:

http := template.NewHTTP("health-check").
    URL("https://myapp/health").
    Method("GET").
    SuccessCond("response.statusCode >= 200 && response.statusCode < 300")

func NewHTTP

func NewHTTP(name string, opts ...HTTPOption) *HTTP

NewHTTP creates a new HTTP workflow source.

Parameters:

  • name: Step name
  • opts: Optional configuration functions

Example:

http := template.NewHTTP("api-call",
    template.WithHTTPURL("https://api.example.com/v1/resource"),
    template.WithHTTPMethod("POST"),
    template.WithHTTPBody(`{"key": "value"}`))

func (*HTTP) Body

func (h *HTTP) Body(body string) *HTTP

Body sets the HTTP request body.

Example:

http.Body(`{"status": "complete"}`)

func (*HTTP) Header

func (h *HTTP) Header(name, value string) *HTTP

Header adds an HTTP header.

Example:

http.Header("Content-Type", "application/json").
    Header("Authorization", "Bearer {{workflow.parameters.token}}")

func (*HTTP) Method

func (h *HTTP) Method(method string) *HTTP

Method sets the HTTP method.

Example:

http.Method("POST")

func (*HTTP) Steps

func (h *HTTP) Steps() ([]v1alpha1.WorkflowStep, error)

Steps implements WorkflowSource interface.

func (*HTTP) SuccessCondition

func (h *HTTP) SuccessCondition(cond string) *HTTP

SuccessCondition sets the condition for considering the request successful.

Example:

http.SuccessCondition("response.statusCode == 200")

func (*HTTP) Templates

func (h *HTTP) Templates() ([]v1alpha1.Template, error)

Templates implements WorkflowSource interface.

func (*HTTP) Timeout

func (h *HTTP) Timeout(seconds int32) *HTTP

Timeout sets the request timeout in seconds.

Example:

http.Timeout(60) // 60 seconds

func (*HTTP) URL

func (h *HTTP) URL(url string) *HTTP

URL sets the HTTP URL.

Example:

http.URL("https://api.example.com/health")

func (*HTTP) When

func (h *HTTP) When(condition string) *HTTP

When sets a conditional expression.

Example:

http.When("{{workflow.status}} == Succeeded")

type HTTPOption

type HTTPOption func(*HTTP)

HTTPOption is a functional option for configuring HTTP.

func WithHTTPBody

func WithHTTPBody(body string) HTTPOption

WithHTTPBody sets the request body.

func WithHTTPHeader

func WithHTTPHeader(name, value string) HTTPOption

WithHTTPHeader adds a header.

func WithHTTPMethod

func WithHTTPMethod(method string) HTTPOption

WithHTTPMethod sets the HTTP method.

func WithHTTPOTelConfig

func WithHTTPOTelConfig(cfg *otel.Config) HTTPOption

WithHTTPOTelConfig enables OpenTelemetry instrumentation.

func WithHTTPSuccessCond

func WithHTTPSuccessCond(cond string) HTTPOption

WithHTTPSuccessCond sets the success condition.

func WithHTTPTimeout

func WithHTTPTimeout(seconds int32) HTTPOption

WithHTTPTimeout sets the timeout.

func WithHTTPURL

func WithHTTPURL(url string) HTTPOption

WithHTTPURL sets the URL.

type Noop

type Noop struct {
	// contains filtered or unexported fields
}

Noop is a no-operation workflow source that produces a single step that does nothing. This is useful as a placeholder or for testing workflow structures.

Example:

noop := template.NewNoop()
builder.Add(noop)

func NewNoop

func NewNoop() *Noop

NewNoop creates a new no-op workflow source. The step will print "noop" to demonstrate execution.

Example:

noop := template.NewNoop()
wf, err := builder.NewWorkflowBuilder("test", "argo").
    Add(noop).
    Build()

func NewNoopWithName

func NewNoopWithName(name string) *Noop

NewNoopWithName creates a no-op workflow source with a custom name. Useful when you need multiple no-op steps with different names.

Example:

placeholder1 := template.NewNoopWithName("placeholder-1")
placeholder2 := template.NewNoopWithName("placeholder-2")

func (*Noop) Steps

func (n *Noop) Steps() ([]v1alpha1.WorkflowStep, error)

Steps implements WorkflowSource interface. Returns a single step that references the no-op template.

func (*Noop) Templates

func (n *Noop) Templates() ([]v1alpha1.Template, error)

Templates implements WorkflowSource interface. Returns a simple container template that prints "noop".

type Script

type Script struct {
	// contains filtered or unexported fields
}

Script is a WorkflowSource that creates a script-based workflow step. It's useful for running inline scripts in various languages (bash, python, etc.).

Example:

script := template.NewScript("backup", "bash").
    Script("tar -czf /backup/data.tar.gz /data").
    Env("BACKUP_DIR", "/backup")

func NewScript

func NewScript(name, language string, opts ...ScriptOption) *Script

NewScript creates a new script workflow source. The image should contain the interpreter for the script language.

Parameters:

  • name: Step name
  • language: Script language ("bash", "python", "sh", etc.) - determines the default image
  • opts: Optional configuration functions

Example:

script := template.NewScript("process", "python",
    template.WithScriptContent("print('Processing data...')"),
    template.WithScriptEnv("API_KEY", "secret"))

func (*Script) CPU

func (s *Script) CPU(request string, limit ...string) *Script

CPU sets CPU request and limit.

Example:

script.CPU("500m", "1000m")

func (*Script) Command

func (s *Script) Command(cmd ...string) *Script

Command overrides the default command.

Example:

script.Command("python3", "-u")

func (*Script) Env

func (s *Script) Env(name, value string) *Script

Env adds an environment variable.

Example:

script.Env("LOG_LEVEL", "debug")

func (*Script) Image

func (s *Script) Image(image string) *Script

Image overrides the default image for the script.

Example:

script.Image("custom/python:3.11")

func (*Script) Memory

func (s *Script) Memory(request string, limit ...string) *Script

Memory sets memory request and limit.

Example:

script.Memory("256Mi", "512Mi")

func (*Script) Script

func (s *Script) Script(content string) *Script

Script sets the inline script content.

Example:

script.Script("echo 'Hello, World!'")

func (*Script) Source

func (s *Script) Source(source string) *Script

Source sets the script source (from artifact or configmap).

Example:

script.Source("{{inputs.artifacts.script}}")

func (*Script) Steps

func (s *Script) Steps() ([]v1alpha1.WorkflowStep, error)

Steps implements WorkflowSource interface.

func (*Script) Templates

func (s *Script) Templates() ([]v1alpha1.Template, error)

Templates implements WorkflowSource interface.

func (*Script) VolumeMount

func (s *Script) VolumeMount(name, mountPath string, readOnly bool) *Script

VolumeMount adds a volume mount.

Example:

script.VolumeMount("data", "/data", false)

func (*Script) When

func (s *Script) When(condition string) *Script

When sets a conditional expression.

Example:

script.When("{{workflow.status}} == Succeeded")

func (*Script) WorkingDir

func (s *Script) WorkingDir(dir string) *Script

WorkingDir sets the working directory.

Example:

script.WorkingDir("/workspace")

type ScriptOption

type ScriptOption func(*Script)

ScriptOption is a functional option for configuring Script.

func WithScriptCommand

func WithScriptCommand(cmd ...string) ScriptOption

WithScriptCommand sets the command.

func WithScriptContent

func WithScriptContent(content string) ScriptOption

WithScriptContent sets the script content.

func WithScriptEnv

func WithScriptEnv(name, value string) ScriptOption

WithScriptEnv adds an environment variable.

func WithScriptImage

func WithScriptImage(image string) ScriptOption

WithScriptImage sets the container image.

func WithScriptOTelConfig

func WithScriptOTelConfig(cfg *otel.Config) ScriptOption

WithScriptOTelConfig enables OpenTelemetry instrumentation.

func WithScriptWorkingDir

func WithScriptWorkingDir(dir string) ScriptOption

WithScriptWorkingDir sets the working directory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL