framework

package
v0.0.0-...-7f68784 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: Apache-2.0 Imports: 61 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatefulSetPoll indicates poll interval for StatefulSet tests
	StatefulSetPoll = 10 * time.Second
	// StatefulSetTimeout indicates timeout interval for StatefulSet operations
	StatefulSetTimeout = 10 * time.Minute
	// StatefulPodTimeout indicates timeout for stateful pods to change state
	StatefulPodTimeout = 5 * time.Minute
)
View Source
const (
	// PodListTimeout indicates how long to wait for the pod to be listable
	PodListTimeout = time.Minute
	// PodStartTimeout indicates that initial pod start can be delayed O(minutes) by slow docker pulls
	// TODO: Make this 30 seconds once #4566 is resolved.
	PodStartTimeout = 5 * time.Minute

	// PodStartShortTimeout is same as `PodStartTimeout` to wait for the pod to be started, but shorter.
	// Use it case by case when we are sure pod start will not be delayed
	// minutes by slow docker pulls or something else.
	PodStartShortTimeout = 2 * time.Minute

	// PodDeleteTimeout indicates how long to wait for a pod to be deleted
	PodDeleteTimeout = 5 * time.Minute

	// PodEventTimeout is how much we wait for a pod event to occur.
	PodEventTimeout = 2 * time.Minute

	// NamespaceCleanupTimeout indicates:
	// If there are any orphaned namespaces to clean up, this test is running
	// on a long lived cluster. A long wait here is preferably to spurious test
	// failures caused by leaked resources from a previous test run.
	NamespaceCleanupTimeout = 15 * time.Minute

	// ServiceStartTimeout indicates how long to wait for a service endpoint to be resolvable.
	ServiceStartTimeout = 3 * time.Minute

	// Poll indicates how often to Poll pods, nodes and claims.
	Poll = 2 * time.Second

	// ServiceAccountProvisionTimeout indicates a service account provision timeout.
	// service accounts are provisioned after namespace creation
	// a service account is required to support pod creation in a namespace as part of admission control
	ServiceAccountProvisionTimeout = 2 * time.Minute

	// SingleCallTimeout indicates how long to try single API calls (like 'get' or 'list'). Used to prevent
	// transient failures from failing tests.
	// TODO: client should not apply this timeout to Watch calls. Increased from 30s until that is fixed.
	SingleCallTimeout = 5 * time.Minute

	// NodeReadyInitialTimeout indicates how long nodes have to be "ready" when a test begins. They should already
	// be "ready" before the test starts, so this is small.
	NodeReadyInitialTimeout = 20 * time.Second

	// PodReadyBeforeTimeout indicates how long pods have to be "ready" when a test begins.
	PodReadyBeforeTimeout = 5 * time.Minute

	// ClaimProvisionTimeout indicates how long claims have to become dynamically provisioned
	ClaimProvisionTimeout = 5 * time.Minute

	// ClaimProvisionShortTimeout is same as `ClaimProvisionTimeout` to wait for claim to be dynamically provisioned, but shorter.
	// Use it case by case when we are sure this timeout is enough.
	ClaimProvisionShortTimeout = 1 * time.Minute

	// ClaimBindingTimeout indicates how long claims have to become bound
	ClaimBindingTimeout = 3 * time.Minute

	// ClaimDeletingTimeout indicates how long claims have to become deleted
	ClaimDeletingTimeout = 3 * time.Minute

	// PVReclaimingTimeout indicates how long PVs have to beome reclaimed
	PVReclaimingTimeout = 3 * time.Minute

	// PVBindingTimeout indicates how long PVs have to become bound
	PVBindingTimeout = 3 * time.Minute

	// PVDeletingTimeout indicates how long PVs have to become deleted
	PVDeletingTimeout = 3 * time.Minute

	// RestartNodeReadyAgainTimeout indicates how long a node is allowed to become "Ready" after it is restarted before
	// the test is considered failed.
	RestartNodeReadyAgainTimeout = 5 * time.Minute

	// RestartPodReadyAgainTimeout indicates how long a pod is allowed to become "running" and "ready" after a node
	// restart before test is considered failed.
	RestartPodReadyAgainTimeout = 5 * time.Minute
)
View Source
const (

	// DefaultNamespaceDeletionTimeout ref https://github.com/kubernetes/kubernetes/issues/47135
	// TODO(mikedanese): reset this to 5 minutes once #47135 is resolved.
	DefaultNamespaceDeletionTimeout = 10 * time.Minute
)

Variables

