Documentation ¶
Index ¶
- Constants
- func BinPathFinder(symbolicName, assetDirectory string) (binPath string)
- func RenderTemplates(argTemplates []string, data interface{}) (args []string, err error)deprecated
- func SliceToArguments(sliceArgs []string, args *Arguments) []stringdeprecated
- func TemplateAndArguments(templ []string, args *Arguments, data TemplateDefaults) (allArgs []string, nonFlagishArgs []string, err error)deprecated
- type Arg
- type Arguments
- func (a *Arguments) Append(key string, values ...string) *Arguments
- func (a *Arguments) AppendNoDefaults(key string, values ...string) *Arguments
- func (a *Arguments) AsStrings(defaults map[string][]string) []string
- func (a *Arguments) Disable(key string) *Arguments
- func (a *Arguments) Enable(key string) *Arguments
- func (a *Arguments) Get(key string) Arg
- func (a *Arguments) Set(key string, values ...string) *Arguments
- func (a *Arguments) SetRaw(key string, val Arg) *Arguments
- type FuncArg
- type HealthCheck
- type ListenAddr
- type State
- type TemplateDefaultsdeprecated
Constants ¶
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" )
Variables ¶
This section is empty.
Functions ¶
func BinPathFinder ¶
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 RenderTemplates
deprecated
func SliceToArguments
deprecated
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
deprecated
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:
- if templ has len > 0, it will be rendered against data
- the rendered template values that look like `--foo=bar` will be split and appended to args, the rest will be kept around
- the given args will be rendered as string form. If a template is given, no defaults will be used, otherwise defaults will be used
- a result of [args..., rest...] will be returned
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.
Types ¶
type Arg ¶
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 }
Arg is an argument that has one or more values, and optionally falls back to default values.
type Arguments ¶
type Arguments struct {
// contains filtered or unexported fields
}
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.
func EmptyArguments ¶
func EmptyArguments() *Arguments
EmptyArguments constructs an empty set of flags with no defaults.
func (*Arguments) Append ¶
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 (*Arguments) AppendNoDefaults ¶
AppendNoDefaults adds additional values to this flag. However, unlike Append, it will *not* copy values from defaults.
func (*Arguments) AsStrings ¶
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.
- Any flag in defaults that's not in Arguments will be present in the output
- Any flag that's present in Arguments will be passed the corresponding defaults to do with as it will (ignore, append-to, suppress, etc).
func (*Arguments) Enable ¶
Enable configures the given key to be passed as a "name-only" flag, like, `--key`.
func (*Arguments) Get ¶
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 ...`.
type FuncArg ¶
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 HealthCheck ¶
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 }
HealthCheck describes the information needed to health-check a process via some health-check URL.
type ListenAddr ¶
ListenAddr represents some listening address and port.
func (*ListenAddr) HostPort ¶
func (l *ListenAddr) HostPort() string
HostPort returns the joined host-port pair for this address.
type State ¶
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 }
State define the state of the process.
func (*State) CheckFlag ¶
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 (*State) Exited ¶
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 (*State) Init ¶
Init sets up this process, configuring binary paths if missing, initializing temporary directories, etc.
This defaults all defaultable fields.
type TemplateDefaults
deprecated
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 }
TemplateDefaults specifies defaults to be used for joining structured arguments with templates.
Deprecated: will be removed when RenderTemplates is removed.