const ( // EnvAssetsPath is the environment variable that stores the global test // binary location override. EnvAssetsPath = "KUBEBUILDER_ASSETS" // EnvAssetOverridePrefix is the environment variable prefix for per-binary // location overrides. EnvAssetOverridePrefix = "TEST_ASSET_" // AssetsDefaultPath is the default location to look for test binaries in, // if no override was provided. AssetsDefaultPath = "/usr/local/kubebuilder/bin" )
func BinPathFinder(symbolicName, assetDirectory string) (binPath string)
BinPathFinder finds the path to the given named binary, using the following locations in order of precedence (highest first). Notice that the various env vars only need to be set -- the asset is not checked for existence on the filesystem.
1. TEST_ASSET_{tr/a-z-/A-Z_/} (if set; asset overrides -- EnvAssetOverridePrefix) 1. KUBEBUILDER_ASSETS (if set; global asset path -- EnvAssetsPath) 3. assetDirectory (if set; per-config asset directory) 4. /usr/local/kubebuilder/bin (AssetsDefaultPath).
func GetSysProcAttr() *unix.SysProcAttr
GetSysProcAttr returns the SysProcAttr to use for the process, for unix systems this returns a SysProcAttr with Setpgid set to true, which inherits the parent's process group id.
func RenderTemplates(argTemplates []string, data interface{}) (args []string, err error)
RenderTemplates returns an []string to render the templates
Deprecated: will be removed in favor of Arguments.
func SliceToArguments(sliceArgs []string, args *Arguments) []string
SliceToArguments converts a slice of arguments to structured arguments, appending each argument that starts with `--` and contains an `=` to the argument set (ignoring defaults), returning the rest.
Deprecated: will be removed when RenderTemplates is removed.
func TemplateAndArguments(templ []string, args *Arguments, data TemplateDefaults) (allArgs []string, nonFlagishArgs []string, err error)
TemplateAndArguments joins structured arguments and non-structured arguments, preserving existing behavior. Namely:
It returns the resulting rendered arguments, plus the arguments that were not transferred to `args` during rendering.
Deprecated: will be removed when RenderTemplates is removed.
Arg is an argument that has one or more values, and optionally falls back to default values.
type Arg interface { // Append adds new values to this argument, returning // a new instance contain the new value. The intermediate // argument should generally be assumed to be consumed. Append(vals ...string) Arg // Get returns the full set of values, optionally including // the passed in defaults. If it returns nil, this will be // skipped. If it returns a non-nil empty slice, it'll be // assumed that the argument should be passed as name-only. Get(defaults []string) []string }
var ( // DontPass indicates that the given argument will not actually be // rendered. DontPass Arg = dontPassArg{} // PassAsName indicates that the given flag will be passed as `--key` // without any value. PassAsName Arg = passAsNameArg{} )
Arguments are structured, overridable arguments. Each Arguments object contains some set of default arguments, which may be appended to, or overridden.
When ready, you can serialize them to pass to exec.Command and friends using AsStrings.
All flag-setting methods return the *same* instance of Arguments so that you can chain calls.
type Arguments struct {
// contains filtered or unexported fields
}
func EmptyArguments() *Arguments
EmptyArguments constructs an empty set of flags with no defaults.
func (a *Arguments) Append(key string, values ...string) *Arguments
Append adds additional values to this flag. If this flag has yet to be set, initial values will include defaults. If you want to intentionally ignore defaults/start from scratch, call AppendNoDefaults.
Multiple values will look like `--key=value1 --key=value2 ...`.
func (a *Arguments) AppendNoDefaults(key string, values ...string) *Arguments
AppendNoDefaults adds additional values to this flag. However, unlike Append, it will *not* copy values from defaults.
func (a *Arguments) AsStrings(defaults map[string][]string) []string
AsStrings serializes this set of arguments to a slice of strings appropriate for passing to exec.Command and friends, making use of the given defaults as indicated for each particular argument.
func (a *Arguments) Disable(key string) *Arguments
Disable prevents this flag from be passed.
func (a *Arguments) Enable(key string) *Arguments
Enable configures the given key to be passed as a "name-only" flag, like, `--key`.
func (a *Arguments) Get(key string) Arg
Get returns the value of the given flag. If nil, it will not be passed in AsString, otherwise:
len == 0 --> `--key`, len > 0 --> `--key=val1 --key=val2 ...`.
func (a *Arguments) Set(key string, values ...string) *Arguments
Set resets the given flag to the specified values, ignoring any existing values or defaults.
func (a *Arguments) SetRaw(key string, val Arg) *Arguments
SetRaw sets the given flag to the given Arg value directly. Use this if you need to do some complicated deferred logic or something.
Otherwise behaves like Set.
FuncArg is a basic implementation of Arg that can be used for custom argument logic, like pulling values out of APIServer, or dynamically calculating values just before launch.
The given function will be mapped directly to Arg#Get, and will generally be used in conjunction with SetRaw. For example, to set `--some-flag` to the API server's CertDir, you could do:
server.Configure().SetRaw("--some-flag", FuncArg(func(defaults []string) []string { return []string{server.CertDir} }))
FuncArg ignores Appends; if you need to support appending values too, consider implementing Arg directly.
type FuncArg func([]string) []string
func (a FuncArg) Append(vals ...string) Arg
Append is a no-op for FuncArg, and just returns itself.
func (a FuncArg) Get(defaults []string) []string
Get delegates functionality to the FuncArg function itself.
HealthCheck describes the information needed to health-check a process via some health-check URL.
type HealthCheck struct { url.URL // HealthCheckPollInterval is the interval which will be used for polling the // endpoint described by Host, Port, and Path. // // If left empty it will default to 100 Milliseconds. PollInterval time.Duration }
ListenAddr represents some listening address and port.
type ListenAddr struct { Address string Port string }
func (l *ListenAddr) HostPort() string
HostPort returns the joined host-port pair for this address.
func (l *ListenAddr) URL(scheme string, path string) *url.URL
URL returns a URL for this address with the given scheme and subpath.
State define the state of the process.
type State struct { Cmd *exec.Cmd // HealthCheck describes how to check if this process is up. If we get an http.StatusOK, // we assume the process is ready to operate. // // For example, the /healthz endpoint of the k8s API server, or the /health endpoint of etcd. HealthCheck HealthCheck Args []string StopTimeout time.Duration StartTimeout time.Duration Dir string DirNeedsCleaning bool Path string // contains filtered or unexported fields }
func (ps *State) CheckFlag(flag string) (bool, error)
CheckFlag checks the help output of this command for the presence of the given flag, specified without the leading `--` (e.g. `CheckFlag("insecure-port")` checks for `--insecure-port`), returning true if the flag is present.
func (ps *State) Exited() (bool, error)
Exited returns true if the process exited, and may also return an error (as per Cmd.Wait) if the process did not exit with error code 0.
func (ps *State) Init(name string) error
Init sets up this process, configuring binary paths if missing, initializing temporary directories, etc.
This defaults all defaultable fields.
func (ps *State) Start(stdout, stderr io.Writer) (err error)
Start starts the apiserver, waits for it to come up, and returns an error, if occurred.
func (ps *State) Stop() error
Stop stops this process gracefully, waits for its termination, and cleans up the CertDir if necessary.
TemplateDefaults specifies defaults to be used for joining structured arguments with templates.
Deprecated: will be removed when RenderTemplates is removed.
type TemplateDefaults struct { // Data will be used to render the template. Data interface{} // Defaults will be used to default structured arguments if no template is passed. Defaults map[string][]string // MinimalDefaults will be used to default structured arguments if a template is passed. // Use this for flags which *must* be present. MinimalDefaults map[string][]string // for api server service-cluster-ip-range }