View Source
var (
	// UnreachableTaintTemplate is the taint for when a node becomes unreachable.
	UnreachableTaintTemplate = &v1.Taint{
		Key:    schedulerapi.TaintNodeUnreachable,
		Effect: v1.TaintEffectNoExecute,
	}
	// NotReadyTaintTemplate is the taint for when a node doesn't ready.
	NotReadyTaintTemplate = &v1.Taint{
		Key:    schedulerapi.TaintNodeNotReady,
		Effect: v1.TaintEffectNoExecute,
	}
)
View Source
var RunID = uuid.NewUUID()

RunID is a unique identifier of the e2e run

Functions

func AfterReadingAllFlags

func AfterReadingAllFlags(t *TestContextType)

AfterReadingAllFlags makes changes to the context after all flags have been read.

func AllNodesReady

func AllNodesReady(c clientset.Interface, timeout time.Duration) error

AllNodesReady checks whether all registered nodes are ready. TODO: we should change the AllNodesReady call in AfterEach to WaitForAllNodesHealthy, and figure out how to do it in a configurable way, as we can't expect all setups to run default test add-ons.

func ConformanceIt

func ConformanceIt(text string, body interface{}, timeout ...float64) bool

ConformanceIt is a wrapper function for ginkgo It. Adds "[Conformance]" tag and makes static analysis easier.

func CreatePV

CreatePV creates the PV resource. Fails test on error.

func CreateServiceSpec

func CreateServiceSpec(serviceName, externalName string, isHeadless bool, selector map[string]string) *v1.Service

CreateServiceSpec creates service spec

func CreateStatefulSetService

func CreateStatefulSetService(name string, labels map[string]string) *v1.Service

CreateStatefulSetService creates a Headless Service with Name name and Selector set to match labels.

func CreateTestingNS

func CreateTestingNS(baseName string, c clientset.Interface, labels map[string]string) (*v1.Namespace, error)

CreateTestingNS should be used by every test, note that we append a common prefix to the provided test name. Please see NewFramework instead of using this directly.

func DeleteAllStatefulSets

func DeleteAllStatefulSets(c clientset.Interface, kc kruiseclientset.Interface, ns string)

DeleteAllStatefulSets deletes all StatefulSet API Objects in Namespace ns.

func DumpAllNamespaceInfo

func DumpAllNamespaceInfo(c clientset.Interface, namespace string)

DumpAllNamespaceInfo is used to dump all namespace info

func DumpDebugInfo

func DumpDebugInfo(c clientset.Interface, ns string)

DumpDebugInfo dumps debug info

func DumpEventsInNamespace

func DumpEventsInNamespace(eventsLister EventsLister, namespace string)

DumpEventsInNamespace dump events in namespace

func ExpectNoError

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

ExpectNoError checks if "err" is set

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 "err" is set with retries

func Failf

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

Failf print fail log

func FailfWithOffset

func FailfWithOffset(offset int, format string, args ...interface{})

FailfWithOffset calls "Fail" and logs the error at "offset" levels above its caller (for example, for call chain f -> g -> FailfWithOffset(1, ...) error would be logged for "f").

func FilterNodes

func FilterNodes(nodeList *v1.NodeList, fn func(node v1.Node) bool)

FilterNodes filters nodes in NodeList in place, removing nodes that do not satisfy the given condition TODO: consider merging with pkg/client/cache.NodeLister

func GetReadySchedulableNodesOrDie

func GetReadySchedulableNodesOrDie(c clientset.Interface) (nodes *v1.NodeList)

GetReadySchedulableNodesOrDie addresses the common use case of getting nodes you can do work on. 1) Needs to be schedulable. 2) Needs to be ready. If EITHER 1 or 2 is not true, most tests will want to ignore the node entirely.

func HandleFlags

func HandleFlags()

HandleFlags sets up all flags and parses the command line.

func IsNodeConditionSetAsExpected

func IsNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionType, wantTrue bool) bool

IsNodeConditionSetAsExpected indicate if node is ready

func IsNodeConditionSetAsExpectedSilent

func IsNodeConditionSetAsExpectedSilent(node *v1.Node, conditionType v1.NodeConditionType, wantTrue bool) bool

IsNodeConditionSetAsExpectedSilent indicate if node is ready with silent

func IsNodeConditionUnset

func IsNodeConditionUnset(node *v1.Node, conditionType v1.NodeConditionType) bool

IsNodeConditionUnset indicate if set condition

func KruiseDescribe

func KruiseDescribe(text string, body func()) bool

KruiseDescribe is a wrapper function for ginkgo describe. Adds namespacing.

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 loads config of client set

func LoadConfig

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

LoadConfig loads config

func Logf

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

