runner

package
v0.0.0-...-675d107 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HelmType = "helm"
	YttType  = "ytt"
)

Variables

View Source
var ErrPathTraversal = errors.New("path traversal detected")

ErrPathTraversal is returned when a path attempts to escape its base directory.

Functions

func BuildChartArgs

func BuildChartArgs(chart pipeline.ChartConfig, name, namespace string) ([]string, error)

BuildChartArgs builds arguments for a chart command based on chart type.

func BuildCreateArgs

func BuildCreateArgs(key pipeline.CreateKey, namespace string, args []pipeline.ArgConfig) []string

BuildCreateArgs builds arguments for a kubectl create command.

func CleanDir

func CleanDir(directory string) error

func ComputeSha

func ComputeSha(buildDir string, sha pipeline.ShaConfig) (string, error)

ComputeSha computes the SHA256 hash of a resource file.

func Copy

func Copy(src, dst string) (err error)

func FindFiles

func FindFiles(layers []string, charts map[string]CmdChart) map[string]CmdChart

func Hydrate

func Hydrate(input []byte, output io.Writer, variables map[string]any) error

Hydrate []byte.

func HydrateFileWrapper

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

HydrateFileWrapper wraps hydrate for use in stages.

func HydrateNameWrapper

func HydrateNameWrapper(input []byte, output *bytes.Buffer, variables map[string]interface{}) error

HydrateNameWrapper wraps Hydrate for filename hydration.

func HydrateScalarNode

func HydrateScalarNode(node *yaml.Node, variables map[string]any) error

HydrateScalarNode a yaml node.

func HydrateString

func HydrateString(input string, output io.Writer, variables map[string]any) error

HydrateString will replace all instance of beaver variables in a given string.

func HydrateStringWrapper

func HydrateStringWrapper(input string, output *bytes.Buffer, variables map[string]interface{}) error

HydrateStringWrapper wraps HydrateString for use in stages.

func HydrateVariables

func HydrateVariables(variables map[string]any) error

func IsContainedPath

func IsContainedPath(basePath, targetPath string) (bool, error)

IsContainedPath checks if targetPath is contained within basePath. Returns true if targetPath is a subdirectory or file within basePath. Both paths are resolved to absolute paths before comparison.

func LookupVariable

func LookupVariable(variables interface{}, name string) (interface{}, bool)

func RunCMD

func RunCMD(c *cmd.Cmd) ([]string, []string, error)

RunCMD runs the given cmd and returns its stdout, stderr and an eventual error.

func RunCMDWithContext

func RunCMDWithContext(ctx context.Context, c *cmd.Cmd) ([]string, []string, error)

RunCMDWithContext runs the given cmd with context support for cancelation. It returns stdout, stderr, and an eventual error.

func SanitizeFilename

func SanitizeFilename(name string) string

SanitizeFilename removes or replaces characters that could be used for path traversal or are invalid in filenames. It allows: alphanumeric, dash, underscore, dot, and template delimiters (<, [, ], >). Template delimiters are preserved because beaver uses <[variable]> syntax for variables that are hydrated later in the pipeline. Path separators and other dangerous characters are replaced with underscores.

func SetVariable

func SetVariable(v interface{}, path []string, value interface{})

func ToBool

func ToBool(s string) (bool, error)

func ValidateContainedPath

func ValidateContainedPath(basePath, targetPath string) error

ValidateContainedPath validates that targetPath stays within basePath. Returns an error if the path escapes the base directory.

func YamlSplit

func YamlSplit(buildDir, inputFile string) ([]string, error)

YamlSplit takes a buildDir and an inputFile it returns a list of yaml documents and an eventual error.

Types

type Arg

type Arg struct {
	// Flag: is a CLI flag, eg. `--from-file`
	Flag string `yaml:"flag"`
	// Value: is the value for this flag, eg. `path/to/my/files`
	Value string `yaml:"value"`
}

Arg define command line arguments.

type Chart

