Documentation
¶
Overview ¶
Package kubectl provides helpers for interacting with Kubernetes through kubectl.
Index ¶
- func Apply(ctx context.Context, o ApplyOptions) (string, error)
- func ApplyInline(ctx context.Context, o ApplyInlineOptions) (string, error)
- func Assert(ctx context.Context, o BlockOptions) error
- func Classify(out string, err error) error
- func Cp(ctx context.Context, o CpOptions) (string, error)
- func CurrentContext(ctx context.Context) (string, error)
- func Delete(ctx context.Context, o DeleteOptions) (string, error)
- func Describe(ctx context.Context, o DescribeOptions) (string, error)
- func DryRun() bool
- func Events(ctx context.Context, o EventsOptions) (string, error)
- func Exec(ctx context.Context, o ExecOptions) (string, error)
- func Get(ctx context.Context, o GetOptions) (string, error)
- func Logs(ctx context.Context, o LogsOptions) (string, error)
- func Patch(ctx context.Context, o PatchOptions) (string, error)
- func PatchFile(ctx context.Context, o PatchFileOptions) (string, error)
- func Post(ctx context.Context, o BlockOptions, report func(label, out string, err error))
- func Restart(ctx context.Context, o RestartOptions) (string, error)
- func Rollout(ctx context.Context, o RolloutOptions) (string, error)
- func Scale(ctx context.Context, o ScaleOptions) (string, error)
- func SetDryRun(v bool)
- func Top(ctx context.Context, o TopOptions) (string, error)
- func UseContext(ctx context.Context, name string) (string, error)
- func Validate(expects spec.Expectations, baseDir string) []error
- func ValidateBlock(loc string, k *spec.Kubectl, baseDir string, post bool) []error
- func Write(ctx context.Context, o BlockOptions) error
- type ApplyInlineOptions
- type ApplyOptions
- type BlockOptions
- type CommandError
- type CpOptions
- type DeleteOptions
- type DescribeOptions
- type EventsOptions
- type ExecOptions
- type ExecTarget
- type GetOptions
- type Kind
- type LogsOptions
- type LogsTarget
- type PatchFileOptions
- type PatchOptions
- type RestartOptions
- type RolloutOptions
- type RolloutSub
- type ScaleOptions
- type TopOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(ctx context.Context, o ApplyOptions) (string, error)
Apply runs kubectl apply -f <file>.
func ApplyInline ¶
func ApplyInline(ctx context.Context, o ApplyInlineOptions) (string, error)
ApplyInline runs kubectl apply -f - with Content on stdin. Content arrives resolved: an inline manifest is part of its expectation, whose ${NAME} is expanded before it runs.
func Assert ¶
func Assert(ctx context.Context, o BlockOptions) error
Assert runs the block's reads and their assertions, stopping at the first that fails.
func Classify ¶
Classify wraps err in a CommandError with Kind inferred from the output. Returns nil when err is nil.
func CurrentContext ¶
CurrentContext returns the kubeconfig's current context.
func Delete ¶
func Delete(ctx context.Context, o DeleteOptions) (string, error)
Delete runs kubectl delete.
func Describe ¶
func Describe(ctx context.Context, o DescribeOptions) (string, error)
Describe runs kubectl describe.
func DryRun ¶
func DryRun() bool
DryRun reports whether dry-run mode is on. Tests use it to assert the flag without reading package state.
func Events ¶
func Events(ctx context.Context, o EventsOptions) (string, error)
Events runs kubectl events.
func Patch ¶
func Patch(ctx context.Context, o PatchOptions) (string, error)
Patch runs kubectl patch.
func PatchFile ¶
func PatchFile(ctx context.Context, o PatchFileOptions) (string, error)
PatchFile runs kubectl patch -f <file>, the manifest form of patch. It patches every object in File, so it has no -n: kubectl reads the namespace from each document.
func Post ¶
func Post(ctx context.Context, o BlockOptions, report func(label, out string, err error))
Post runs every entry in the block once, the writes and then the reads, and hands each one's label, output and error to report. Unlike a step it never stops early: a failed entry is reported and the next one runs, so a cleanup does all it can and a diagnostic prints all it can.
func Restart ¶
func Restart(ctx context.Context, o RestartOptions) (string, error)
Restart runs kubectl rollout restart.
func Rollout ¶
func Rollout(ctx context.Context, o RolloutOptions) (string, error)
Rollout runs kubectl rollout.
func Scale ¶
func Scale(ctx context.Context, o ScaleOptions) (string, error)
Scale runs kubectl scale.
func SetDryRun ¶
func SetDryRun(v bool)
SetDryRun toggles dry-run mode for every subsequent kubectl invocation in this process. The E2E runner sets it once at startup, from --dry-run.
func UseContext ¶
UseContext switches the kubeconfig's current context to name.
func Validate ¶
func Validate(expects spec.Expectations, baseDir string) []error
Validate checks every kubectl: block across the expectations: each step's, and each one's onFailure and finally post blocks.
func ValidateBlock ¶
ValidateBlock checks one kubectl: block; loc prefixes each error. A post block (onFailure, finally) is checked by the same rules except the step-only ones: a read there may only print, so it needs no assertion, and a get or describe may cover every object of its kind.
Types ¶
type ApplyInlineOptions ¶
ApplyInlineOptions is one `kubectl apply -f - [-n <ns>]` fed through stdin.
type ApplyOptions ¶
ApplyOptions is one `kubectl apply -f <file> [-n <ns>]`.
type BlockOptions ¶
type BlockOptions struct {
Kubectl *spec.Kubectl // the block whose entries run, in order
Env env.Resolver // the expectation's env, in every invocation's environment
WorkDir string // cwd for each kubectl call; relative paths resolve here
Client kubernetes.Interface // for lease/exec/cp lookups that need the API
Config *rest.Config // for port-forward (SPDY dialer)
Dynamic dynamic.Interface // for client-go-native get instead of kubectl subprocess
Mapper apimeta.RESTMapper // resolves kind strings to GVR for the dynamic path
// Capture saves what a get's capture: entries captured, once its
// checks pass.
Capture func(map[string]string)
}
BlockOptions is one kubectl: block and what its entries need to reach the cluster. Write, Assert and Post all take it.
type CommandError ¶
CommandError is a failed kubectl invocation with a classified Kind.
func (*CommandError) Error ¶
func (e *CommandError) Error() string
func (*CommandError) Unwrap ¶
func (e *CommandError) Unwrap() error
type CpOptions ¶
type CpOptions struct {
Source string // "ns/pod:/path/inside"
Dest string // local path
Container string
WorkDir string
Env env.Resolver
}
CpOptions is one `kubectl cp <src> <dst> [-c <container>]`.
type DeleteOptions ¶
type DeleteOptions struct {
File string
Kind string
Name string
Namespace string
IgnoreNotFound bool
Timeout string // --timeout=<dur>; empty means kubectl's default
Wait *bool // --wait=false when set to false; nil means kubectl's default (wait)
WorkDir string
Env env.Resolver
}
DeleteOptions is one `kubectl delete -f <file>` or `kubectl delete <kind> <name> -n <ns>`.
type DescribeOptions ¶
type DescribeOptions struct {
Kind string
Name string // mutually exclusive with LabelSelector
LabelSelector string
Namespace string
WorkDir string
Env env.Resolver
}
DescribeOptions is one `kubectl describe <kind> [name|-l selector] -n <ns>`.
type EventsOptions ¶
type EventsOptions struct {
Kind string
Name string
Namespace string
WorkDir string
Env env.Resolver
}
EventsOptions is one `kubectl events --for <kind>/<name> -n <ns>`.
type ExecOptions ¶
type ExecOptions struct {
Pod string
Namespace string
Container string
Command []string // argv after --
WorkDir string
Env env.Resolver
}
ExecOptions is one `kubectl exec -n <ns> <pod> [-- <command…>]`.
type ExecTarget ¶
ExecTarget is the resolved pod and namespace an exec runs against.
type GetOptions ¶
type GetOptions struct {
Kind string
Name string // mutually exclusive with LabelSelector
LabelSelector string
AllNamespaces bool // --all-namespaces; suppresses -n
Namespace string
Format string
WorkDir string
Env env.Resolver
IgnoreNotFound bool // --ignore-not-found
}
GetOptions is one `kubectl get <kind> [name] [-l <selector>] -n <ns> [-o <format>]` or, with AllNS, `kubectl get <kind> --all-namespaces`.
type Kind ¶
type Kind string
Kind classifies a kubectl failure so callers can branch on it without string-matching stderr.
type LogsOptions ¶
type LogsOptions struct {
Target string // pod name; mutually exclusive with LabelSelector
LabelSelector string // -l <selector>
Namespace string
Container string
Since string
WorkDir string
Env env.Resolver
}
LogsOptions is one `kubectl logs -n <ns> <target> [-c <container>] [--since=<d>]`.
type LogsTarget ¶
LogsTarget is the resolved target for a logs invocation: a pod name, or a label selector, plus the namespace the pod lives in.
type PatchFileOptions ¶
type PatchFileOptions struct {
File string
Type string // "merge" (default), "strategic", "json"
Patch string
PatchFile string // used when Patch is empty
WorkDir string
Env env.Resolver
}
PatchFileOptions is one `kubectl patch -f <file> --type <type>` with -p <patch> or --patch-file <file>.
type PatchOptions ¶
type PatchOptions struct {
Kind string
Name string
Namespace string
Type string // "merge" (default), "strategic", "json"
Patch string
PatchFile string // used when Patch is empty
WorkDir string
Env env.Resolver
}
PatchOptions is one `kubectl patch <kind> <name> -n <ns> --type <type>` with -p <patch> or --patch-file <file>.
type RestartOptions ¶
type RestartOptions struct {
Target string // "deployment/name", "statefulset/name", …
Namespace string
WorkDir string
Env env.Resolver
}
RestartOptions is one `kubectl rollout restart <target> -n <ns>`.
type RolloutOptions ¶
type RolloutOptions struct {
Sub RolloutSub
Target string
Namespace string
WorkDir string
Env env.Resolver
}
RolloutOptions is one `kubectl rollout <sub> <target> -n <ns>`.
type RolloutSub ¶
type RolloutSub string
RolloutSub is a kubectl rollout subcommand: restart, status, undo, …
const ( RolloutRestart RolloutSub = "restart" RolloutStatus RolloutSub = "status" )