Logf print info log

func NewStatefulSet

func NewStatefulSet(name, ns, governingSvcName string, replicas int32, statefulPodMounts []v1.VolumeMount, podMounts []v1.VolumeMount, labels map[string]string) *appsv1alpha1.StatefulSet

NewStatefulSet creates a new NGINX StatefulSet for testing. The StatefulSet is named name, is in namespace ns, statefulPodsMounts are the mounts that will be backed by PVs. podsMounts are the mounts that are mounted directly to the Pod. labels are the labels that will be usd for the StatefulSet selector.

func NewStatefulSetPVC

func NewStatefulSetPVC(name string) v1.PersistentVolumeClaim

NewStatefulSetPVC returns a PersistentVolumeClaim named name, for testing StatefulSets.

func NewStatefulSetScale

func NewStatefulSetScale(ss *appsv1alpha1.StatefulSet) *appsV1beta2.Scale

NewStatefulSetScale creates a new StatefulSet scale subresource and returns it

func RegisterClusterFlags

func RegisterClusterFlags()

RegisterClusterFlags registers flags specific to the cluster e2e test suite.

func RegisterCommonFlags

func RegisterCommonFlags()

RegisterCommonFlags registers flags common to all e2e test suites.

func RegisterNodeFlags

func RegisterNodeFlags()

RegisterNodeFlags registers flags specific to the node e2e test suite.

func RegisterProvider

func RegisterProvider(name string, factory Factory)

RegisterProvider is expected to be called during application init, typically by an init function in a provider package.

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 loads config

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 RunHostCmd

func RunHostCmd(ns, name, cmd string) (string, error)

RunHostCmd runs the given cmd in the context of the given pod using `kubectl exec` inside of a shell.

func RunHostCmdWithRetries

func RunHostCmdWithRetries(ns, name, cmd string, interval, timeout time.Duration) (string, error)

RunHostCmdWithRetries calls RunHostCmd and retries all errors until it succeeds or the specified timeout expires. This can be used with idempotent commands to deflake transient Node issues.

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 Skipf

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

Skipf log info with skip

func UpdateStatefulSetWithRetries

func UpdateStatefulSetWithRetries(kc kruiseclientset.Interface, namespace, name string, applyUpdate updateStatefulSetFunc) (statefulSet *appsv1alpha1.StatefulSet, err error)

UpdateStatefulSetWithRetries update StatefulSet with retries

func WaitForDefaultServiceAccountInNamespace

func WaitForDefaultServiceAccountInNamespace(c clientset.Interface, namespace string) error

WaitForDefaultServiceAccountInNamespace waits for the default service account to be provisioned the default service account is what is associated with pods when they do not specify a service account as a result, pods are not able to be provisioned in a namespace until the service account is provisioned

func WaitForPodCondition

func WaitForPodCondition(c clientset.Interface, ns, podName, desc string, timeout time.Duration, condition podCondition) error

WaitForPodCondition waits until pod satisfied condition

func WaitForPodNameRunningInNamespace

func WaitForPodNameRunningInNamespace(c clientset.Interface, podName, namespace string) error

WaitForPodNameRunningInNamespace waits default amount of time (PodStartTimeout) for the specified pod to become running. Returns an error if timeout occurs first, or pod goes in to failed state.

func WaitForPodRunningInNamespace

func WaitForPodRunningInNamespace(c clientset.Interface, pod *v1.Pod) error

WaitForPodRunningInNamespace waits default amount of time (PodStartTimeout) for the specified pod to become running. Returns an error if timeout occurs first, or pod goes in to failed state.

func WaitTimeoutForPodRunningInNamespace

func WaitTimeoutForPodRunningInNamespace(c clientset.Interface, podName, namespace string, timeout time.Duration) error

WaitTimeoutForPodRunningInNamespace waits default amount of time

Types

type CleanupActionHandle

type CleanupActionHandle *int

CleanupActionHandle defines a type for cleanup action handle

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 ClientConfigGetter

type ClientConfigGetter func() (*restclient.Config, error)

ClientConfigGetter gets client config

type CloudConfig

type CloudConfig struct {
	APIEndpoint       string
	ProjectID         string
	Zone              string // for multizone tests, arbitrarily chosen zone
	Region            string
	MultiZone         bool
	MultiMaster       bool
	Cluster           string
	MasterName        string
	NodeInstanceGroup string // comma-delimited list of groups' names
	NumNodes          int
	ClusterIPRange    string
	ClusterTag        string
	Network           string
	ConfigFile        string // for azure and openstack
	NodeTag           string
	MasterTag         string

	Provider ProviderInterface
}