type Chart struct {
	// Type: chart type, can be either `ytt` or `helm`
	Type string `yaml:"type"`
	// Path: relative path to the chart itself
	Path string `yaml:"path"`
	// Name: overwrite helm application name
	Name string `yaml:"name"`
	// Namespace: will be pass to helm as parameter (helm only)
	Namespace string `yaml:"namespace"`
	// Disabled: disable this chart
	// This can be useful when inheriting the chart
	// must be castable to bool (0,1,true,false)
	Disabled string `yaml:"disabled"`
	// KubeVersion: kubernetes version to use for helm template (helm only)
	KubeVersion string `yaml:"kubeversion"`
}

Chart define a chart to compile.

type CmdChart

type CmdChart struct {
	Type      string
	Path      string
	Name      string
	Namespace string
	// Must be castable into bool (0,1,true,false).
	Disabled        string
	ValuesFileNames []string
	KubeVersion     string
}

func CmdChartFromChart

func CmdChartFromChart(c Chart) CmdChart

func (CmdChart) BuildArgs

func (c CmdChart) BuildArgs(n, ns string) ([]string, error)

BuildArgs is in charge of producing the argument list to be provided to the cmd.

type CmdCharts

type CmdCharts map[string]CmdChart

type CmdConfig

type CmdConfig struct {
	Spec           CmdSpec
	RootDir        string
	Layers         []string
	Namespace      string
	Logger         zerolog.Logger
	DryRun         bool
	WithoutHydrate bool
	Output         string
	FetchHelmDeps  bool
	Tools          Tools
}

func NewCmdConfig

func NewCmdConfig(opts CmdConfigOptions) *CmdConfig

func (*CmdConfig) BuildYttArgs

func (c *CmdConfig) BuildYttArgs(paths, compiled []string) []string

func (*CmdConfig) HasShas

func (c *CmdConfig) HasShas() bool

func (*CmdConfig) HelmBuildDependency

func (c *CmdConfig) HelmBuildDependency(path string) error

func (*CmdConfig) HelmChartsPaths

func (c *CmdConfig) HelmChartsPaths() ([]string, error)

func (*CmdConfig) HelmDependencyBuild

func (c *CmdConfig) HelmDependencyBuild() error

func (*CmdConfig) Initialize

func (c *CmdConfig) Initialize(tmpDir string) error

func (*CmdConfig) MergeVariables

func (c *CmdConfig) MergeVariables(other *Config)

MergeVariables takes a config (from a file, not a cmd one) and import its variables into the current cmdconfig by replacing old ones and adding the new ones.

func (*CmdConfig) PrepareVariables

func (c *CmdConfig) PrepareVariables(doSha bool) (map[string]interface{}, error)

func (*CmdConfig) SetShas

func (c *CmdConfig) SetShas(buildDir string) error

type CmdConfigAdapter

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

CmdConfigAdapter adapts CmdConfig to the ConfigProvider interface.

func NewCmdConfigAdapter

func NewCmdConfigAdapter(config *CmdConfig) *CmdConfigAdapter

NewCmdConfigAdapter creates a new adapter for CmdConfig.

func (*CmdConfigAdapter) BuildYttArgs

func (a *CmdConfigAdapter) BuildYttArgs(paths, compiled []string) []string

BuildYttArgs builds the ytt command arguments.

func (*CmdConfigAdapter) FetchHelmDeps

func (a *CmdConfigAdapter) FetchHelmDeps() bool

FetchHelmDeps returns true if helm dependencies should be fetched.

func (*CmdConfigAdapter) GetCharts

func (a *CmdConfigAdapter) GetCharts() map[string]pipeline.ChartConfig

GetCharts returns the charts configuration.

func (*CmdConfigAdapter) GetCreates

GetCreates returns the create commands configuration.

func (*CmdConfigAdapter) GetLayers

func (a *CmdConfigAdapter) GetLayers() []string

GetLayers returns the configuration layers.

func (*CmdConfigAdapter) GetNamespace

