pipeline

package
v0.0.0-...-de72fe1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHelmCmd    = "helm"
	DefaultYttCmd     = "ytt"
	DefaultKubectlCmd = "kubectl"
)

Default tool commands.

View Source
const (
	EnvHelmCmd    = "BEAVER_HELM_CMD"
	EnvYttCmd     = "BEAVER_YTT_CMD"
	EnvKubectlCmd = "BEAVER_KUBECTL_CMD"
)

Environment variable names for tool paths.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgConfig

type ArgConfig struct {
	Flag  string
	Value string
}

ArgConfig represents a command argument.

type BoolParser

type BoolParser interface {
	ToBool(s string) (bool, error)
}

BoolParser parses string values to booleans.

type BuildConfig

type BuildConfig struct {
	// TmpDir is the temporary directory for intermediate files
	TmpDir string
	// PreBuildDir is where compiled charts are stored before final output
	PreBuildDir string
	// Logger for structured logging
	Logger zerolog.Logger
	// DryRun indicates if we should skip actual file operations
	DryRun bool
	// WithoutHydrate indicates if hydration should be skipped
	WithoutHydrate bool
}

BuildConfig holds immutable configuration for the build pipeline. These values are set once at pipeline creation and never change.

func NewBuildConfig

func NewBuildConfig(tmpDir, preBuildDir string, logger zerolog.Logger, dryRun, withoutHydrate bool) *BuildConfig

NewBuildConfig creates a new immutable build configuration.

type BuildState

type BuildState struct {
	// OutputDir is the final output directory (determined during execution)
	OutputDir string
	// Variables holds the resolved variables for hydration
	Variables map[string]interface{}
	// CompiledFiles holds paths to compiled chart outputs
	CompiledFiles []string
	// YttOutput holds the output file from ytt processing
	YttOutput *os.File
	// KustomizeOutput holds the output file from kustomize processing
	KustomizeOutput *os.File
}

BuildState holds mutable state that flows through the build pipeline. Each stage can read and modify this state.

func NewBuildState

func NewBuildState() *BuildState

NewBuildState creates a new mutable build state.

func (*BuildState) Close

func (s *BuildState) Close() error

Close releases any resources held by BuildState. It closes any open file handles and returns the first error encountered.

type ChartArgsBuilder

type ChartArgsBuilder interface {
	BuildArgs(chart ChartConfig, name, namespace string) ([]string, error)
}

ChartArgsBuilder builds command arguments for charts.

type ChartConfig

type ChartConfig struct {
	Type        string
	Path        string
	Name        string
	Namespace   string
	Disabled    string
	KubeVersion string
	ValuesFiles []string
}

ChartConfig represents chart configuration needed by stages.

type ChartPathValidator

type ChartPathValidator struct {
	Charts ChartProvider
}

ChartPathValidator validates that chart paths exist.

func (*ChartPathValidator) Validate

func (v *ChartPathValidator) Validate() error

Validate checks that all chart paths exist and are accessible. Chart paths can be either directories or files (for ytt templates).

type ChartProvider

type ChartProvider interface {
	// GetCharts returns the charts configuration
	GetCharts() map[string]ChartConfig
	// SetChartDisabled sets the disabled field of a chart
	SetChartDisabled(name, disabled string)
	// SetChartKubeVersion sets the kube version of a chart
	SetChartKubeVersion(name, kubeVersion string)
}

ChartProvider provides access to chart configuration.

type ChartTypeValidator

type ChartTypeValidator struct {
	Charts ChartProvider
}

ChartTypeValidator validates that chart types are supported.

func (*ChartTypeValidator) Validate

func (v *ChartTypeValidator) Validate() error

Validate checks that all chart types are valid.

type CommandExecutor

type CommandExecutor interface {
	RunCommand(ctx context.Context, tmpDir, name string, cmd *cmd.Cmd) (*os.File, error)
}

CommandExecutor is an interface for executing external commands.

type CompileChartsConfig

type CompileChartsConfig interface {
	ChartProvider
	CreateProvider
	NamespaceProvider
}

CompileChartsConfig provides configuration needed by CompileChartsStage.

type CompileChartsStage

