bespoke

package module
v0.0.0-...-e865a80 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 11 Imported by: 0

README

bespoke

Run kustomize after substituting environment variables

Note: this tool is still in its "infancy" and has not yet been released; use it at your own risk.

Most folks run kustomize and then use envsubst to substitute environment variables. They do it in this order because kustomize generates a single output stream that's easy to feed into envsubst; the input to kustomize may be many files spread over many directories. Unfortunately, that limits where in the kustomize input variables may be used -- they can't be used in resource names, patch target paths, etc.

(The kustomize maintainers don't like variables; the tool is "opinionated" in this way and so the rest of us must find workarounds.)

bespoke finds all the input files that kustomize would use, copies them to a temporary directory while substituting variables along the way, and then runs kustomize on that temporary directory to generate the final output.

As much as possible, bespoke uses the kustomize API, but it must make its own determination of what files or directories are referenced from the kustomization.yaml file. As a result, it may be a little fragile as kustomize evolves. For example, many existing files use bases which is deprecated; when it's finally removed from kustomize, a similar change must be made in bespoke.

At the moment, bespoke doesn't really have any options; when you run bespoke build [dir] it's the same as running kustomize build with --enable-alpha-plugins. The directory is optional; the tool defaults to the current working directory to find an input file.

bespoke uses a variant of a Go-based envsubst command that allows for defaults in variables. It's a variant because the default behavior of the original is to substitute "" when variables are not set (or fail, with that option selected); the variant will pass variables through as-is when not set, so that they may be used, e.g., in scripts passed into Kubernetes pods (where, presumably, the variable is defined).

That is, if the input contains $LC_PREFIX or ${LC_PREFIX} and LC_PREFIX isn't set in the current environment, then the output will have ${LC_PREFIX} in it, rather than the empty string.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runner

type Runner struct {
	Args   []string
	Env    []string // key=value pairs, not a map
	Writer io.Writer
	Temp   string
	Debug  bool
}

func (*Runner) Cleanup

func (r *Runner) Cleanup()

func (*Runner) Run

func (r *Runner) Run() error

Run handles the top-level work: identify the target, create a temp directory for the copies, copy/substitute the targeted files, and then run kustomize on that temp directory.

type Target

type Target struct {
	Parent   *Target
	Root     string
	Files    []string
	Children map[string]*Target
}

func Accumulate

func Accumulate(root string) (t *Target, err error)

Accumulate starts in the given directory and walks the tree defined by kustomize targets to collect other targets and files that we need to copy

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