Documentation ¶
Index ¶
- func WithEnvironment(opts []EnvironmentOption, fn func(e *Environment)) (err error)
- func WithNamespace(ctx context.Context, e *Environment, nf NamespaceFactory, ...) (err error)
- type Environment
- type EnvironmentOption
- type EnvironmentOptionFunc
- type EnvironmentOptions
- type EnvironmentWithCRDDirectoryPaths
- type EnvironmentWithClientContext
- type EnvironmentWithClientKubeconfigs
- type ExecResult
- type Execer
- type ExecerOption
- type ExecerOptions
- type ExecerWithGenerateName
- type ExecerWithImage
- type ExecerWithName
- type ExecerWithNamespace
- type ExecerWithShell
- type ExecerWithTimeout
- type NamespaceFactory
- type NamespaceFactoryFunc
- type NamespaceOption
- type NamespaceOptions
- type NamespaceWithLabels
- type NamespaceWithNamePrefix
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithEnvironment ¶
func WithEnvironment(opts []EnvironmentOption, fn func(e *Environment)) (err error)
WithEnvironment runs a function with a connection to a cluster and then tears down the connection.
func WithNamespace ¶
func WithNamespace(ctx context.Context, e *Environment, nf NamespaceFactory, fn func(ns *corev1.Namespace)) (err error)
Types ¶
type Environment ¶
type Environment struct { Scheme *runtime.Scheme RESTConfig *rest.Config RESTMapper meta.RESTMapper ControllerClient client.Client StaticClient kubernetes.Interface DynamicClient dynamic.Interface // contains filtered or unexported fields }
Environment provides an opinionated connection to an existing cluster in test. It does not allow a new cluster to be created (like controller-runtime's envtest).
func NewEnvironment ¶
func NewEnvironment(opts ...EnvironmentOption) (e *Environment, err error)
NewEnvironment establishes a connection to the cluster given by the relevant Kubernetes client configuration and sets up client accessors for it.
func (*Environment) Close ¶
func (e *Environment) Close(ctx context.Context) error
Close terminates the connection to this cluster and cleans up resources created by the connection.
func (*Environment) Impersonate ¶ added in v0.2.0
func (e *Environment) Impersonate(ic rest.ImpersonationConfig) (*Environment, error)
Impersonate creates an Environment that uses the given configuration for impersonating a user or service account. Its lifetime is the same as the parent environment.
type EnvironmentOption ¶
type EnvironmentOption interface { // ApplyToEnvironmentOptions copies the configuration of this option to the // given environment options. ApplyToEnvironmentOptions(target *EnvironmentOptions) }
EnvironmentOption is a setter for one or more environment options.
func EnvironmentWithClientConfigLoader ¶
func EnvironmentWithClientConfigLoader(loader clientcmd.ClientConfigLoader) EnvironmentOption
EnvironmentWithClientConfigLoader replaces the client configuration loader with the specified one.
This option is incompatible with EnvironmentWithClientKubeconfigs.
func EnvironmentWithClientConfigOverrides ¶
func EnvironmentWithClientConfigOverrides(overrides *clientcmd.ConfigOverrides) EnvironmentOption
EnvironmentWithClientConfigOverrides replaces the client configuration overrides with the specified one.
This option overwrites any changes made by EnvironmentWithClientContext.
func EnvironmentWithClientScheme ¶
func EnvironmentWithClientScheme(s *runtime.Scheme) EnvironmentOption
EnvironmentWithClientScheme sets the runtime scheme to use for the controller and dynamic clients.
type EnvironmentOptionFunc ¶
type EnvironmentOptionFunc func(target *EnvironmentOptions)
EnvironmentOptionFunc allows a functio to be used as an enviroment option.
func (EnvironmentOptionFunc) ApplyToEnvironmentOptions ¶
func (eof EnvironmentOptionFunc) ApplyToEnvironmentOptions(target *EnvironmentOptions)
ApplyToEnvironmentOptions copies the configuration of this option to the given environment options.
type EnvironmentOptions ¶
type EnvironmentOptions struct { CRDDirectoryPaths []string ClientConfigLoader clientcmd.ClientConfigLoader ClientConfigOverrides *clientcmd.ConfigOverrides ClientScheme *runtime.Scheme }
EnvironmentOptions are the options that control a given test environment.
func (*EnvironmentOptions) ApplyOptions ¶
func (o *EnvironmentOptions) ApplyOptions(opts []EnvironmentOption)
ApplyOptions runs each of the given option setters against this environment options struct.
type EnvironmentWithCRDDirectoryPaths ¶
type EnvironmentWithCRDDirectoryPaths []string
EnvironmentWithCRDDirectoryPaths causes any CRDs found in the given directories to be loaded into the cluster when the environment connection is established.
func (EnvironmentWithCRDDirectoryPaths) ApplyToEnvironmentOptions ¶
func (ewcdp EnvironmentWithCRDDirectoryPaths) ApplyToEnvironmentOptions(target *EnvironmentOptions)
ApplyToEnvironmentOptions copies the configuration of this option to the given environment options.
type EnvironmentWithClientContext ¶
type EnvironmentWithClientContext string
EnvironmentWithClientContext causes the environment connection to use the given context from the Kubeconfig(s) instead of the default configured in the file.
func (EnvironmentWithClientContext) ApplyToEnvironmentOptions ¶
func (ewcc EnvironmentWithClientContext) ApplyToEnvironmentOptions(target *EnvironmentOptions)
ApplyToEnvironmentOptions copies the configuration of this option to the given environment options.
type EnvironmentWithClientKubeconfigs ¶
type EnvironmentWithClientKubeconfigs []string
EnvironmentWithClientKubeconfigs sets the path to one or more Kubeconfig files to use to load the connection to the cluster.
This option is incompatible with EnvironmentWithClientConfigLoader.
func (EnvironmentWithClientKubeconfigs) ApplyToEnvironmentOptions ¶
func (ewck EnvironmentWithClientKubeconfigs) ApplyToEnvironmentOptions(target *EnvironmentOptions)
ApplyToEnvironmentOptions copies the configuration of this option to the given environment options.
type ExecResult ¶
type ExecResult struct { // Code is the exit code returned by the script. Code int // Stdout is the complete contents of the script's standard output file // descriptor. Stdout string // Stderr is the complete contents of the script's standard error file // descriptor. Stderr string }
ExecResult provides access to some information after running a script.
func Exec ¶
func Exec(ctx context.Context, e *Environment, script string, opts ...ExecerOption) (res *ExecResult, err error)
Exec creates a one-time-use Execer, runs the given script, and then tears down the backing pod.
type Execer ¶
type Execer struct {
// contains filtered or unexported fields
}
Execer is a utility that allows arbitrary shell commands to be run inside a cluster.
For example, this can be used to test that services only accessible within a cluster are behaving correctly without port-forwarding them.
func NewExecer ¶
func NewExecer(e *Environment, opts ...ExecerOption) *Execer
NewExecer creates a new script executor for the given environment and options.
func (*Execer) Exec ¶
Exec executes the given script using a POSIX-compatible shell.
The result of executing the shell is made available in the result struct. If the command fails, its exit status is reported in the result, but an error is not returned. This method only returns an error if an infrastucture failure occurs (like not being able to communicate with the execution pod).
type ExecerOption ¶
type ExecerOption interface { // ApplyToExecerOptions copies the configuration of this option to the given // script executor options. ApplyToExecerOptions(target *ExecerOptions) }
ExecerOption is a setter for one or more script executor options.
type ExecerOptions ¶
type ExecerOptions struct { // PodMeta is the pod metadata for the execution environment. Defaults to // the default namespace and a generated name starting with "script-". PodMeta metav1.ObjectMeta // Image is the name of the Docker image to use. Defaults to Alpine. Image string // Shell is the POSIX-compatible shell to use. Defaults to /bin/sh. Shell string // Timeout is the maximum lifetime for the script executor pod. Defaults to // 24 hours. Timeout time.Duration }
ExecerOptions allow for customization of a script executor.
func (*ExecerOptions) ApplyOptions ¶
func (o *ExecerOptions) ApplyOptions(opts []ExecerOption)
ApplyOptions runs each of the given options against this script executor options struct.
type ExecerWithGenerateName ¶
type ExecerWithGenerateName string
ExecerWithGenerateName generates the pod name from the given template string.
func (ExecerWithGenerateName) ApplyToExecerOptions ¶
func (ewgn ExecerWithGenerateName) ApplyToExecerOptions(target *ExecerOptions)
ApplyToExecerOptions copies the configuration of this option to the given script executor options.
type ExecerWithImage ¶
type ExecerWithImage string
ExecerWithImage sets the Docker image to use for the execution environment.
func (ExecerWithImage) ApplyToExecerOptions ¶
func (ewi ExecerWithImage) ApplyToExecerOptions(target *ExecerOptions)
ApplyToExecerOptions copies the configuration of this option to the given script executor options.
type ExecerWithName ¶
type ExecerWithName string
ExecerWithName sets the pod name.
func (ExecerWithName) ApplyToExecerOptions ¶
func (ewn ExecerWithName) ApplyToExecerOptions(target *ExecerOptions)
ApplyToExecerOptions copies the configuration of this option to the given script executor options.
type ExecerWithNamespace ¶
type ExecerWithNamespace string
ExecerWithNamespace causes the script execution pod to be created in the given namespace.
func (ExecerWithNamespace) ApplyToExecerOptions ¶
func (ewn ExecerWithNamespace) ApplyToExecerOptions(target *ExecerOptions)
ApplyToExecerOptions copies the configuration of this option to the given script executor options.
type ExecerWithShell ¶
type ExecerWithShell string
ExecerWithShell sets the POSIX-compatible shell to use when executing scripts.
func (ExecerWithShell) ApplyToExecerOptions ¶
func (ews ExecerWithShell) ApplyToExecerOptions(target *ExecerOptions)
ApplyToExecerOptions copies the configuration of this option to the given script executor options.
type ExecerWithTimeout ¶
ExecerWithTimeout sets the maximum lifetime for the pod.
func (ExecerWithTimeout) ApplyToExecerOptions ¶
func (ewt ExecerWithTimeout) ApplyToExecerOptions(target *ExecerOptions)
ApplyToExecerOptions copies the configuration of this option to the given script executor options.
type NamespaceFactory ¶
type NamespaceFactory interface {
New(ctx context.Context, e *Environment) (*corev1.Namespace, error)
}
func NewGenerateNameNamespaceFactory ¶
func NewGenerateNameNamespaceFactory(opts ...NamespaceOption) NamespaceFactory
func NewTestNamespaceFactory ¶
func NewTestNamespaceFactory(t *testing.T, opts ...NamespaceOption) NamespaceFactory
type NamespaceFactoryFunc ¶
func (NamespaceFactoryFunc) New ¶
func (nff NamespaceFactoryFunc) New(ctx context.Context, e *Environment) (*corev1.Namespace, error)
type NamespaceOption ¶
type NamespaceOption interface {
ApplyToNamespaceOptions(target *NamespaceOptions)
}
type NamespaceOptions ¶
func (*NamespaceOptions) ApplyOptions ¶
func (o *NamespaceOptions) ApplyOptions(opts []NamespaceOption)
func (*NamespaceOptions) ApplyToNamespaceOptions ¶
func (o *NamespaceOptions) ApplyToNamespaceOptions(target *NamespaceOptions)
type NamespaceWithLabels ¶
func (NamespaceWithLabels) ApplyToNamespaceOptions ¶
func (nwl NamespaceWithLabels) ApplyToNamespaceOptions(target *NamespaceOptions)
type NamespaceWithNamePrefix ¶
type NamespaceWithNamePrefix string
func (NamespaceWithNamePrefix) ApplyToNamespaceOptions ¶
func (nwnp NamespaceWithNamePrefix) ApplyToNamespaceOptions(target *NamespaceOptions)