type CompileChartsStage struct {
	Config     CompileChartsConfig
	Executor   CommandExecutor
	HelmCmd    string
	YttCmd     string
	KubectlCmd string
	BoolParser BoolParser
	ChartArgs  ChartArgsBuilder
	CreateArgs CreateArgsBuilder
}

CompileChartsStage compiles charts using helm/ytt.

func (*CompileChartsStage) Execute

func (s *CompileChartsStage) Execute(ctx context.Context, pctx *Context) error

Execute compiles all charts.

func (*CompileChartsStage) Name

func (s *CompileChartsStage) Name() string

Name returns the stage name.

type ComputeShasStage

type ComputeShasStage struct {
	Config      ShaProvider
	ShaComputer ShaComputer
}

ComputeShasStage computes SHA256 hashes for resources.

func (*ComputeShasStage) Execute

func (s *ComputeShasStage) Execute(ctx context.Context, pctx *Context) error

Execute computes SHAs for configured resources.

func (*ComputeShasStage) Name

func (s *ComputeShasStage) Name() string

Name returns the stage name.

type ConfigProvider

ConfigProvider is a composite interface that provides access to all configuration data. This interface is implemented by CmdConfigAdapter and allows passing a single adapter that satisfies all the specific stage configuration interfaces.

type Context

type Context struct {
	// Config holds immutable build configuration
	Config *BuildConfig
	// State holds mutable build state
	State *BuildState
}

Context combines BuildConfig and BuildState for the pipeline. It provides both immutable configuration and mutable state to stages.

func NewContext

func NewContext(config *BuildConfig) *Context

NewContext creates a new pipeline context with the given configuration.

func (*Context) DryRun

func (c *Context) DryRun() bool

DryRun returns whether this is a dry run.

func (*Context) Logger

func (c *Context) Logger() zerolog.Logger

Logger returns the logger.

func (*Context) PreBuildDir

func (c *Context) PreBuildDir() string

PreBuildDir returns the pre-build directory.

func (*Context) TmpDir

func (c *Context) TmpDir() string

TmpDir returns the temporary directory.

func (*Context) WithoutHydrate

func (c *Context) WithoutHydrate() bool

WithoutHydrate returns whether hydration is disabled.

type CreateArgsBuilder

type CreateArgsBuilder interface {
	BuildCreate(key CreateKey, namespace string, args []ArgConfig) []string
}

CreateArgsBuilder builds command arguments for kubectl create commands.

type CreateConfig

type CreateConfig struct {
	Dir  string
	Args []ArgConfig
}

CreateConfig represents create command configuration.

type CreateKey

type CreateKey struct {
	Type string
	Name string
}

CreateKey identifies a create command.

type CreateProvider

type CreateProvider interface {
	// GetCreates returns the create commands configuration
	GetCreates() map[CreateKey]CreateConfig
}

CreateProvider provides access to create commands configuration.

type DirCleaner

type DirCleaner interface {
	CleanDir(directory string) error
}

DirCleaner cleans directories.

type FileCopier

type FileCopier interface {
	Copy(src, dst string) error
}

FileCopier copies files.

type FileHydrator

type FileHydrator interface {
	HydrateFile(input string, output *os.File, variables map[string]interface{}, disabled bool) error
}

FileHydrator hydrates template variables in files.

type HelmDependencyStage

type HelmDependencyStage struct {
	Config HelmDepsProvider
}

HelmDependencyStage fetches helm dependencies.

func (*HelmDependencyStage) Execute

func (s *HelmDependencyStage) Execute(ctx context.Context, pctx *Context) error

Execute fetches helm dependencies.

func (*HelmDependencyStage) Name

func (s *HelmDependencyStage) Name() string

Name returns the stage name.

type HelmDepsProvider

type HelmDepsProvider interface {
	// FetchHelmDeps returns true if helm dependencies should be fetched
	FetchHelmDeps() bool
	// HelmDependencyBuild builds helm dependencies
	HelmDependencyBuild() error
}

HelmDepsProvider provides access to helm dependency operations.

type HydrateOutputStage

type HydrateOutputStage struct {
	Config       OutputProvider
	FileHydrator FileHydrator
	NameHydrator NameHydrator
	DirCleaner   DirCleaner
	StdOutMarker string
}

