Version: v0.0.0-...-576d2b3 Latest Latest

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

Go to latest
Published: Aug 26, 2021 License: Apache-2.0 Imports: 50 Imported by: 0




View Source
const (
	NamespaceCleanupTimeout = 2 * time.Minute
View Source
const (
	// Poll is how often to Poll pods
	Poll = 2 * time.Second


View Source
var (
	RetryInterval        = time.Second * 5
	Timeout              = time.Second * 180
	TimeoutSuite         = time.Second * 1200
	CleanupRetryInterval = time.Second * 1
	CleanupTimeout       = time.Second * 5
	GVR                  = groupName + "/" + apiVersion
View Source
var (
	RunID = uuid.NewUUID()


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 CreateResourcesFromYAML

func CreateResourcesFromYAML(kubeClient clientset.Interface, dynClient dynamic.Interface, namespace, fileOrUrl string) error

CreateResourcesFromYAML creates all resources from the provided YAML file or URL using an initialized VanClient instance.

func DeleteNamespaces

func DeleteNamespaces(c clientset.Interface, deleteFilter, skipFilter []string) ([]string, error)

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

func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{})

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

func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{})

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

func GetPorts(service corev1.Service) []int

GetPorts returns an int slice with all ports exposed by the provided corev1.Service object

func HandleFlags

func HandleFlags()

HandleFlags sets up all flags and parses the command line.

func HasAlreadyExistsSuffix

func HasAlreadyExistsSuffix(err error) bool

HasAlreadyExistsSuffix returns true if the string representation of the error ends with "already exists".

func IsRetryFailure

func IsRetryFailure(err error) bool

func KubectlCmd

func KubectlCmd(args ...string) *exec.Cmd

KubectlCmd runs the kubectl executable through the wrapper script.

func LoadClientset

func LoadClientset() (*clientset.Clientset, error)

LoadClientset returns clientset for connecting to kubernetes clusters.

func LoadConfig

func LoadConfig() (*restclient.Config, error)

LoadConfig returns a config for a rest client.

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(ns, 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(ns, 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 RegisterFlags

func RegisterFlags()

RegisterFlags registers flags for e2e test suites.

func RemoveCleanupAction

func RemoveCleanupAction(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

func RetryWithContext(ctx context.Context, interval time.Duration, f ConditionFunc) error

RetryWithContext retries f every interval until the specified context times out.

func RunCleanupActions

func RunCleanupActions()

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(args ...string) (string, error)

RunKubectl is a convenience wrapper over kubectlBuilder

func RunKubectlOrDie

func RunKubectlOrDie(args ...string) string

RunKubectlOrDie is a convenience wrapper over kubectlBuilder

func WaitForDaemonSet

func WaitForDaemonSet(kubeclient kubernetes.Interface, namespace, name string, count int, retryInterval, timeout time.Duration) error

func WaitForDeletion

func WaitForDeletion(dynclient client.Client, obj runtime.Object, retryInterval, timeout time.Duration) error

func WaitForDeployment

func WaitForDeployment(kubeclient kubernetes.Interface, namespace, name string, replicas int, retryInterval, timeout time.Duration) error

func WaitForDeploymentDeleted

func WaitForDeploymentDeleted(ctx context.Context, kubeclient kubernetes.Interface, namespace, name string) error

func WaitForNamespacesDeleted

func WaitForNamespacesDeleted(c clientset.Interface, namespaces []string, timeout time.Duration) error

WaitForNamespacesDeleted waits for the namespaces to be deleted.


type CleanupActionHandle

type CleanupActionHandle *int

CleanupActionHandle is an integer pointer type for handling cleanup action

func AddCleanupAction

func AddCleanupAction(fn func()) CleanupActionHandle

AddCleanupAction installs a function that will be called in the event of the whole test being terminated. This allows arbitrary pieces of the overall test to hook into SynchronizedAfterSuite().

type ConditionFunc

type ConditionFunc func() (bool, error)

type Framework

type Framework struct {
	BaseName 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

	KubeClient clientset.Interface
	ExtClient  apiextension.Interface
	QdrClient  qdrclient.Interface
	DynClient  dynamic.Interface
	OcpClient  ocpClient

	CertManagerPresent    bool // if crd is detected
	SkipNamespaceCreation bool // Whether to skip creating a namespace
	KeepCRD               bool // Whether to preserve CRD on cleanup
	Namespace             string
	// contains filtered or unexported fields

func NewFramework

func NewFramework(baseName string, client clientset.Interface) *Framework

NewFramework creates a test framework

func (*Framework) AddNamespacesToDelete

func (f *Framework) AddNamespacesToDelete(namespaces ...*corev1.Namespace)

func (*Framework) AfterEach

func (f *Framework) AfterEach()

AfterEach deletes the namespace, after reading its events.

func (*Framework) BeforeEach

func (f *Framework) BeforeEach()

BeforeEach gets clients and makes a namespace

func (*Framework) CreateInterconnect

func (f *Framework) CreateInterconnect(namespace string, size int32, fn ...InterconnectCustomizer) (*v1alpha1.Interconnect, error)

CreateInterconnect creates an interconnect resource

func (*Framework) CreateNamespace

func (f *Framework) CreateNamespace(clientSet *clientset.Clientset,
	baseName string, labels map[string]string) *corev1.Namespace

CreateNamespace creates a namespace for e2e testing.

func (*Framework) DeleteInterconnect

func (f *Framework) DeleteInterconnect(interconnect *v1alpha1.Interconnect) error

func (*Framework) DeleteNamespace

func (f *Framework) DeleteNamespace(ns *corev1.Namespace) []error

func (*Framework) GenerateNamespace

func (f *Framework) GenerateNamespace() (*corev1.Namespace, error)

GenerateNamespace creates a namespace with a random name.

func (*Framework) GetDaemonSet

func (f *Framework) GetDaemonSet(name string) (*appsv1.DaemonSet, error)

func (*Framework) GetDeployment

func (f *Framework) GetDeployment(name string) (*appsv1.Deployment, error)

func (*Framework) GetInterconnect

func (f *Framework) GetInterconnect(name string) (*v1alpha1.Interconnect, error)

func (*Framework) GetInterconnectPodNames

func (f *Framework) GetInterconnectPodNames(ic *v1alpha1.Interconnect) ([]string, error)

GetInterconnectPodNames returns all pod names for the given interconnect instance

func (*Framework) GetInterconnectPods

func (f *Framework) GetInterconnectPods(ic *v1alpha1.Interconnect) ([]v1.Pod, error)

GetInterconnectPods returns all pods for the given interconnect instance

func (*Framework) GetResource

func (f *Framework) GetResource(resourceType ResourceType, name string) (*unstructured.Unstructured, error)

GetResource returns the given resource type, identified by its given name

func (*Framework) GetSecret

func (f *Framework) GetSecret(name string) (*corev1.Secret, error)

func (*Framework) GetService

func (f *Framework) GetService(name string) (*corev1.Service, error)

func (*Framework) InterconnectHasExpectedSize

func (f *Framework) InterconnectHasExpectedSize(interconnect *v1alpha1.Interconnect, expectedSize int) (bool, error)

func (*Framework) InterconnectHasExpectedVersion

func (f *Framework) InterconnectHasExpectedVersion(interconnect *v1alpha1.Interconnect, expectedVersion string) (bool, error)

func (*Framework) IsOpenShift

func (f *Framework) IsOpenShift() bool

func (*Framework) ListPodsForDeployment

func (f *Framework) ListPodsForDeployment(deployment *appsv1.Deployment) (*corev1.PodList, error)

func (*Framework) ListResources

func (f *Framework) 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 (*Framework) PodsForInterconnect

func (f *Framework) PodsForInterconnect(interconnect *v1alpha1.Interconnect) ([]corev1.Pod, error)

func (*Framework) Setup

func (f *Framework) Setup() error

func (*Framework) Teardown

func (f *Framework) Teardown() error

func (*Framework) UpdateInterconnect

func (f *Framework) UpdateInterconnect(interconnect *v1alpha1.Interconnect) (*v1alpha1.Interconnect, error)

func (*Framework) VersionForPod

func (f *Framework) VersionForPod(pod corev1.Pod) (string, error)

func (*Framework) WaitForNewInterconnectPods

func (f *Framework) WaitForNewInterconnectPods(ctx context.Context, initialPodNames []string, interconnect *v1alpha1.Interconnect, retryInterval, timeout time.Duration) error

func (*Framework) WaitForPodStatus

func (f *Framework) WaitForPodStatus(podName string, status v1.PodPhase, timeout time.Duration, interval time.Duration) (*v1.Pod, error)

WaitForPodStatus waits for given podName to be available with a matching PodPhase

or it returns a timeout.

func (*Framework) WaitUntilFullInterconnectWithSize

func (f *Framework) WaitUntilFullInterconnectWithSize(ctx context.Context, interconnect *v1alpha1.Interconnect, expectedSize int) error

WaitUntilFullInterconnectWithSize waits until all the pods belonging to the Interconnect deployment report the expected state and size. The expected state will differs for interior versus edge roles

func (*Framework) WaitUntilFullInterconnectWithVersion

func (f *Framework) WaitUntilFullInterconnectWithVersion(ctx context.Context, interconnect *v1alpha1.Interconnect, expectedSize int, expectedVersion string) error

WaitUntilFullInterconnectWithVersion waits until all the pods belonging to the Interconnect deployment report the expected state and expected version (if one has been provided). The expected state will differs for interior versus edge roles

type InterconnectCustomizer

type InterconnectCustomizer func(interconnect *v1alpha1.Interconnect)

InterconnectCustomizer represents a function that allows for customizing an Interconnect resource before it is created.

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(args ...string) *KubectlBuilder

NewKubectlCommand returns a KubectlBuilder for running kubectl.

func NewKubectlCommandTimeout

func NewKubectlCommandTimeout(timeout time.Duration, args ...string) *KubectlBuilder

NewKubectlCommandTimeout returns a KubectlBuilder with a timeout defined, for running kubectl.

func NewKubectlExecCommand

func NewKubectlExecCommand(f *Framework, 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 ResourceType

type ResourceType int
const (
	Issuers ResourceType = iota

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
	KubeContext              string
	CertDir                  string
	Host                     string
	RepoRoot                 string
	KubectlPath              string
	OutputDir                string
	ReportDir                string
	ReportPrefix             string
	Prefix                   string
	QdrImage                 string
	OperatorImage            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 common context data.


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.

Jump to

Keyboard shortcuts

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