util

package
v1.28.8 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 53 Imported by: 47

Documentation

Index

Constants

View Source
const (
	// TestProjectID is the project id used for creating NewMockGCECloud
	TestProjectID = "test-project"
	// TestNetworkProjectID is the network project id for creating NewMockGCECloud
	TestNetworkProjectID = "net-test-project"
	// TestRegion is the region for creating NewMockGCECloud
	TestRegion = "test-region"
	// TestZone is the zone for creating NewMockGCECloud
	TestZone = "test-zone"
	// TestNetworkName is the network name for creating NewMockGCECloud
	TestNetworkName = "test-network"
	// TestSubnetworkName is the sub network name for creating NewMockGCECloud
	TestSubnetworkName = "test-sub-network"
	// TestSecondaryRangeName is the secondary range name for creating NewMockGCECloud
	TestSecondaryRangeName = "test-secondary-range"
)

Variables

This section is empty.

Functions

func AddTaintToNode added in v1.18.0

func AddTaintToNode(cs clientset.Interface, nodeName string, taint v1.Taint) error

AddTaintToNode add taints to specific node

func CleanupNodes added in v1.18.0

func CleanupNodes(cs clientset.Interface, t *testing.T)

CleanupNodes cleans all nodes which were created during integration test

func CleanupPods added in v1.18.0

func CleanupPods(ctx context.Context, cs clientset.Interface, t *testing.T, pods []*v1.Pod)

CleanupPods deletes the given pods and waits for them to be actually deleted.

func CleanupTest added in v1.18.0

func CleanupTest(t *testing.T, testCtx *TestContext)

CleanupTest cleans related resources which were created during integration test

func CreateAndWaitForNodesInCache added in v1.24.10

func CreateAndWaitForNodesInCache(testCtx *TestContext, prefix string, wrapper *st.NodeWrapper, numNodes int) ([]*v1.Node, error)

CreateAndWaitForNodesInCache calls createNodes(), and wait for the created nodes to be present in scheduler cache.

func CreateGCController added in v1.28.0

func CreateGCController(ctx context.Context, tb testing.TB, restConfig restclient.Config, informerSet informers.SharedInformerFactory) func()

CreateGCController creates a garbage controller and returns a run function for it. The informer factory needs to be started before invoking that function.

func CreateNamespaceController added in v1.28.0

func CreateNamespaceController(ctx context.Context, tb testing.TB, restConfig restclient.Config, informerSet informers.SharedInformerFactory) func()

CreateNamespaceController creates a namespace controller and returns a run function for it. The informer factory needs to be started before invoking that function.

func CreateNamespacesWithLabels added in v1.24.10

func CreateNamespacesWithLabels(cs clientset.Interface, namespaces []string, labels map[string]string) error

func CreateNode added in v1.24.10

func CreateNode(cs clientset.Interface, node *v1.Node) (*v1.Node, error)

func CreatePV added in v1.26.0

CreatePV creates a PersistentVolume with the given config and returns its pointer and error status.

func CreatePVC added in v1.26.0

CreatePVC creates a PersistentVolumeClaim with the given config and returns its pointer and error status.

func CreatePausePod added in v1.24.10

func CreatePausePod(cs clientset.Interface, p *v1.Pod) (*v1.Pod, error)

CreatePausePod creates a pod with "Pause" image and the given config and return its pointer and error status.

func CreatePausePodWithResource added in v1.24.10

func CreatePausePodWithResource(cs clientset.Interface, podName string,
	nsName string, res *v1.ResourceList) (*v1.Pod, error)

CreatePausePodWithResource creates a pod with "Pause" image and the given resources and returns its pointer and error status. The resource list can be nil.

func CreateResourceClaimController added in v1.28.0

func CreateResourceClaimController(ctx context.Context, tb testing.TB, clientSet clientset.Interface, informerFactory informers.SharedInformerFactory) func()

func DeletePV added in v1.27.0

func DeletePV(cs clientset.Interface, pvName string) error

DeletePV deletes the given PV in the given namespace.

func DeletePVC added in v1.27.0

func DeletePVC(cs clientset.Interface, pvcName string, nsName string) error

DeletePVC deletes the given PVC in the given namespace.