func (a *CmdConfigAdapter) GetNamespace() string

GetNamespace returns the current namespace.

func (*CmdConfigAdapter) GetOutput

func (a *CmdConfigAdapter) GetOutput() string

GetOutput returns the output directory override.

func (*CmdConfigAdapter) GetRootDir

func (a *CmdConfigAdapter) GetRootDir() string

GetRootDir returns the root directory.

func (*CmdConfigAdapter) GetShas

func (a *CmdConfigAdapter) GetShas() []pipeline.ShaConfig

GetShas returns the SHA configurations.

func (*CmdConfigAdapter) GetYtt

func (a *CmdConfigAdapter) GetYtt() []string

GetYtt returns ytt paths.

func (*CmdConfigAdapter) HelmDependencyBuild

func (a *CmdConfigAdapter) HelmDependencyBuild() error

HelmDependencyBuild builds helm dependencies.

func (*CmdConfigAdapter) IsDryRun

func (a *CmdConfigAdapter) IsDryRun() bool

IsDryRun returns true if dry run mode is enabled.

func (*CmdConfigAdapter) IsWithoutHydrate

func (a *CmdConfigAdapter) IsWithoutHydrate() bool

IsWithoutHydrate returns true if hydration is disabled.

func (*CmdConfigAdapter) PrepareVariables

func (a *CmdConfigAdapter) PrepareVariables(doSha bool) (map[string]interface{}, error)

PrepareVariables prepares and returns the variables map.

func (*CmdConfigAdapter) SetChartDisabled

func (a *CmdConfigAdapter) SetChartDisabled(name, disabled string)

SetChartDisabled sets the disabled field of a chart.

func (*CmdConfigAdapter) SetChartKubeVersion

func (a *CmdConfigAdapter) SetChartKubeVersion(name, kubeVersion string)

SetChartKubeVersion sets the kube version of a chart.

func (*CmdConfigAdapter) SetNamespace

func (a *CmdConfigAdapter) SetNamespace(ns string)

SetNamespace sets the namespace.

func (*CmdConfigAdapter) SetSha

func (a *CmdConfigAdapter) SetSha(index int, sha string)

SetSha sets the SHA value for a given index.

type CmdConfigOptions

type CmdConfigOptions struct {
	Logger         zerolog.Logger
	RootDir        string
	ConfigDir      string
	DryRun         bool
	WithoutHydrate bool
	Output         string
	Namespace      string
	FetchHelmDeps  bool
}

CmdConfigOptions holds options for creating a CmdConfig.

type CmdCreate

type CmdCreate struct {
	Dir  string
	Args []Arg
}

type CmdCreateKey

type CmdCreateKey struct {
	Type string
	Name string
}

func (CmdCreateKey) BuildArgs

func (k CmdCreateKey) BuildArgs(namespace string, args []Arg) []string

type CmdSha

type CmdSha struct {
	Key      string
	Resource string
	Sha      string
}

func (*CmdSha) SetSha

func (s *CmdSha) SetSha(buildDir string) error

type CmdSpec

type CmdSpec struct {
	Variables Variables
	Shas      []*CmdSha
	Charts    CmdCharts
	Ytt       Ytt
	Creates   map[CmdCreateKey]CmdCreate
}

type Config

type Config struct {
	// Inherit: relative path to another beaver project
	// a beaver project is a folder with a beaver.yaml file
	Inherit string `yaml:"inherit"`
	// BeaverVersion: the beaver version this config is supposed to work with.
	BeaverVersion string `yaml:"beaverversion"`
	// NameSpace: a kubernetes Namespace, shouldn't be mandatory
	NameSpace string `yaml:"namespace"`
	// Inherits: list of relative path to other beaver projects
	Inherits []string `yaml:"inherits,flow"`
	// Variables: list of beaver variables
	Variables Variables `yaml:"variables,flow"`
	// Sha: list of Sha
	Sha []Sha `yaml:"sha,flow"`
	// Charts: map of charts definitions, where the key is the chart name for beaver values.
	// eg. beaver will use `foo.yaml` for a chart with key `foo`
	Charts map[string]Chart `yaml:"charts,flow"`
	// Creates: list of kubectl create commands
	Creates []Create `yaml:"create,flow"`
	// Tools: custom paths for external tools (helm, ytt, kubectl)
	Tools Tools `yaml:"tools"`
	// Dir: internal use
	Dir string `yaml:"-"` // the directory in which we found the config file
}

