framework

package
v0.17.1-beta.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 36 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PollTimeout              = time.Minute
	DefaultVclusterName      = "vcluster"
	DefaultVclusterNamespace = "vcluster"
	DefaultClientTimeout     = 32 * time.Second // the default in client-go is 32
)

Variables

View Source
var DefaultFramework = &Framework{}

Functions

func CreateFramework

func CreateFramework(ctx context.Context, scheme *runtime.Scheme) error

func ExpectConsistOf

func ExpectConsistOf(actual interface{}, extra interface{}, explain ...interface{})

ExpectConsistOf expects actual contains precisely the extra elements. The ordering of the elements does not matter.

func ExpectEmpty

func ExpectEmpty(actual interface{}, explain ...interface{})

ExpectEmpty expects actual is empty

func ExpectEqual

func ExpectEqual(actual interface{}, extra interface{}, explain ...interface{})

ExpectEqual expects the specified two are the same, otherwise an exception raises

func ExpectError

func ExpectError(err error, explain ...interface{})

ExpectError expects an error happens, otherwise an exception raises

func ExpectHaveKey

func ExpectHaveKey(actual interface{}, key interface{}, explain ...interface{})

ExpectHaveKey expects the actual map has the key in the keyset

func ExpectMatchRegexp

func ExpectMatchRegexp(actual string, regexp string, explain ...interface{})

ExpectMatchRegexp expects the string to match the provided regular expression

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 ExpectNotEmpty added in v0.13.0

func ExpectNotEmpty(actual interface{}, explain ...interface{})

func ExpectNotEqual

func ExpectNotEqual(actual interface{}, extra interface{}, explain ...interface{})

ExpectNotEqual expects the specified two are not the same, otherwise an exception raises

func Failf

func Failf(format string, args ...interface{})

ExpectMatchRegexp expects the string to match the provided regular expression

func RunKubectl

func RunKubectl(kubeconfigPath, namespace string, args ...string) (string, error)

RunKubectl is a convenience wrapper over kubectlBuilder

func RunKubectlInput

func RunKubectlInput(kubeconfigPath, namespace string, data string, args ...string) (string, error)

RunKubectlInput is a convenience wrapper over kubectlBuilder that takes input to stdin

func RunKubectlOrDie

func RunKubectlOrDie(kubeconfigPath, namespace string, args ...string) string

RunKubectlOrDie is a convenience wrapper over kubectlBuilder

func RunKubectlOrDieInput

func RunKubectlOrDieInput(kubeconfigPath, namespace string, data string, args ...string) string

RunKubectlOrDieInput is a convenience wrapper over kubectlBuilder that takes input to stdin

func RunKubectlWithFullOutput

func RunKubectlWithFullOutput(kubeconfigPath, namespace string, args ...string) (string, string, error)

RunKubectlWithFullOutput is a convenience wrapper over kubectlBuilder It will also return the command's stderr.

Types

type Framework

type Framework struct {
	// The context to use for testing
	Context context.Context

	// VclusterName is the name of the vcluster instance which we are testing
	VclusterName string

	// VclusterNamespace is the namespace in host cluster of the current
	// vcluster instance which we are testing
	VclusterNamespace string

	// The suffix to append to the synced resources in the host namespace
	Suffix string

	// HostConfig is the kubernetes rest config of the
	// host kubernetes cluster were we are testing in
	HostConfig *rest.Config

	// HostClient is the kubernetes client of the current
	// host kubernetes cluster were we are testing in
	HostClient *kubernetes.Clientset

	// HostCRClient is the controller runtime client of the current
	// host kubernetes cluster were we are testing in
	HostCRClient client.Client

	// VclusterConfig is the kubernetes rest config of the current
	// vcluster instance which we are testing
	VclusterConfig *rest.Config

	// VclusterClient is the kubernetes client of the current
	// vcluster instance which we are testing
	VclusterClient *kubernetes.Clientset

	// VclusterCRClient is the controller runtime client of the current
	// vcluster instance which we are testing
	VclusterCRClient client.Client

	// VclusterKubeconfigFile is a file containing kube config
	// of the current vcluster instance which we are testing.
	// This file shall be deleted in the end of the test suite execution.
	VclusterKubeconfigFile *os.File

	// Scheme is the global scheme to use
	Scheme *runtime.Scheme

	// Log is the logger that should be used
	Log log.Logger

	// ClientTimeout value used in the clients
	ClientTimeout time.Duration

	// MultiNamespaceMode denotes whether the multi namespace mode is enabled for the virtualcluster
	MultiNamespaceMode bool
}

func (*Framework) Cleanup

func (f *Framework) Cleanup() error

func (*Framework) CreateCurlPod

func (f *Framework) CreateCurlPod(ns string) (*corev1.Pod, error)

func (*Framework) CreateEgressNetworkPolicyForDNS

func (f *Framework) CreateEgressNetworkPolicyForDNS(ctx context.Context, ns string) (*networkingv1.NetworkPolicy, error)