func DeletePod added in v1.24.10

func DeletePod(cs clientset.Interface, podName string, nsName string) error

DeletePod deletes the given pod in the given namespace.

func GetPod added in v1.24.10

func GetPod(cs clientset.Interface, podName string, podNamespace string) (*v1.Pod, error)

func GetTolerationSeconds added in v1.18.0

func GetTolerationSeconds(tolerations []v1.Toleration) (int64, error)

GetTolerationSeconds gets the period of time the toleration

func InitDisruptionController added in v1.24.10

func InitDisruptionController(t *testing.T, testCtx *TestContext) *disruption.DisruptionController

InitDisruptionController initializes and runs a Disruption Controller to properly update PodDisuptionBudget objects.

func InitPausePod added in v1.24.10

func InitPausePod(conf *PausePodConfig) *v1.Pod

InitPausePod initializes a pod API object from the given config. It is used mainly in pod creation process.

func InitPodWithContainers added in v1.24.10

func InitPodWithContainers(cs clientset.Interface, conf *PodWithContainersConfig) *v1.Pod

InitPodWithContainers initializes a pod API object from the given config. This is used primarily for generating pods with containers each having a specific image.

func NewMockGCECloud added in v1.11.0

func NewMockGCECloud(cloud cloud.Cloud) (*gce.Cloud, error)

NewMockGCECloud returns a handle to a Cloud instance that is served by a mock http server

func NextPod added in v1.24.10

func NextPod(t *testing.T, testCtx *TestContext) *schedulerframework.QueuedPodInfo

NextPod returns the next Pod in the scheduler queue, with a 5 seconds timeout.

func NextPodOrDie added in v1.24.10

func NextPodOrDie(t *testing.T, testCtx *TestContext) *schedulerframework.QueuedPodInfo

NextPodOrDie returns the next Pod in the scheduler queue. The operation needs to be completed within 5 seconds; otherwise the test gets aborted.

func NodeCopyWithConditions added in v1.18.0

func NodeCopyWithConditions(node *v1.Node, conditions []v1.NodeCondition) *v1.Node

NodeCopyWithConditions duplicates the ode object with conditions

func NodeReadyStatus added in v1.18.0

func NodeReadyStatus(conditions []v1.NodeCondition) (v1.ConditionStatus, error)

NodeReadyStatus returns the status of first condition with type NodeReady. If none of the condition is of type NodeReady, returns an error.

func NodeTainted added in v1.18.0

func NodeTainted(cs clientset.Interface, nodeName string, taints []v1.Taint) wait.ConditionFunc

NodeTainted return a condition function that returns true if the given node contains the taints.

func PodDeleted added in v1.18.0