CloudConfig defines some config

type CreateTestingNSFn

type CreateTestingNSFn func(baseName string, c clientset.Interface, labels map[string]string) (*v1.Namespace, error)

CreateTestingNSFn defines a function to create test

type EventsLister

type EventsLister func(opts metav1.ListOptions, ns string) (*v1.EventList, error)

EventsLister defines a event listener

type Factory

type Factory func() (ProviderInterface, error)

Factory represents the factory pattern

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

	KruiseClientSet kruiseclientset.Interface
	ClientSet       clientset.Interface

	DynamicClient dynamic.Interface

	ScalesGetter scaleclient.ScalesGetter

	SkipNamespaceCreation bool          // Whether to skip creating a namespace
	Namespace             *v1.Namespace // Every test has at least one namespace unless creation is skipped

	NamespaceDeletionTimeout time.Duration
	SkipPrivilegedPSPBinding bool // Whether to skip creating a binding to the privileged PSP in the test namespace

	// configuration for framework's client
	Options Options

	// Place where various additional data is stored during test run to be printed to ReportDir,
	// or stdout if ReportDir is not set once test ends.
	TestSummaries []TestDataSummary
	// contains filtered or unexported fields
}

Framework supports common operations used by e2e tests; it will keep a client & a namespace for you. Eventual goal is to merge this with integration test framework.

func NewDefaultFramework

func NewDefaultFramework(baseName string) *Framework

NewDefaultFramework makes a new framework and sets up a BeforeEach/AfterEach for you (you can write additional before/after each functions).

func NewFramework

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

NewFramework makes a new framework and sets up a BeforeEach/AfterEach

func (*Framework) AddNamespacesToDelete

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

AddNamespacesToDelete adds one or more namespaces to be deleted when the test completes.

func (*Framework) AfterEach

func (f *Framework) AfterEach()

AfterEach deletes the namespace, after reading its events.

func (*Framework) BeforeEach

func (f *Framework) BeforeEach()

BeforeEach gets a client and makes a namespace.

func (*Framework) CreateNamespace

func (f *Framework) CreateNamespace(baseName string, labels map[string]string) (*v1.Namespace, error)

CreateNamespace is used to create namespace

func (*Framework) PodClient

func (f *Framework) PodClient() *PodClient

PodClient is convenience method for getting a pod client interface in the framework's namespace, possibly applying test-suite specific transformations to the pod spec, e.g. for node e2e pod scheduling.

func (*Framework) WaitForPodRunning

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

WaitForPodRunning waits for the pod to run in the namespace.

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 return a KubectlBuilder

func (KubectlBuilder) Exec

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

Exec executes

func (KubectlBuilder) ExecOrDie

func (b KubectlBuilder) ExecOrDie() string

ExecOrDie indicates execute or die

func (*KubectlBuilder) WithEnv

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

WithEnv sets env

func (KubectlBuilder) WithStdinData

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

WithStdinData sets stdin data

func (KubectlBuilder) WithStdinReader

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

WithStdinReader sets stdin reader

func (*KubectlBuilder) WithTimeout

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

WithTimeout sets timeout

type NodeTestContextType

type NodeTestContextType struct {
	// NodeE2E indicates whether it is running node e2e.
	NodeE2E bool
	// Name of the node to run tests on.
	NodeName string
	// NodeConformance indicates whether the test is running in node conformance mode.
	NodeConformance bool
	// PrepullImages indicates whether node e2e framework should prepull images.
	PrepullImages bool
	// ImageDescription is the description of the image on which the test is running.
	ImageDescription string
	// SystemSpecName is the name of the system spec (e.g., gke) that's used in
	// the node e2e test. If empty, the default one (system.DefaultSpec) is
	// used. The system specs are in test/e2e_node/system/specs/.
	SystemSpecName string
	// ExtraEnvs is a map of environment names to values.
	ExtraEnvs map[string]string
}

NodeTestContextType is part of TestContextType, it is shared by all node e2e test.

type NullProvider

type NullProvider struct{}

NullProvider is the default implementation of the ProviderInterface which doesn't do anything.

func (NullProvider) CleanupServiceResources

func (n NullProvider) CleanupServiceResources(c clientset.Interface, loadBalancerName, region, zone string)

CleanupServiceResources no usages

func (NullProvider) CreatePD

func (n NullProvider) CreatePD(zone string) (string, error)

CreatePD no usages

func (NullProvider) CreatePVSource

func (n NullProvider) CreatePVSource(zone, diskName string) (*v1.PersistentVolumeSource, error)

CreatePVSource no usages

func (NullProvider) DeletePD

