Documentation
¶
Index ¶
- Constants
- Variables
- func BuildChartArgs(chart pipeline.ChartConfig, name, namespace string) ([]string, error)
- func BuildCreateArgs(key pipeline.CreateKey, namespace string, args []pipeline.ArgConfig) []string
- func CleanDir(directory string) error
- func ComputeSha(buildDir string, sha pipeline.ShaConfig) (string, error)
- func Copy(src, dst string) (err error)
- func FindFiles(layers []string, charts map[string]CmdChart) map[string]CmdChart
- func Hydrate(input []byte, output io.Writer, variables map[string]any) error
- func HydrateFileWrapper(input string, output *os.File, variables map[string]interface{}, disabled bool) error
- func HydrateNameWrapper(input []byte, output *bytes.Buffer, variables map[string]interface{}) error
- func HydrateScalarNode(node *yaml.Node, variables map[string]any) error
- func HydrateString(input string, output io.Writer, variables map[string]any) error
- func HydrateStringWrapper(input string, output *bytes.Buffer, variables map[string]interface{}) error
- func HydrateVariables(variables map[string]any) error
- func IsContainedPath(basePath, targetPath string) (bool, error)
- func LookupVariable(variables interface{}, name string) (interface{}, bool)
- func RunCMD(c *cmd.Cmd) ([]string, []string, error)
- func RunCMDWithContext(ctx context.Context, c *cmd.Cmd) ([]string, []string, error)
- func SanitizeFilename(name string) string
- func SetVariable(v interface{}, path []string, value interface{})
- func ToBool(s string) (bool, error)
- func ValidateContainedPath(basePath, targetPath string) error
- func YamlSplit(buildDir, inputFile string) ([]string, error)
- type Arg
- type Chart
- type CmdChart
- type CmdCharts
- type CmdConfig
- func (c *CmdConfig) BuildYttArgs(paths, compiled []string) []string
- func (c *CmdConfig) HasShas() bool
- func (c *CmdConfig) HelmBuildDependency(path string) error
- func (c *CmdConfig) HelmChartsPaths() ([]string, error)
- func (c *CmdConfig) HelmDependencyBuild() error
- func (c *CmdConfig) Initialize(tmpDir string) error
- func (c *CmdConfig) MergeVariables(other *Config)
- func (c *CmdConfig) PrepareVariables(doSha bool) (map[string]interface{}, error)
- func (c *CmdConfig) SetShas(buildDir string) error
- type CmdConfigAdapter
- func (a *CmdConfigAdapter) BuildYttArgs(paths, compiled []string) []string
- func (a *CmdConfigAdapter) FetchHelmDeps() bool
- func (a *CmdConfigAdapter) GetCharts() map[string]pipeline.ChartConfig
- func (a *CmdConfigAdapter) GetCreates() map[pipeline.CreateKey]pipeline.CreateConfig
- func (a *CmdConfigAdapter) GetLayers() []string
- func (a *CmdConfigAdapter) GetNamespace() string
- func (a *CmdConfigAdapter) GetOutput() string
- func (a *CmdConfigAdapter) GetRootDir() string
- func (a *CmdConfigAdapter) GetShas() []pipeline.ShaConfig
- func (a *CmdConfigAdapter) GetYtt() []string
- func (a *CmdConfigAdapter) HelmDependencyBuild() error
- func (a *CmdConfigAdapter) IsDryRun() bool
- func (a *CmdConfigAdapter) IsWithoutHydrate() bool
- func (a *CmdConfigAdapter) PrepareVariables(doSha bool) (map[string]interface{}, error)
- func (a *CmdConfigAdapter) SetChartDisabled(name, disabled string)
- func (a *CmdConfigAdapter) SetChartKubeVersion(name, kubeVersion string)
- func (a *CmdConfigAdapter) SetNamespace(ns string)
- func (a *CmdConfigAdapter) SetSha(index int, sha string)
- type CmdConfigOptions
- type CmdCreate
- type CmdCreateKey
- type CmdSha
- type CmdSpec
- type Config
- type Create
- type DefaultBoolParser
- type DefaultChartArgsBuilder
- type DefaultCommandExecutor
- type DefaultCreateArgsBuilder
- type DefaultDirCleaner
- type DefaultFileCopier
- type DefaultFileHydrator
- type DefaultNameHydrator
- type DefaultShaComputer
- type DefaultStringHydrator
- type DefaultYamlSplitter
- type HelmChart
- type HelmDependency
- type Runner
- type Sha
- type Tools
- type Variable
- type Variables
- type Ytt
Constants ¶
const ( HelmType = "helm" YttType = "ytt" )
Variables ¶
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 ¶
BuildCreateArgs builds arguments for a kubectl create command.
func ComputeSha ¶
ComputeSha computes the SHA256 hash of a resource file.
func Hydrate ¶
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 ¶
HydrateNameWrapper wraps Hydrate for filename hydration.
func HydrateScalarNode ¶
HydrateScalarNode a yaml node.
func HydrateString ¶
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 IsContainedPath ¶
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 RunCMD ¶
RunCMD runs the given cmd and returns its stdout, stderr and an eventual error.
func RunCMDWithContext ¶
RunCMDWithContext runs the given cmd with context support for cancelation. It returns stdout, stderr, and an eventual error.
func SanitizeFilename ¶
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 ValidateContainedPath ¶
ValidateContainedPath validates that targetPath stays within basePath. Returns an error if the path escapes the base directory.
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 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 (*CmdConfig) MergeVariables ¶
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 ¶
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 ¶
func (a *CmdConfigAdapter) GetCreates() map[pipeline.CreateKey]pipeline.CreateConfig
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 CmdCreateKey ¶
func (CmdCreateKey) BuildArgs ¶
func (k CmdCreateKey) BuildArgs(namespace string, args []Arg) []string
type CmdSha ¶
type CmdSpec ¶
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.
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 ¶
DefaultCommandExecutor executes external commands.
func NewCommandExecutor ¶
func NewCommandExecutor(logger zerolog.Logger, dryRun bool) *DefaultCommandExecutor
NewCommandExecutor creates a new command executor.
type DefaultCreateArgsBuilder ¶
type DefaultCreateArgsBuilder struct{}
DefaultCreateArgsBuilder implements pipeline.CreateArgsBuilder using BuildCreateArgs.
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.
type DefaultNameHydrator ¶
type DefaultNameHydrator struct{}
DefaultNameHydrator implements pipeline.NameHydrator using Hydrate.
type DefaultShaComputer ¶
type DefaultShaComputer struct{}
DefaultShaComputer implements pipeline.ShaComputer using ComputeSha.
type DefaultStringHydrator ¶
type DefaultStringHydrator struct{}
DefaultStringHydrator implements pipeline.StringHydrator using HydrateString.
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 Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner is the struct in charge of launching commands.
func (*Runner) Build ¶
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 ¶
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.
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 ...
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