Config represent the beaver.yaml config file.

func NewConfig

func NewConfig(configDir string) (*Config, error)

NewConfig returns a *Config.

func (*Config) Absolutize

func (c *Config) Absolutize(dir string) error

Absolutize makes all chart paths absolute.

type Create

type Create struct {
	// Type: of resource you want to create with kubectl, eg. configmap
	Type string `yaml:"type"`
	// Name: resource name
	Name string `yaml:"name"`
	// Args: list of Arg pass to kubectl create command
	Args []Arg `yaml:"args,flow"`
}

Create define kubectl create command invocation.

type DefaultBoolParser

type DefaultBoolParser struct{}

DefaultBoolParser implements pipeline.BoolParser using ToBool.

func (*DefaultBoolParser) ToBool

func (d *DefaultBoolParser) ToBool(s string) (bool, error)

ToBool implements pipeline.BoolParser.

type DefaultChartArgsBuilder

type DefaultChartArgsBuilder struct{}

DefaultChartArgsBuilder implements pipeline.ChartArgsBuilder using BuildChartArgs.

func (*DefaultChartArgsBuilder) BuildArgs

func (d *DefaultChartArgsBuilder) BuildArgs(
	chart pipeline.ChartConfig,
	name, namespace string,
) ([]string, error)

BuildArgs implements pipeline.ChartArgsBuilder.

type DefaultCommandExecutor

type DefaultCommandExecutor struct {
	Logger zerolog.Logger
	DryRun bool
}

DefaultCommandExecutor executes external commands.

func NewCommandExecutor

func NewCommandExecutor(logger zerolog.Logger, dryRun bool) *DefaultCommandExecutor

NewCommandExecutor creates a new command executor.

func (*DefaultCommandExecutor) RunCommand

func (e *DefaultCommandExecutor) RunCommand(ctx context.Context, tmpDir, name string, c *cmd.Cmd) (*os.File, error)

RunCommand executes a command and returns the output file. The context can be used for cancelation.

type DefaultCreateArgsBuilder

type DefaultCreateArgsBuilder struct{}

DefaultCreateArgsBuilder implements pipeline.CreateArgsBuilder using BuildCreateArgs.

func (*DefaultCreateArgsBuilder) BuildCreate

func (d *DefaultCreateArgsBuilder) BuildCreate(
	key pipeline.CreateKey,
	namespace string,
	args []pipeline.ArgConfig,
) []string

BuildCreate implements pipeline.CreateArgsBuilder.

type DefaultDirCleaner

type DefaultDirCleaner struct{}

DefaultDirCleaner implements pipeline.DirCleaner using CleanDir.

func (*DefaultDirCleaner) CleanDir

func (d *DefaultDirCleaner) CleanDir(directory string) error

CleanDir implements pipeline.DirCleaner.

type DefaultFileCopier

type DefaultFileCopier struct{}

DefaultFileCopier implements pipeline.FileCopier using Copy.

func (*DefaultFileCopier) Copy

func (d *DefaultFileCopier) Copy(src, dst string) error

Copy implements pipeline.FileCopier.

type DefaultFileHydrator

type DefaultFileHydrator struct{}

DefaultFileHydrator implements pipeline.FileHydrator using hydrate.

func (*DefaultFileHydrator) HydrateFile

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

HydrateFile implements pipeline.FileHydrator.

type DefaultNameHydrator

type DefaultNameHydrator struct{}