func (n NullProvider) DeletePD(pdName string) error

DeletePD no usages

func (NullProvider) DeletePVSource

func (n NullProvider) DeletePVSource(pvSource *v1.PersistentVolumeSource) error

DeletePVSource no usages

func (NullProvider) EnableAndDisableInternalLB

func (n NullProvider) EnableAndDisableInternalLB() (enable, disable func(svc *v1.Service))

EnableAndDisableInternalLB no usages

func (NullProvider) EnsureLoadBalancerResourcesDeleted

func (n NullProvider) EnsureLoadBalancerResourcesDeleted(ip, portRange string) error

EnsureLoadBalancerResourcesDeleted no usages

func (NullProvider) FrameworkAfterEach

func (n NullProvider) FrameworkAfterEach(f *Framework)

FrameworkAfterEach is framework after each

func (NullProvider) FrameworkBeforeEach

func (n NullProvider) FrameworkBeforeEach(f *Framework)

FrameworkBeforeEach is a framework before each

func (NullProvider) GetGroupNodes

func (n NullProvider) GetGroupNodes(group string) ([]string, error)

GetGroupNodes no usages

func (NullProvider) GroupSize

func (n NullProvider) GroupSize(group string) (int, error)

GroupSize no usages

func (NullProvider) LoadBalancerSrcRanges

func (n NullProvider) LoadBalancerSrcRanges() []string

LoadBalancerSrcRanges no usages

func (NullProvider) ResizeGroup

func (n NullProvider) ResizeGroup(string, int32) error

ResizeGroup no usages

type Options

type Options struct {
	ClientQPS    float32
	ClientBurst  int
	GroupVersion *schema.GroupVersion
}

Options contains some options

type PodClient

type PodClient struct {
	v1core.PodInterface
	// contains filtered or unexported fields
}

PodClient defines a convenience method for getting a pod client interface in the framework's namespace

func (*PodClient) Update

func (c *PodClient) Update(name string, updateFn func(pod *v1.Pod))

Update updates the pod object. It retries if there is a conflict, throw out error if there is any other errors. name is the pod name, updateFn is the function updating the pod object.

type ProviderInterface

type ProviderInterface interface {
	FrameworkBeforeEach(f *Framework)
	FrameworkAfterEach(f *Framework)

	ResizeGroup(group string, size int32) error
	GetGroupNodes(group string) ([]string, error)
	GroupSize(group string) (int, error)

	CreatePD(zone string) (string, error)
	DeletePD(pdName string) error
	CreatePVSource(zone, diskName string) (*v1.PersistentVolumeSource, error)
	DeletePVSource(pvSource *v1.PersistentVolumeSource) error

	CleanupServiceResources(c clientset.Interface, loadBalancerName, region, zone string)

	EnsureLoadBalancerResourcesDeleted(ip, portRange string) error
	LoadBalancerSrcRanges() []string
	EnableAndDisableInternalLB() (enable, disable func(svc *v1.Service))
}

ProviderInterface contains the implementation for certain provider-specific functionality.

func SetupProviderConfig

func SetupProviderConfig(providerName string) (ProviderInterface, error)

SetupProviderConfig validates the chosen provider and creates an interface instance for it.

type StatefulSetTester

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

StatefulSetTester is a struct that contains utility methods for testing StatefulSet related functionality. It uses a clientset.Interface to communicate with the API server.

func NewStatefulSetTester

func NewStatefulSetTester(c clientset.Interface, kc kruiseclientset.Interface) *StatefulSetTester

NewStatefulSetTester creates a StatefulSetTester that uses c to interact with the API server.

func (*StatefulSetTester) BreakHTTPProbe

func (s *StatefulSetTester) BreakHTTPProbe(ss *appsv1alpha1.StatefulSet) error

BreakHTTPProbe breaks the readiness probe for Nginx StatefulSet containers in ss.

func (*StatefulSetTester) BreakPodHTTPProbe

func (s *StatefulSetTester) BreakPodHTTPProbe(ss *appsv1alpha1.StatefulSet, pod *v1.Pod) error

BreakPodHTTPProbe breaks the readiness probe for Nginx StatefulSet containers in one pod.

func (*StatefulSetTester) CheckHostname

func (s *StatefulSetTester) CheckHostname(ss *appsv1alpha1.StatefulSet) error

CheckHostname verifies that all Pods in ss have the correct Hostname. If the returned error is not nil than verification failed.

func (*StatefulSetTester) CheckMount

func (s *StatefulSetTester) CheckMount(ss *appsv1alpha1.StatefulSet, mountPath string) error

