process

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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

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 RenderTemplates deprecated

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 deprecated

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 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:

  1. if templ has len > 0, it will be rendered against data
  2. the rendered template values that look like `--foo=bar` will be split and appended to args, the rest will be kept around
  3. the given args will be rendered as string form. If a template is given, no defaults will be used, otherwise defaults will be used
  4. 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.

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{}
)

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

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 (*Arguments) AppendNoDefaults

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 (*Arguments) AsStrings

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.

  • 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) Disable

func (a *Arguments) Disable(key string) *Arguments

Disable prevents this flag from be passed.

func (*Arguments) Enable

func (a *Arguments) Enable(key string) *Arguments

Enable configures the given key to be passed as a "name-only" flag, like, `--key`.

func (*Arguments) Get

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 (*Arguments) Set

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 (*Arguments) SetRaw

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.

type FuncArg

type FuncArg func([]string) []string

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.

func (FuncArg) Append

func (a FuncArg) Append(vals ...string) Arg

Append is a no-op for FuncArg, and just returns itself.

func (FuncArg) Get

func (a FuncArg) Get(defaults []string) []string

Get delegates functionality to the FuncArg function itself.

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

type ListenAddr struct {
	Address string
	Port    string
}

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.

func (*ListenAddr) URL

func (l *ListenAddr) URL(scheme string, path string) *url.URL

URL returns a URL for this address with the given scheme and subpath.

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

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 (*State) Exited

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 (*State) Init

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 (*State) Start

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 (*State) Stop

func (ps *State) Stop() error

Stop stops this process gracefully, waits for its termination, and cleans up the CertDir if necessary.

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.

Jump to

Keyboard shortcuts

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