func (*Framework) CreateNginxPodAndService

func (f *Framework) CreateNginxPodAndService(ns string) (*corev1.Pod, *corev1.Service, error)

func (*Framework) DeleteTestNamespace

func (f *Framework) DeleteTestNamespace(ns string, waitUntilDeleted bool) error

func (*Framework) GetDefaultSecurityContext

func (f *Framework) GetDefaultSecurityContext() *corev1.SecurityContext

func (*Framework) TestServiceIsEventuallyReachable

func (f *Framework) TestServiceIsEventuallyReachable(curlPod *corev1.Pod, service *corev1.Service)

func (*Framework) TestServiceIsEventuallyUnreachable

func (f *Framework) TestServiceIsEventuallyUnreachable(curlPod *corev1.Pod, service *corev1.Service)

func (*Framework) WaitForInitManifestConfigMapCreation

func (f *Framework) WaitForInitManifestConfigMapCreation(configMapName, ns string) error

func (*Framework) WaitForPersistentVolumeClaimBound

func (f *Framework) WaitForPersistentVolumeClaimBound(pvcName, ns string) error

func (*Framework) WaitForPodRunning

func (f *Framework) WaitForPodRunning(podName string, ns string) error

func (*Framework) WaitForPodToComeUpWithEphemeralContainers

func (f *Framework) WaitForPodToComeUpWithEphemeralContainers(podName string, ns string) error

func (*Framework) WaitForPodToComeUpWithReadinessConditions

func (f *Framework) WaitForPodToComeUpWithReadinessConditions(podName string, ns string) error

func (*Framework) WaitForService

func (f *Framework) WaitForService(serviceName string, ns string) error

func (*Framework) WaitForServiceAccount

func (f *Framework) WaitForServiceAccount(saName string, ns string) error

func (*Framework) WaitForServiceInSyncerCache

func (f *Framework) WaitForServiceInSyncerCache(serviceName string, ns string) error

Some vcluster operations list Service, e.g. pod translation. To ensure expected results of such operation we need to wait until newly created Service is in syncer controller cache, otherwise syncer will operate on slightly outdated resources, which is not good for test stability. This function ensures that Service is actually in controller cache by making an update and checking for it in physical service.

type KubectlBuilder

type KubectlBuilder struct {
	// contains filtered or unexported fields
}

Adopted from k8s test suite - https://github.com/kubernetes/kubernetes/blob/f2576efecdf2d902b12a3fedae7995311d4febfa/test/e2e/framework/util.go#L552-L687 KubectlBuilder is used to build, customize and execute a kubectl Command. Add more functions to customize the builder as needed.

func NewKubectlCommand

func NewKubectlCommand(kubeconfigPath, namespace string, args ...string) *KubectlBuilder

NewKubectlCommand returns a KubectlBuilder for running kubectl.

func (KubectlBuilder) Exec

func (b KubectlBuilder) Exec() (string, error)

Exec runs the kubectl executable.

func (KubectlBuilder) ExecOrDie

func (b KubectlBuilder) ExecOrDie(namespace string) string

ExecOrDie runs the kubectl executable or dies if error occurs.

func (KubectlBuilder) ExecWithFullOutput

func (b KubectlBuilder) ExecWithFullOutput() (string, string, error)

ExecWithFullOutput runs the kubectl executable, and returns the stdout and stderr.

func (*KubectlBuilder) WithEnv

func (b *KubectlBuilder) WithEnv(env []string) *KubectlBuilder

WithEnv sets the given environment and returns itself.

func (KubectlBuilder) WithStdinData

func (b KubectlBuilder) WithStdinData(data string) *KubectlBuilder

WithStdinData sets the given data to stdin and returns itself.

func (KubectlBuilder) WithStdinReader

func (b KubectlBuilder) WithStdinReader(reader io.Reader) *KubectlBuilder

WithStdinReader sets the given reader and returns itself.

func (*KubectlBuilder) WithTimeout

func (b *KubectlBuilder) WithTimeout(t <-chan time.Time) *KubectlBuilder

WithTimeout sets the given timeout and returns itself.

type TestKubeconfig

type TestKubeconfig struct {
	CertDir     string
	Host        string
	KubeConfig  string
	KubeContext string
	KubectlPath string
	Namespace   string // Every test has at least one namespace unless creation is skipped
}

Adopted from k8s test suite - https://github.com/kubernetes/kubernetes/blob/f2576efecdf2d902b12a3fedae7995311d4febfa/test/e2e/framework/kubectl/kubectl_utils.go#L43-L100 TestKubeconfig is a struct containing the needed attributes from TestContext and Framework(Namespace).

func NewTestKubeconfig

func NewTestKubeconfig(kubeconfig, namespace string) *TestKubeconfig

NewTestKubeconfig returns a new Kubeconfig struct instance.

func (*TestKubeconfig) KubectlCmd

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

KubectlCmd runs the kubectl executable through the wrapper script.

Jump to

Keyboard shortcuts

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