CheckMount checks that the mount at mountPath is valid for all Pods in ss.

func (*StatefulSetTester) CheckServiceName

func (s *StatefulSetTester) CheckServiceName(ss *appsv1alpha1.StatefulSet, expectedServiceName string) error

CheckServiceName asserts that the ServiceName for ss is equivalent to expectedServiceName.

func (*StatefulSetTester) ConfirmStatefulPodCount

func (s *StatefulSetTester) ConfirmStatefulPodCount(count int, ss *appsv1alpha1.StatefulSet, timeout time.Duration, hard bool)

ConfirmStatefulPodCount asserts that the current number of Pods in ss is count waiting up to timeout for ss to to scale to count.

func (*StatefulSetTester) CreateStatefulSet

func (s *StatefulSetTester) CreateStatefulSet(manifestPath, ns string) *appsv1alpha1.StatefulSet

CreateStatefulSet creates a StatefulSet from the manifest at manifestPath in the Namespace ns using kubectl create.

func (*StatefulSetTester) DeleteStatefulPodAtIndex

func (s *StatefulSetTester) DeleteStatefulPodAtIndex(index int, ss *appsv1alpha1.StatefulSet)

DeleteStatefulPodAtIndex deletes the Pod with ordinal index in ss.

func (*StatefulSetTester) ExecInStatefulPods

func (s *StatefulSetTester) ExecInStatefulPods(ss *appsv1alpha1.StatefulSet, cmd string) error

ExecInStatefulPods executes cmd in all Pods in ss. If a error occurs it is returned and cmd is not execute in any subsequent Pods.

func (*StatefulSetTester) GetPodList

func (s *StatefulSetTester) GetPodList(ss *appsv1alpha1.StatefulSet) *v1.PodList

GetPodList gets the current Pods in ss.

func (*StatefulSetTester) GetStatefulSet

func (s *StatefulSetTester) GetStatefulSet(namespace, name string) *appsv1alpha1.StatefulSet

GetStatefulSet gets the StatefulSet named name in namespace.

func (*StatefulSetTester) PauseNewPods

func (s *StatefulSetTester) PauseNewPods(ss *appsv1alpha1.StatefulSet)

PauseNewPods adds an always-failing ReadinessProbe to the StatefulSet PodTemplate. This causes all newly-created Pods to stay Unready until they are manually resumed with ResumeNextPod(). Note that this cannot be used together with SetHTTPProbe().

func (*StatefulSetTester) Restart

func (s *StatefulSetTester) Restart(ss *appsv1alpha1.StatefulSet)

Restart scales ss to 0 and then back to its previous number of replicas.

func (*StatefulSetTester) RestoreHTTPProbe

func (s *StatefulSetTester) RestoreHTTPProbe(ss *appsv1alpha1.StatefulSet) error

RestoreHTTPProbe restores the readiness probe for Nginx StatefulSet containers in ss.

func (*StatefulSetTester) RestorePodHTTPProbe

func (s *StatefulSetTester) RestorePodHTTPProbe(ss *appsv1alpha1.StatefulSet, pod *v1.Pod) error

RestorePodHTTPProbe restores the readiness probe for Nginx StatefulSet containers in pod.

func (*StatefulSetTester) ResumeNextPod

func (s *StatefulSetTester) ResumeNextPod(ss *appsv1alpha1.StatefulSet)

ResumeNextPod allows the next Pod in the StatefulSet to continue by removing the ReadinessProbe added by PauseNewPods(), if it's still there. It fails the test if it finds any pods that are not in phase Running, or if it finds more than one paused Pod existing at the same time. This is a no-op if there are no paused pods.

func (*StatefulSetTester) Saturate

func (s *StatefulSetTester) Saturate(ss *appsv1alpha1.StatefulSet)

Saturate waits for all Pods in ss to become Running and Ready.

func (*StatefulSetTester) Scale

Scale scales ss to count replicas.

func (*StatefulSetTester) SetHTTPProbe

func (s *StatefulSetTester) SetHTTPProbe(ss *appsv1alpha1.StatefulSet)

SetHTTPProbe sets the pod template's ReadinessProbe for Nginx StatefulSet containers. This probe can then be controlled with BreakHTTPProbe() and RestoreHTTPProbe(). Note that this cannot be used together with PauseNewPods().

func (*StatefulSetTester) SortStatefulPods

func (s *StatefulSetTester) SortStatefulPods(pods *v1.PodList)

SortStatefulPods sorts pods by their ordinals

func (*StatefulSetTester) UpdateReplicas

func (s *StatefulSetTester) UpdateReplicas(ss *appsv1alpha1.StatefulSet, count int32)