HydrateOutputStage hydrates the final output files.

func (*HydrateOutputStage) Execute

func (s *HydrateOutputStage) Execute(ctx context.Context, pctx *Context) error

Execute hydrates output files.

func (*HydrateOutputStage) Name

func (s *HydrateOutputStage) Name() string

Name returns the stage name.

type KustomizeStage

type KustomizeStage struct {
	Config         LayerProvider
	Executor       CommandExecutor
	KubectlCmd     string
	FileHydrator   FileHydrator
	FileCopier     FileCopier
	WithoutHydrate bool
}

KustomizeStage applies kustomize patches.

func (*KustomizeStage) Execute

func (s *KustomizeStage) Execute(ctx context.Context, pctx *Context) error

Execute applies kustomize patches.

func (*KustomizeStage) Name

func (s *KustomizeStage) Name() string

Name returns the stage name.

type LayerPathValidator

type LayerPathValidator struct {
	Layers LayerProvider
}

LayerPathValidator validates that layer paths exist.

func (*LayerPathValidator) Validate

func (v *LayerPathValidator) Validate() error

Validate checks that all layer paths exist.

type LayerProvider

type LayerProvider interface {
	// GetLayers returns the configuration layers
	GetLayers() []string
}

LayerProvider provides access to layer configuration.

type NameHydrator

type NameHydrator interface {
	HydrateName(input []byte, output *bytes.Buffer, variables map[string]interface{}) error
}

NameHydrator hydrates template variables in file names.

type NamespaceProvider

type NamespaceProvider interface {
	// GetNamespace returns the current namespace
	GetNamespace() string
	// SetNamespace sets the namespace
	SetNamespace(ns string)
}

NamespaceProvider provides access to namespace configuration.

type OutputProvider

type OutputProvider interface {
	// GetRootDir returns the root directory
	GetRootDir() string
	// GetOutput returns the output directory override
	GetOutput() string
	// IsDryRun returns true if dry run mode is enabled
	IsDryRun() bool
	// IsWithoutHydrate returns true if hydration is disabled
	IsWithoutHydrate() bool
}

OutputProvider provides access to output configuration.

type Pipeline

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

Pipeline orchestrates the execution of multiple stages in sequence.

func New

func New(stages ...Stage) *Pipeline

New creates a new pipeline with the given stages.

func (*Pipeline) AddStage

func (p *Pipeline) AddStage(stage Stage)

AddStage appends a stage to the pipeline.

func (*Pipeline) Run

func (p *Pipeline) Run(ctx context.Context, pctx *Context) error

Run executes all stages in sequence. If any stage fails or the context is canceled, execution stops and the error is returned. Run ensures that any resources held by the pipeline context are properly cleaned up.

func (*Pipeline) Stages

func (p *Pipeline) Stages() []Stage

Stages returns the list of stages in the pipeline.

type PrepareVariablesConfig

type PrepareVariablesConfig interface {
	VariableProvider
	NamespaceProvider
	ChartProvider
	OutputProvider
}

PrepareVariablesConfig provides configuration needed by PrepareVariablesStage.

type PrepareVariablesStage

type PrepareVariablesStage struct {
	Config       PrepareVariablesConfig
	WithShas     bool
	Hydrator     StringHydrator
	HydrateChart bool // If true, also hydrate chart disabled and kubeVersion fields
}

PrepareVariablesStage prepares variables for hydration.

func (*PrepareVariablesStage) Execute

func (s *PrepareVariablesStage) Execute(ctx context.Context, pctx *Context) error

Execute prepares the variables.

func (*PrepareVariablesStage) Name

func (s *PrepareVariablesStage) Name() string

Name returns the stage name.

type ShaComputer

type ShaComputer interface {
	ComputeSha(buildDir string, sha ShaConfig) (string, error)
}

ShaComputer computes SHA256 hashes for resources.

type ShaConfig

type ShaConfig struct {
	Key      string
	Resource string
	Sha      string
}

ShaConfig represents SHA configuration.

type ShaProvider

type ShaProvider interface {
	// GetShas returns the SHA configurations
	GetShas() []ShaConfig
	// SetSha sets the SHA value for a given key
	SetSha(index int, sha string)
}

ShaProvider provides access to SHA configuration.