DefaultNameHydrator implements pipeline.NameHydrator using Hydrate.

func (*DefaultNameHydrator) HydrateName

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

HydrateName implements pipeline.NameHydrator.

type DefaultShaComputer

type DefaultShaComputer struct{}

DefaultShaComputer implements pipeline.ShaComputer using ComputeSha.

func (*DefaultShaComputer) ComputeSha

func (d *DefaultShaComputer) ComputeSha(buildDir string, sha pipeline.ShaConfig) (string, error)

ComputeSha implements pipeline.ShaComputer.

type DefaultStringHydrator

type DefaultStringHydrator struct{}

DefaultStringHydrator implements pipeline.StringHydrator using HydrateString.

func (*DefaultStringHydrator) HydrateString

func (d *DefaultStringHydrator) HydrateString(
	input string,
	output *bytes.Buffer,
	variables map[string]interface{},
) error

HydrateString implements pipeline.StringHydrator.

type DefaultYamlSplitter

type DefaultYamlSplitter struct{}

DefaultYamlSplitter implements pipeline.YamlSplitter using YamlSplit.

func (*DefaultYamlSplitter) Split

func (d *DefaultYamlSplitter) Split(buildDir, inputFile string) ([]string, error)

Split implements pipeline.YamlSplitter.

type HelmChart

type HelmChart struct {
	Dependencies []HelmDependency `yaml:"dependencies"`
}

type HelmDependency

type HelmDependency struct {
	Name       string `yaml:"name"`
	Repository string `yaml:"repository"`
}

type Runner

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

Runner is the struct in charge of launching commands.

func NewRunner

func NewRunner(cfg *CmdConfig) *Runner

NewRunner ...

func (*Runner) Build

func (r *Runner) Build(tmpDir string) error

Build is in charge of applying commands based on the config data. It delegates to BuildWithPipeline which uses the stage-based pipeline architecture.

func (*Runner) BuildWithPipeline

func (r *Runner) BuildWithPipeline(tmpDir string) error

BuildWithPipeline executes the build using the new pipeline architecture. This method provides the same functionality as Build() but uses the stage-based pipeline for better separation of concerns.

func (*Runner) BuildWithPipelineContext

func (r *Runner) BuildWithPipelineContext(ctx context.Context, tmpDir string) error

BuildWithPipelineContext executes the build with context support for cancelation.

type Sha

type Sha struct {
	// Key is used to generate beaver variable
	// beaver variable will be `sha.<Key>`
	Key string `yaml:"key"`
	// Resource file from which we should compute the sha256
	// Same format as beaver output:
	// <kind>.<apiVersion>.<name>.yaml
	Resource string `yaml:"resource"`
}

Sha define sha feature parameter.

type Tools

type Tools struct {
	// Helm: path to helm executable
	Helm string `yaml:"helm"`
	// Ytt: path to ytt executable
	Ytt string `yaml:"ytt"`
	// Kubectl: path to kubectl executable
	Kubectl string `yaml:"kubectl"`
}

Tools defines custom paths for external tools.

type Variable

type Variable struct {
	Name  string      `yaml:"name"`
	Value interface{} `yaml:"value"`
}

Variable ...

type Variables

type Variables []Variable

func (*Variables) Get

func (v *Variables) Get(path string) (interface{}, bool)

func (*Variables) GetD

func (v *Variables) GetD(path string, defaultValue interface{}) interface{}

func (*Variables) Overlay

func (v *Variables) Overlay(variables ...Variable)

func (*Variables) UnmarshalYAML

func (v *Variables) UnmarshalYAML(node *yaml.Node) error

type Ytt

type Ytt []string

Ytt is a type alias describing ytt arguments.

Source Files

  • build_helpers.go
  • cmd.go
  • cmd_config.go
  • command_executor.go
  • config.go
  • config_adapter.go
  • helm.go
  • hydrate.go
  • main.go
  • pathutil.go
  • populate.go
  • runner_pipeline.go
  • variables.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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