UpdateReplicas updates the replicas of ss to count.

func (*StatefulSetTester) VerifyPodAtIndex

func (s *StatefulSetTester) VerifyPodAtIndex(index int, ss *appsv1alpha1.StatefulSet, verify VerifyStatefulPodFunc)

VerifyPodAtIndex applies a visitor patter to the Pod at index in ss. verify is applied to the Pod to "visit" it.

func (*StatefulSetTester) WaitForPartitionedRollingUpdate

func (s *StatefulSetTester) WaitForPartitionedRollingUpdate(set *appsv1alpha1.StatefulSet) (*appsv1alpha1.StatefulSet, *v1.PodList)

WaitForPartitionedRollingUpdate waits for all Pods in set to exist and have the correct revision. set must have a RollingUpdateStatefulSetStrategyType with a non-nil RollingUpdate and Partition. All Pods with ordinals less than or equal to the Partition are expected to be at set's current revision. All other Pods are expected to be at its update revision.

func (*StatefulSetTester) WaitForPodNotReady

func (s *StatefulSetTester) WaitForPodNotReady(set *appsv1alpha1.StatefulSet, podName string) (*appsv1alpha1.StatefulSet, *v1.PodList)

WaitForPodNotReady waist for the Pod named podName in set to exist and to not have a Ready condition.

func (*StatefulSetTester) WaitForPodReady

func (s *StatefulSetTester) WaitForPodReady(set *appsv1alpha1.StatefulSet, podName string) (*appsv1alpha1.StatefulSet, *v1.PodList)

WaitForPodReady waits for the Pod named podName in set to exist and have a Ready condition.

func (*StatefulSetTester) WaitForRollingUpdate

func (s *StatefulSetTester) WaitForRollingUpdate(set *appsv1alpha1.StatefulSet) (*appsv1alpha1.StatefulSet, *v1.PodList)

WaitForRollingUpdate waits for all Pods in set to exist and have the correct revision and for the RollingUpdate to complete. set must have a RollingUpdateStatefulSetStrategyType.

func (*StatefulSetTester) WaitForRunning

func (s *StatefulSetTester) WaitForRunning(numPodsRunning, numPodsReady int32, ss *appsv1alpha1.StatefulSet)

WaitForRunning waits for numPodsRunning in ss to be Running and for the first numPodsReady ordinals to be Ready.

func (*StatefulSetTester) WaitForRunningAndNotReady

func (s *StatefulSetTester) WaitForRunningAndNotReady(numStatefulPods int32, ss *appsv1alpha1.StatefulSet)

WaitForRunningAndNotReady waits for numStatefulPods in ss to be Running and not Ready.

func (*StatefulSetTester) WaitForRunningAndReady

func (s *StatefulSetTester) WaitForRunningAndReady(numStatefulPods int32, ss *appsv1alpha1.StatefulSet)

WaitForRunningAndReady waits for numStatefulPods in ss to be Running and Ready.

func (*StatefulSetTester) WaitForState

func (s *StatefulSetTester) WaitForState(ss *appsv1alpha1.StatefulSet, until func(*appsv1alpha1.StatefulSet, *v1.PodList) (bool, error))

WaitForState periodically polls for the ss and its pods until the until function returns either true or an error

func (*StatefulSetTester) WaitForStatus

WaitForStatus waits for the StatefulSetStatus's ObservedGeneration to be greater than or equal to set's Generation. The returned StatefulSet contains such a StatefulSetStatus

func (*StatefulSetTester) WaitForStatusReadyReplicas

func (s *StatefulSetTester) WaitForStatusReadyReplicas(ss *appsv1alpha1.StatefulSet, expectedReplicas int32)

WaitForStatusReadyReplicas waits for the ss.Status.ReadyReplicas to be equal to expectedReplicas

func (*StatefulSetTester) WaitForStatusReplicas

func (s *StatefulSetTester) WaitForStatusReplicas(ss *appsv1alpha1.StatefulSet, expectedReplicas int32)

WaitForStatusReplicas waits for the ss.Status.Replicas to be equal to expectedReplicas

type TestContextType