func PodDeleted(ctx context.Context, c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc

PodDeleted returns true if a pod is not found in the given namespace.

func PodIsGettingEvicted added in v1.24.10

func PodIsGettingEvicted(c clientset.Interface, podNamespace, podName string) wait.ConditionFunc

PodIsGettingEvicted returns true if the pod's deletion timestamp is set.

func PodScheduled added in v1.18.0

func PodScheduled(c clientset.Interface, podNamespace, podName string) wait.ConditionFunc

PodScheduled checks if the pod has been scheduled

func PodScheduledIn added in v1.24.10

func PodScheduledIn(c clientset.Interface, podNamespace, podName string, nodeNames []string) wait.ConditionFunc

PodScheduledIn returns true if a given pod is placed onto one of the expected nodes.

func PodSchedulingError added in v1.24.10

func PodSchedulingError(c clientset.Interface, podNamespace, podName string) wait.ConditionFunc

PodSchedulingError returns a condition function that returns true if the given pod gets unschedulable status for reasons other than "Unschedulable". The scheduler records such reasons in case of error.

func PodSchedulingGated added in v1.26.0

func PodSchedulingGated(c clientset.Interface, podNamespace, podName string) wait.ConditionFunc

PodSchedulingGated returns a condition function that returns true if the given pod gets unschedulable status of reason 'SchedulingGated'.

func PodUnschedulable added in v1.24.10

func PodUnschedulable(c clientset.Interface, podNamespace, podName string) wait.ConditionFunc

PodUnschedulable returns a condition function that returns true if the given pod gets unschedulable status of reason 'Unschedulable'.

func PodsCleanedUp added in v1.28.0

func PodsCleanedUp(ctx context.Context, c clientset.Interface, namespace string) wait.ConditionWithContextFunc

PodsCleanedUp returns true if all pods are deleted in the specific namespace.

func RemovePodFinalizers added in v1.25.0

func RemovePodFinalizers(ctx context.Context, cs clientset.Interface, t *testing.T, pods ...v1.Pod)

RemovePodFinalizers removes pod finalizers for the pods

func RemovePodFinalizersInNamespace added in v1.26.7

func RemovePodFinalizersInNamespace(ctx context.Context, cs clientset.Interface, t *testing.T, ns string)

func RemoveTaintOffNode added in v1.19.0

func RemoveTaintOffNode(cs clientset.Interface, nodeName string, taint v1.Taint) error

RemoveTaintOffNode removes a specific taint from a node

func RunPausePod added in v1.24.10

func RunPausePod(cs clientset.Interface, pod *v1.Pod) (*v1.Pod, error)

RunPausePod creates a pod with "Pause" image and the given config and waits until it is scheduled. It returns its pointer and error status.

func RunPodWithContainers added in v1.24.10

func RunPodWithContainers(cs clientset.Interface, pod *v1.Pod) (*v1.Pod, error)

RunPodWithContainers creates a pod with given config and containers and waits until it is scheduled. It returns its pointer and error status.

func StartFakePVController added in v1.18.0

func StartFakePVController(ctx context.Context, clientSet clientset.Interface, informerFactory informers.SharedInformerFactory)

StartFakePVController is a simplified pv controller logic that sets PVC VolumeName and annotation for each PV binding. TODO(mborsz): Use a real PV controller here.

func StartScheduler

StartScheduler configures and starts a scheduler given a handle to the clientSet interface and event broadcaster. It returns the running scheduler and podInformer. Background goroutines will keep running until the context is canceled.

func SyncSchedulerInformerFactory added in v1.28.0

func SyncSchedulerInformerFactory(testCtx *TestContext)

SyncSchedulerInformerFactory starts informer and waits for caches to be synced

func UpdateNode added in v1.24.10

func UpdateNode(cs clientset.Interface, node *v1.Node) (*v1.Node, error)

func UpdateNodeStatus added in v1.18.0

func UpdateNodeStatus(cs clientset.Interface, node *v1.Node) error

UpdateNodeStatus updates the status of node.

func WaitCachedPodsStable added in v1.24.10

func WaitCachedPodsStable(testCtx *TestContext, pods []*v1.Pod) error

WaitCachedPodsStable waits until scheduler cache has the given pods.

func WaitForNodeTaints added in v1.18.0

func WaitForNodeTaints(cs clientset.Interface, node *v1.Node, taints []v1.Taint) error

WaitForNodeTaints waits for a node to have the target taints and returns an error if it does not have taints within the given timeout.

func WaitForNodesInCache added in v1.24.10

func WaitForNodesInCache(sched *scheduler.Scheduler, nodeCount int) error

WaitForNodesInCache ensures at least <nodeCount> nodes are present in scheduler cache within 30 seconds; otherwise returns false.

func WaitForPDBsStable added in v1.24.10

func WaitForPDBsStable(testCtx *TestContext, pdbs []*policy.PodDisruptionBudget, pdbPodNum []int32) error

WaitForPDBsStable waits for PDBs to have "CurrentHealthy" status equal to the expected values.

func WaitForPodSchedulingGated added in v1.26.0

func WaitForPodSchedulingGated(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error

WaitForPodSchedulingGated waits for a pod to be in scheduling gated state and returns an error if it does not fall into this state within the given timeout.

func WaitForPodToSchedule added in v1.18.0

func WaitForPodToSchedule(cs clientset.Interface, pod *v1.Pod) error

WaitForPodToSchedule waits for a pod to get scheduled and returns an error if it does not get scheduled within the timeout duration (30 seconds).

func WaitForPodToScheduleWithTimeout added in v1.18.0

func WaitForPodToScheduleWithTimeout(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error

WaitForPodToScheduleWithTimeout waits for a pod to get scheduled and returns an error if it does not scheduled within the given timeout.

func WaitForPodUnschedulable added in v1.24.10

func WaitForPodUnschedulable(cs clientset.Interface, pod *v1.Pod) error

WaitForPodUnschedulable waits for a pod to fail scheduling and returns an error if it does not become unschedulable within the timeout duration (30 seconds).

func WaitForPodUnschedulableWithTimeout added in v1.24.10

func WaitForPodUnschedulableWithTimeout(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error

WaitForPodUnschedulableWithTimeout waits for a pod to fail scheduling and returns an error if it does not become unschedulable within the given timeout.

func WaitForReflection added in v1.24.10

func WaitForReflection(t *testing.T, nodeLister corelisters.NodeLister, key string,
	passFunc func(n interface{}) bool) error

WaitForReflection waits till the passFunc confirms that the object it expects to see is in the store. Used to observe reflected events.

func WaitForSchedulerCacheCleanup added in v1.18.0

func WaitForSchedulerCacheCleanup(sched *scheduler.Scheduler, t *testing.T)

WaitForSchedulerCacheCleanup waits for cleanup of scheduler's cache to complete

Types

type PausePodConfig added in v1.24.10

type PausePodConfig struct {
	Name                              string
	Namespace                         string
	Affinity                          *v1.Affinity
	Annotations, Labels, NodeSelector map[string]string
	Resources                         *v1.ResourceRequirements
	Tolerations                       []v1.Toleration
	NodeName                          string
	SchedulerName                     string
	Priority                          *int32
	PreemptionPolicy                  *v1.PreemptionPolicy
	PriorityClassName                 string
	Volumes                           []v1.Volume
}

type PodWithContainersConfig added in v1.24.10

type PodWithContainersConfig struct {
	Name       string
	Namespace  string
	Containers []v1.Container
}

type ShutdownFunc

type ShutdownFunc func()

ShutdownFunc represents the function handle to be called, typically in a defer handler, to shutdown a running module

type TestContext added in v1.18.0

type TestContext struct {
	NS                 *v1.Namespace
	ClientSet          clientset.Interface
	KubeConfig         *restclient.Config
	InformerFactory    informers.SharedInformerFactory
	DynInformerFactory dynamicinformer.DynamicSharedInformerFactory
	Scheduler          *scheduler.Scheduler
	// This is the top context when initializing the test environment.
	Ctx context.Context
	// CloseFn will stop the apiserver and clean up the resources
	// after itself, including shutting down its storage layer.
	CloseFn framework.TearDownFunc
	// This is the context when initializing scheduler.
	SchedulerCtx context.Context
	// SchedulerCloseFn will tear down the resources in creating scheduler,
	// including the scheduler itself.
	SchedulerCloseFn framework.TearDownFunc
}

TestContext store necessary context info

func InitTestAPIServer added in v1.22.0

func InitTestAPIServer(t *testing.T, nsPrefix string, admission admission.Interface) *TestContext

InitTestAPIServer initializes a test environment and creates an API server with default configuration. It registers cleanup functions to t.Cleanup(), they will be called when the test completes, no need to do this again.

func InitTestDisablePreemption added in v1.24.10

func InitTestDisablePreemption(t *testing.T, nsPrefix string) *TestContext

InitTestDisablePreemption initializes a test environment and creates API server and scheduler with default configuration but with pod preemption disabled.

func InitTestScheduler added in v1.18.0

func InitTestScheduler(
	t *testing.T,
	testCtx *TestContext,
) *TestContext

InitTestScheduler initializes a test environment and creates a scheduler with default configuration.

func InitTestSchedulerWithNS added in v1.24.10

func InitTestSchedulerWithNS(t *testing.T, nsPrefix string, opts ...scheduler.Option) *TestContext

InitTestSchedulerWithNS initializes a test environment and creates API server and scheduler with default configuration.

func InitTestSchedulerWithOptions added in v1.18.0

func InitTestSchedulerWithOptions(
	t *testing.T,
	testCtx *TestContext,
	resyncPeriod time.Duration,
	opts ...scheduler.Option,
) *TestContext

InitTestSchedulerWithOptions initializes a test environment and creates a scheduler with default configuration and other options.

Jump to

Keyboard shortcuts

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