type Stage

type Stage interface {
	// Name returns the human-readable name of this stage
	Name() string
	// Execute performs the stage's work using the provided context.
	// The context.Context can be used for cancelation and timeouts.
	Execute(ctx context.Context, pctx *Context) error
}

Stage represents a single step in the build pipeline. Each stage receives a context, performs its work, and returns an error if it fails.

type StringHydrator

type StringHydrator interface {
	HydrateString(input string, output *bytes.Buffer, variables map[string]interface{}) error
}

StringHydrator hydrates template variables in strings.

type ToolConfig

type ToolConfig struct {
	Name    string
	Command string
}

ToolConfig represents an external tool to validate.

type ToolRegistry

type ToolRegistry struct {
	Helm    string
	Ytt     string
	Kubectl string
}

ToolRegistry holds the paths to external tools used by the pipeline. Tool paths can be configured via: 1. Explicit configuration (highest priority). 2. Environment variables (BEAVER_HELM_CMD, BEAVER_YTT_CMD, BEAVER_KUBECTL_CMD). 3. Default values (lowest priority).

func NewToolRegistry

func NewToolRegistry() *ToolRegistry

NewToolRegistry creates a new ToolRegistry with default values. It checks environment variables for overrides.

func NewToolRegistryWithConfig

func NewToolRegistryWithConfig(helm, ytt, kubectl string) *ToolRegistry

NewToolRegistryWithConfig creates a ToolRegistry with explicit configuration. Empty strings in config fall back to environment variables, then defaults.

func (*ToolRegistry) ToToolConfigs

func (r *ToolRegistry) ToToolConfigs() []ToolConfig

ToToolConfigs returns the tool configurations for validation.

type ToolValidator

type ToolValidator struct {
	Tools []ToolConfig
}

ToolValidator validates that required external tools are available.

func (*ToolValidator) Validate

func (v *ToolValidator) Validate() error

Validate checks that all required tools are available in PATH.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation failure with context.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type ValidationStage

type ValidationStage struct {
	Validators []Validator
}

ValidationStage runs all validators before pipeline execution.

func (*ValidationStage) Execute

func (s *ValidationStage) Execute(ctx context.Context, _ *Context) error

Execute runs all validators and returns aggregated errors.

func (*ValidationStage) Name

func (s *ValidationStage) Name() string

Name returns the stage name.

type Validator

type Validator interface {
	// Validate checks the configuration and returns an error if invalid.
	Validate() error
}

Validator validates configuration before pipeline execution.

type VariableProvider

type VariableProvider interface {
	// PrepareVariables prepares and returns the variables map
	PrepareVariables(doSha bool) (map[string]interface{}, error)
}

VariableProvider provides access to variable-related configuration.

type YamlSplitStage

type YamlSplitStage struct {
	Splitter   YamlSplitter
	DirCleaner DirCleaner
}

YamlSplitStage splits the compiled YAML into individual resource files.

func (*YamlSplitStage) Execute

func (s *YamlSplitStage) Execute(ctx context.Context, pctx *Context) error

Execute splits the YAML output.

func (*YamlSplitStage) Name

func (s *YamlSplitStage) Name() string

Name returns the stage name.

type YamlSplitter

type YamlSplitter interface {
	Split(buildDir, inputFile string) ([]string, error)
}

YamlSplitter splits YAML documents into individual files.

type YttProcessStage

type YttProcessStage struct {
	Config   YttProvider
	Executor CommandExecutor
	YttCmd   string
}

YttProcessStage runs ytt on compiled charts.

func (*YttProcessStage) Execute

func (s *YttProcessStage) Execute(ctx context.Context, pctx *Context) error

Execute runs ytt on the compiled files.

func (*YttProcessStage) Name

func (s *YttProcessStage) Name() string

Name returns the stage name.

type YttProvider

type YttProvider interface {
	// GetYtt returns ytt paths
	GetYtt() []string
	// BuildYttArgs builds the ytt command arguments
	BuildYttArgs(paths, compiled []string) []string
}

YttProvider provides access to ytt configuration.

Source Files

  • context.go
  • stage.go
  • stages.go
  • tools.go
  • validation.go

Jump to

Keyboard shortcuts

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