type TestContextType struct {
	KubeConfig         string
	KubeContext        string
	KubeAPIContentType string
	KubeVolumeDir      string
	CertDir            string
	Host               string
	// TODO: Deprecating this over time... instead just use gobindata_util.go , see #23987.
	RepoRoot                string
	DockershimCheckpointDir string

	// Provider identifies the infrastructure provider (gce, gke, aws)
	Provider string

	// Tooling is the tooling in use (e.g. kops, gke).  Provider is the cloud provider and might not uniquely identify the tooling.
	Tooling string

	CloudConfig    CloudConfig
	KubectlPath    string
	OutputDir      string
	ReportDir      string
	ReportPrefix   string
	Prefix         string
	MinStartupPods int
	// Timeout for waiting for system pods to be running
	SystemPodsStartupTimeout    time.Duration
	EtcdUpgradeStorage          string
	EtcdUpgradeVersion          string
	IngressUpgradeImage         string
	GCEUpgradeScript            string
	ContainerRuntime            string
	ContainerRuntimeEndpoint    string
	ContainerRuntimeProcessName string
	ContainerRuntimePidFile     string
	// SystemdServices are comma separated list of systemd services the test framework
	// will dump logs for.
	SystemdServices          string
	ImageServiceEndpoint     string
	MasterOSDistro           string
	NodeOSDistro             string
	VerifyServiceAccount     bool
	DeleteNamespace          bool
	DeleteNamespaceOnFailure bool
	AllowedNotReadyNodes     int
	CleanStart               bool
	// If set to 'true' or 'all' framework will start a goroutine monitoring resource usage of system add-ons.
	// It will read the data every 30 seconds from all Nodes and print summary during afterEach. If set to 'master'
	// only master Node will be monitored.
	GatherKubeSystemResourceUsageData string
	GatherLogsSizes                   bool
	GatherMetricsAfterTest            string
	GatherSuiteMetricsAfterTest       bool
	AllowGatheringProfiles            bool
	// If set to 'true' framework will gather ClusterAutoscaler metrics when gathering them for other components.
	IncludeClusterAutoscalerMetrics bool
	// Currently supported values are 'hr' for human-readable and 'json'. It's a comma separated list.
	OutputPrintType string
	// NodeSchedulableTimeout is the timeout for waiting for all nodes to be schedulable.
	NodeSchedulableTimeout time.Duration
	// SystemDaemonsetStartupTimeout is the timeout for waiting for all system daemonsets to be ready.
	SystemDaemonsetStartupTimeout time.Duration
	// CreateTestingNS is responsible for creating namespace used for executing e2e tests.
	// It accepts namespace base name, which will be prepended with e2e prefix, kube client
	// and labels to be applied to a namespace.
	CreateTestingNS CreateTestingNSFn
	// If set to true test will dump data about the namespace in which test was running.
	DumpLogsOnFailure bool
	// Disables dumping cluster log from master and nodes after all tests.
	DisableLogDump bool
	// Path to the GCS artifacts directory to dump logs from nodes. Logexporter gets enabled if this is non-empty.
	LogexporterGCSPath string
	// featureGates is a map of feature names to bools that enable or disable alpha/experimental features.
	FeatureGates map[string]bool
	// Node e2e specific test context
	NodeTestContextType
	// Monitoring solution that is used in current cluster.
	ClusterMonitoringMode string
	// Separate Prometheus monitoring deployed in cluster
	EnablePrometheusMonitoring bool

	// Indicates what path the kubernetes-anywhere is installed on
	KubernetesAnywherePath string

	// The DNS Domain of the cluster.
	ClusterDNSDomain string
}

TestContextType contains test settings and global state. Due to historic reasons, it is a mixture of items managed by the test framework itself, cloud providers and individual tests. The goal is to move anything not required by the framework into the code which uses the settings.

The recommendation for those settings is:

  • They are stored in their own context structure or local variables.
  • The standard `flag` package is used to register them. The flag name should follow the pattern <part1>.<part2>....<partn> where the prefix is unlikely to conflict with other tests or standard packages and each part is in lower camel case. For example, test/e2e/storage/csi/context.go could define storage.csi.numIterations.
  • framework/config can be used to simplify the registration of multiple options with a single function call: var storageCSI { NumIterations `default:"1" usage:"number of iterations"` } _ config.AddOptions(&storageCSI, "storage.csi")
  • The direct use Viper in tests is possible, but discouraged because it only works in test suites which use Viper (which is not required) and the supported options cannot be discovered by a test suite user.

Test suite authors can use framework/viper to make all command line parameters also configurable via a configuration file.

var TestContext TestContextType

TestContext defines a context include test settings and global state

type TestDataSummary

type TestDataSummary interface {
	SummaryKind() string
	PrintHumanReadable() string
	PrintJSON() string
}

TestDataSummary defines a interface to test data summary

type VerifyStatefulPodFunc

type VerifyStatefulPodFunc func(*v1.Pod)

VerifyStatefulPodFunc is a func that examines a StatefulSetPod.

Jump to

Keyboard shortcuts

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