Documentation ¶
Overview ¶
Provides builders and helper methods for preparing Pods and nested Containers
Index ¶
- Constants
- Variables
- func AfterReadingAllFlags(t *TestContextType)
- func ContainsAll(model, target []interface{}) bool
- func DeleteNamespaces(c clientset.Interface, deleteFilter, skipFilter []string) ([]string, error)
- func Execute(ctx1 *ContextData, command string, arguments string, podname string) (string, string, error)
- func ExpectError(err error, explain ...interface{})
- func ExpectNoError(err error, explain ...interface{})
- func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{})
- func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{})
- func FromInts(m []int) []interface{}
- func FromStrings(m []string) []interface{}
- func GetPorts(service corev1.Service) []int
- func HandleFlags()
- func Int32Ptr(i int32) *int32
- func IsRetryFailure(err error) bool
- func KubectlCmd(ctxData ContextData, args ...string) *exec.Cmd
- func LoadClientset() (*clientset.Clientset, error)
- func LoadConfig() (*restclient.Config, error)
- func LoadYamlFromUrl(url string) (*unstructured.Unstructured, error)
- func LookForRegexp(expectedRegexp string, timeout time.Duration, fn func() string) (result string, err error)
- func LookForRegexpInLog(ctxData ContextData, podName, container, expectedRegexp string, ...) (result string, err error)
- func LookForString(expectedString string, timeout time.Duration, fn func() string) (result string, err error)
- func LookForStringInLog(ctxData ContextData, podName, container, expectedString string, ...) (result string, err error)
- func RegisterFlags()
- func RemoveCleanupAction(action ActionType, p CleanupActionHandle)
- func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error)
- func Retry(interval time.Duration, maxRetries int, f ConditionFunc) error
- func RetryWithContext(ctx context.Context, interval time.Duration, f ConditionFunc) error
- func RunCleanupActions(action ActionType)
- func RunKubectl(ctxData ContextData, args ...string) (string, error)
- func RunKubectlOrDie(ctxData ContextData, args ...string) string
- func WaitForDaemonSet(kubeclient kubernetes.Interface, namespace, name string, count int, ...) error
- func WaitForDeletion(dynclient client.Client, obj runtime.Object, ...) error
- func WaitForDeployment(kubeclient kubernetes.Interface, namespace, name string, replicas int, ...) error
- func WaitForDeploymentDeleted(ctx context.Context, kubeclient kubernetes.Interface, namespace, name string) error
- func WaitForNamespacesDeleted(c clientset.Interface, namespaces []string, timeout time.Duration) error
- func WaitForStatefulSet(kubeclient kubernetes.Interface, namespace, name string, count int, ...) error
- type ActionType
- type Builder
- type CleanupActionHandle
- type ClientSet
- type ConditionFunc
- type ConfigMapData
- type ContainerBuilder
- func (cb *ContainerBuilder) AddArgs(args ...string) *ContainerBuilder
- func (cb *ContainerBuilder) AddVolumeMountConfigMapData(volumeName string, mountPath string, readOnly bool) *ContainerBuilder
- func (cb *ContainerBuilder) Build() v1.Container
- func (cb *ContainerBuilder) EnvVar(variable, value string) *ContainerBuilder
- func (cb *ContainerBuilder) ImagePullPolicy(policy string) *ContainerBuilder
- func (cb *ContainerBuilder) WithCommands(commands ...string) *ContainerBuilder
- type ContextData
- func (c *ContextData) AddNamespacesToDelete(namespaces ...*corev1.Namespace)
- func (c *ContextData) CreateConfigMapData(name string, data ...ConfigMapData) (*v1.ConfigMap, error)
- func (c *ContextData) CreateNamespace(clientSet *clientset.Clientset, baseName string, labels map[string]string) *corev1.Namespace
- func (c *ContextData) CreateResource(resourceType ResourceType, obj *unstructured.Unstructured, ...) (*unstructured.Unstructured, error)
- func (c *ContextData) CreateResourceGroupVersion(gv schema.GroupVersionResource, obj *unstructured.Unstructured, ...) (*unstructured.Unstructured, error)
- func (c *ContextData) DeleteNamespace(ns *corev1.Namespace) []error
- func (c *ContextData) DeleteResource(resourceType ResourceType, name string, options v1.DeleteOptions, ...) error
- func (c *ContextData) DeleteResourceGroupVersion(gv schema.GroupVersionResource, name string, options v1.DeleteOptions, ...) error
- func (c *ContextData) GenerateNamespace() (*corev1.Namespace, error)
- func (c *ContextData) GetDaemonSet(name string) (*appsv1.DaemonSet, error)
- func (c *ContextData) GetDeployment(name string) (*appsv1.Deployment, error)
- func (c *ContextData) GetLogs(podName string) (string, error)
- func (c *ContextData) GetResource(resourceType ResourceType, name string) (*unstructured.Unstructured, error)
- func (c *ContextData) GetResourceGroupVersion(gv schema.GroupVersionResource, name string) (*unstructured.Unstructured, error)
- func (c *ContextData) GetSecret(name string) (*corev1.Secret, error)
- func (c *ContextData) GetService(name string) (*corev1.Service, error)
- func (c *ContextData) IsOpenShift() bool
- func (c *ContextData) ListPodsForDeployment(deployment *appsv1.Deployment) (*corev1.PodList, error)
- func (c *ContextData) ListPodsForDeploymentName(name string) (*corev1.PodList, error)
- func (c *ContextData) ListResources(resourceType ResourceType) (*unstructured.UnstructuredList, error)
- func (c *ContextData) ListResourcesGroupVersion(gv schema.GroupVersionResource) (*unstructured.UnstructuredList, error)
- func (c *ContextData) WaitForPodStatus(podName string, status v1.PodPhase, timeout time.Duration, ...) (*v1.Pod, error)
- func (c *ContextData) WaitForService(name string, timeout time.Duration, interval time.Duration) (*corev1.Service, error)
- type Framework
- func (f *Framework) AfterEach()
- func (f *Framework) AfterSuite()
- func (f *Framework) BeforeEach(contexts ...string)
- func (f *Framework) GetFirstContext() *ContextData
- func (f *Framework) SetOperatorBuilders(builders ...operators.OperatorSetupBuilder)
- func (f *Framework) Setup() error
- func (f *Framework) TeardownEach() error
- func (f *Framework) TeardownSuite() error
- type KubectlBuilder
- func NewKubectlCommand(ctxData ContextData, args ...string) *KubectlBuilder
- func NewKubectlCommandTimeout(ctxData ContextData, timeout time.Duration, args ...string) *KubectlBuilder
- func NewKubectlExecCommand(ctxData ContextData, pod string, timeout time.Duration, commandArgs ...string) *KubectlBuilder
- type PodBuilder
- func (p *PodBuilder) AddConfigMapVolumeSource(name string, configMapName string) *PodBuilder
- func (p *PodBuilder) AddContainer(c v1.Container) *PodBuilder
- func (p *PodBuilder) AddLabel(key, value string) *PodBuilder
- func (p *PodBuilder) Build() *v1.Pod
- func (p *PodBuilder) RestartPolicy(policy string) *PodBuilder
- type ResourceType
- type RetryError
- type TestContextType
Constants ¶
const (
NamespaceCleanupTimeout = 2 * time.Minute
)
const ( // Poll is how often to Poll pods Poll = 2 * time.Second )
Variables ¶
var ( RetryInterval = time.Second * 5 Timeout = time.Second * 600 CleanupRetryInterval = time.Second * 1 CleanupTimeout = time.Second * 5 )
var (
RunID = uuid.NewUUID()
)
Functions ¶
func AfterReadingAllFlags ¶
func AfterReadingAllFlags(t *TestContextType)
AfterReadingAllFlags makes changes to the context after all flags have been read.
func ContainsAll ¶
func ContainsAll(model, target []interface{}) bool
ContainsAll can be used to compare two sorted slices and validate both are not nil and all elements from given model are present on the target instance.
func DeleteNamespaces ¶
DeleteNamespaces deletes all namespaces that match the given delete and skip filters. Filter is by simple strings.Contains; first skip filter, then delete filter. Returns the list of deleted namespaces or an error.
func ExpectError ¶
func ExpectError(err error, explain ...interface{})
ExpectError expects an error happens, otherwise an exception raises
func ExpectNoError ¶
func ExpectNoError(err error, explain ...interface{})
ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.
func ExpectNoErrorWithOffset ¶
ExpectNoErrorWithOffset checks if "err" is set, and if so, fails assertion while logging the error at "offset" levels above its caller (for example, for call chain f -> g -> ExpectNoErrorWithOffset(1, ...) error would be logged for "f").
func ExpectNoErrorWithRetries ¶
ExpectNoErrorWithRetries checks if an error occurs with the given retry count.
func FromInts ¶
func FromInts(m []int) []interface{}
FromInts returns an interface array with sorted elements from int array
func FromStrings ¶
func FromStrings(m []string) []interface{}
FromStrings returns an interface array with sorted elements from string array
func GetPorts ¶
GetPorts returns an int slice with all ports exposed by the provided corev1.Service object
func IsRetryFailure ¶
func KubectlCmd ¶
func KubectlCmd(ctxData ContextData, args ...string) *exec.Cmd
KubectlCmd runs the kubectl executable through the wrapper script.
func LoadClientset ¶
LoadClientset returns clientset for connecting to kubernetes clusters.
func LoadConfig ¶
func LoadConfig() (*restclient.Config, error)
LoadConfig returns a config for a rest client.
func LoadYamlFromUrl ¶ added in v0.1.2
func LoadYamlFromUrl(url string) (*unstructured.Unstructured, error)
func LookForRegexp ¶
func LookForRegexp(expectedRegexp string, timeout time.Duration, fn func() string) (result string, err error)
LookForRegexp looks for the given regexp in results from given "func() string"
func LookForRegexpInLog ¶
func LookForRegexpInLog(ctxData ContextData, podName, container, expectedRegexp string, timeout time.Duration) (result string, err error)
LookForRegexpInLog looks for the given regexp in the log of a specific pod container
func LookForString ¶
func LookForString(expectedString string, timeout time.Duration, fn func() string) (result string, err error)
LookForString looks for the given string in the output of fn, repeatedly calling fn until the timeout is reached or the string is found. Returns last log and possibly error if the string was not found. TODO(alejandrox1): move to pod/ subpkg once kubectl methods are refactored.
func LookForStringInLog ¶
func LookForStringInLog(ctxData ContextData, podName, container, expectedString string, timeout time.Duration) (result string, err error)
LookForStringInLog looks for the given string in the log of a specific pod container
func RemoveCleanupAction ¶
func RemoveCleanupAction(action ActionType, p CleanupActionHandle)
RemoveCleanupAction removes a function that was installed by AddCleanupAction.
func RestclientConfig ¶
func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error)
RestclientConfig returns a config holds the information needed to build connection to kubernetes clusters.
func Retry ¶
func Retry(interval time.Duration, maxRetries int, f ConditionFunc) error
Retry retries f every interval until after maxRetries. The interval won't be affected by how long f takes. For example, if interval is 3s, f takes 1s, another f will be called 2s later. However, if f takes longer than interval, it will be delayed.
func RetryWithContext ¶
RetryWithContext retries f every interval until the specified context times out.
func RunCleanupActions ¶
func RunCleanupActions(action ActionType)
RunCleanupActions runs all functions installed by AddCleanupAction. It does not remove them (see RemoveCleanupAction) but it does run unlocked, so they may remove themselves.
func RunKubectl ¶
func RunKubectl(ctxData ContextData, args ...string) (string, error)
RunKubectl is a convenience wrapper over kubectlBuilder
func RunKubectlOrDie ¶
func RunKubectlOrDie(ctxData ContextData, args ...string) string
RunKubectlOrDie is a convenience wrapper over kubectlBuilder
func WaitForDaemonSet ¶
func WaitForDeletion ¶
func WaitForDeployment ¶
func WaitForNamespacesDeleted ¶
func WaitForNamespacesDeleted(c clientset.Interface, namespaces []string, timeout time.Duration) error
WaitForNamespacesDeleted waits for the namespaces to be deleted.
func WaitForStatefulSet ¶
Types ¶
type ActionType ¶
type ActionType int
Action type to be enqueued
const ( AfterEach ActionType = iota AfterSuite )
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Framework Builder type
func NewFrameworkBuilder ¶
Helper for building frameworks with possible customizations
func (Builder) WithBuilders ¶
func (b Builder) WithBuilders(builders ...operators.OperatorSetupBuilder) Builder
Customize builders, by default when "BeforeEach" runs, the Framework iterates through all supported operators (from SupportedOperators map) and initializes all the default builder instances.
func (Builder) WithContexts ¶
Customize contexts to use (default is the current-context only)
type CleanupActionHandle ¶
type CleanupActionHandle *int
CleanupActionHandle is an integer pointer type for handling cleanup action
func AddCleanupAction ¶
func AddCleanupAction(action ActionType, fn func()) CleanupActionHandle
AddCleanupAction installs a function that will be called in the event of completion of a test Spec or a test Suite. This allows arbitrary pieces of the overall test to hook into AfterEach() and SynchronizedAfterSuite().
type ConditionFunc ¶
type ConfigMapData ¶
ConfigMapData makes it simpler to provide multiple data elements for a new ConfigMap
type ContainerBuilder ¶
type ContainerBuilder struct {
// contains filtered or unexported fields
}
ContainerBuilder
func NewContainerBuilder ¶
func NewContainerBuilder(name string, image string) *ContainerBuilder
NewContainerBuilder creates an instance of a ContainerBuilder helper
func (*ContainerBuilder) AddArgs ¶
func (cb *ContainerBuilder) AddArgs(args ...string) *ContainerBuilder
AddArgs appends a given list of arguments to the existing
func (*ContainerBuilder) AddVolumeMountConfigMapData ¶
func (cb *ContainerBuilder) AddVolumeMountConfigMapData(volumeName string, mountPath string, readOnly bool) *ContainerBuilder
AddVolumeMountConfigMapData add a VolumeMount entry to the container that must be related with a valid Volume defined in the Pod Spec.
func (*ContainerBuilder) Build ¶
func (cb *ContainerBuilder) Build() v1.Container
Build returns the prepared Container to be used within a Pod
func (*ContainerBuilder) EnvVar ¶
func (cb *ContainerBuilder) EnvVar(variable, value string) *ContainerBuilder
EnvVar sets an environment variable into the container
func (*ContainerBuilder) ImagePullPolicy ¶
func (cb *ContainerBuilder) ImagePullPolicy(policy string) *ContainerBuilder
ImagePullPolicy sets the ImagePullPolicy for the given container. Default is PullAlways.
func (*ContainerBuilder) WithCommands ¶
func (cb *ContainerBuilder) WithCommands(commands ...string) *ContainerBuilder
WithCommands set the list of commands to use with the new container
type ContextData ¶
type ContextData struct { Id string Clients ClientSet Namespace string // Set together with creating the ClientSet and the namespace. // Guaranteed to be unique in the cluster even when running the same // test multiple times in parallel. UniqueName string CertManagerPresent bool // if crd is detected OperatorMap map[operators.OperatorType]operators.OperatorSetup EventHandler events.EventHandler // contains filtered or unexported fields }
ContextData holds clients and data related with namespaces
created within
func (*ContextData) AddNamespacesToDelete ¶
func (c *ContextData) AddNamespacesToDelete(namespaces ...*corev1.Namespace)
func (*ContextData) CreateConfigMapData ¶
func (c *ContextData) CreateConfigMapData(name string, data ...ConfigMapData) (*v1.ConfigMap, error)
CreateConfigMapData helper method to generate a ConfiMap using configuration Data
func (*ContextData) CreateNamespace ¶
func (c *ContextData) CreateNamespace(clientSet *clientset.Clientset, baseName string, labels map[string]string) *corev1.Namespace
CreateNamespace creates a namespace for e2e testing.
func (*ContextData) CreateResource ¶ added in v0.1.2
func (c *ContextData) CreateResource(resourceType ResourceType, obj *unstructured.Unstructured, options v1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error)
CreateResource creates a resource based on provided (known) resource type and unstructured data
func (*ContextData) CreateResourceGroupVersion ¶ added in v0.1.2
func (c *ContextData) CreateResourceGroupVersion(gv schema.GroupVersionResource, obj *unstructured.Unstructured, options v1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error)
func (*ContextData) DeleteNamespace ¶
func (c *ContextData) DeleteNamespace(ns *corev1.Namespace) []error
func (*ContextData) DeleteResource ¶ added in v0.1.2
func (c *ContextData) DeleteResource(resourceType ResourceType, name string, options v1.DeleteOptions, subresources ...string) error
DeleteResource deletes a resource based on provided (known) resource type and name
func (*ContextData) DeleteResourceGroupVersion ¶ added in v0.1.2
func (c *ContextData) DeleteResourceGroupVersion(gv schema.GroupVersionResource, name string, options v1.DeleteOptions, subresources ...string) error
func (*ContextData) GenerateNamespace ¶
func (c *ContextData) GenerateNamespace() (*corev1.Namespace, error)
GenerateNamespace creates a namespace with a random name.
func (*ContextData) GetDaemonSet ¶
func (c *ContextData) GetDaemonSet(name string) (*appsv1.DaemonSet, error)
func (*ContextData) GetDeployment ¶
func (c *ContextData) GetDeployment(name string) (*appsv1.Deployment, error)
func (*ContextData) GetLogs ¶
func (c *ContextData) GetLogs(podName string) (string, error)
returns whole pod log as a (meaty) string
func (*ContextData) GetResource ¶
func (c *ContextData) GetResource(resourceType ResourceType, name string) (*unstructured.Unstructured, error)
GetResource returns the given resource type, identified by its given name
func (*ContextData) GetResourceGroupVersion ¶ added in v0.1.2
func (c *ContextData) GetResourceGroupVersion(gv schema.GroupVersionResource, name string) (*unstructured.Unstructured, error)
func (*ContextData) GetSecret ¶
func (c *ContextData) GetSecret(name string) (*corev1.Secret, error)
func (*ContextData) GetService ¶
func (c *ContextData) GetService(name string) (*corev1.Service, error)
func (*ContextData) IsOpenShift ¶
func (c *ContextData) IsOpenShift() bool
func (*ContextData) ListPodsForDeployment ¶
func (c *ContextData) ListPodsForDeployment(deployment *appsv1.Deployment) (*corev1.PodList, error)
func (*ContextData) ListPodsForDeploymentName ¶
func (c *ContextData) ListPodsForDeploymentName(name string) (*corev1.PodList, error)
func (*ContextData) ListResources ¶
func (c *ContextData) ListResources(resourceType ResourceType) (*unstructured.UnstructuredList, error)
ListResources returns a list of resources found in the related Framework's namespace, for the given resource type
func (*ContextData) ListResourcesGroupVersion ¶ added in v0.1.2
func (c *ContextData) ListResourcesGroupVersion(gv schema.GroupVersionResource) (*unstructured.UnstructuredList, error)
func (*ContextData) WaitForPodStatus ¶ added in v0.1.2
type Framework ¶
type Framework struct { BaseName string // Map that ties clients and namespaces for each available context ContextMap map[string]*ContextData SkipNamespaceCreation bool // Whether to skip creating a namespace // contains filtered or unexported fields }
func (*Framework) AfterEach ¶
func (f *Framework) AfterEach()
AfterEach deletes the namespace, after reading its events.
func (*Framework) AfterSuite ¶
func (f *Framework) AfterSuite()
AfterSuite deletes the cluster level resources
func (*Framework) BeforeEach ¶
BeforeEach gets clients and makes a namespace
func (*Framework) GetFirstContext ¶
func (f *Framework) GetFirstContext() *ContextData
GetFirstContext returns the first entry in the ContextMap or nil if none
func (*Framework) SetOperatorBuilders ¶
func (f *Framework) SetOperatorBuilders(builders ...operators.OperatorSetupBuilder)
Defines a custom set of builders for the given Framework instance
func (*Framework) TeardownEach ¶
func (*Framework) TeardownSuite ¶
type KubectlBuilder ¶
type KubectlBuilder struct {
// contains filtered or unexported fields
}
KubectlBuilder is used to build, customize and execute a kubectl Command. Add more functions to customize the builder as needed.
func NewKubectlCommand ¶
func NewKubectlCommand(ctxData ContextData, args ...string) *KubectlBuilder
NewKubectlCommand returns a KubectlBuilder for running kubectl.
func NewKubectlCommandTimeout ¶
func NewKubectlCommandTimeout(ctxData ContextData, timeout time.Duration, args ...string) *KubectlBuilder
NewKubectlCommandTimeout returns a KubectlBuilder with a timeout defined, for running kubectl.
func NewKubectlExecCommand ¶
func NewKubectlExecCommand(ctxData ContextData, pod string, timeout time.Duration, commandArgs ...string) *KubectlBuilder
NewKubectlExecCommand returns a KubectlBuilder prepared to execute a given command in a running pod.
func (KubectlBuilder) Exec ¶
func (b KubectlBuilder) Exec() (string, error)
Exec runs the kubectl executable.
func (KubectlBuilder) ExecOrDie ¶
func (b KubectlBuilder) ExecOrDie() string
ExecOrDie runs the kubectl executable or dies if error occurs.
type PodBuilder ¶
type PodBuilder struct {
// contains filtered or unexported fields
}
PodBuilder
func NewPodBuilder ¶
func NewPodBuilder(name string, namespace string) *PodBuilder
NewPodBuilder Creates an instance of a PodBuilder helper
func (*PodBuilder) AddConfigMapVolumeSource ¶
func (p *PodBuilder) AddConfigMapVolumeSource(name string, configMapName string) *PodBuilder
AddConfigMapVolumeSource append a Volume with a local reference to a ConfigMap into the Pod Spec
func (*PodBuilder) AddContainer ¶
func (p *PodBuilder) AddContainer(c v1.Container) *PodBuilder
AddContainer adds a container to the Pod being prepared
func (*PodBuilder) AddLabel ¶
func (p *PodBuilder) AddLabel(key, value string) *PodBuilder
AddLabel Adds or replaces the given label key and value to Pod
func (*PodBuilder) Build ¶
func (p *PodBuilder) Build() *v1.Pod
Build returns the prepared Pod instance
func (*PodBuilder) RestartPolicy ¶
func (p *PodBuilder) RestartPolicy(policy string) *PodBuilder
RestartPolicy defines the RestartPolicy of the Pod. Default is Never.
type ResourceType ¶
type ResourceType int
const ( Issuers ResourceType = iota Certificates Deployments )
type RetryError ¶
type RetryError struct {
// contains filtered or unexported fields
}
func (*RetryError) Error ¶
func (e *RetryError) Error() string
type TestContextType ¶
type TestContextType struct { KubeConfig string KubeContexts contextNames CertDir string Host string RepoRoot string KubectlPath string OutputDir string ReportDir string ReportPrefix string Prefix string DeleteNamespace bool DeleteNamespaceOnFailure bool CleanStart bool }
TestContextType contains test settings and global state.
var TestContext TestContextType
TestContext should be used by all tests to access validation context data.
func (TestContextType) ContextsAvailable ¶
func (t TestContextType) ContextsAvailable() int
ContextsAvailable returns the number of contexts available after parsing command line arguments.
func (TestContextType) GetContexts ¶
func (t TestContextType) GetContexts() []string
GetContexts returns a list of contexts from provided flags or the current-context if none. If KubeConfig not provided or not generated, it returns nil.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ginkgowrapper wraps Ginkgo Fail and Skip functions to panic with structured data instead of a constant string.
|
Package ginkgowrapper wraps Ginkgo Fail and Skip functions to panic with structured data instead of a constant string. |