kubernetesk8s.io/kubernetes/test/integration/util Index | Files

package util

import "k8s.io/kubernetes/test/integration/util"

Index

Constants

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"
)

Functions

func AddTaintToNode

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

AddTaintToNode add taints to specific node

func CleanupNodes

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

CleanupNodes cleans all nodes which were created during integration test

func CleanupPods

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

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

func CleanupTest

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

CleanupTest cleans related resources which were created during integration test

func CreateAndWaitForNodesInCache

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 CreateNamespacesWithLabels

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

func CreateNode

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

func CreatePV

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

func CreatePVC

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

func CreatePausePod

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

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 DeletePod

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

DeletePod deletes the given pod in the given namespace.

func GetPod

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

func GetTolerationSeconds

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

GetTolerationSeconds gets the period of time the toleration

func InitDisruptionController

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

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

func InitPausePod

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

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

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

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

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

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

NodeCopyWithConditions duplicates the ode object with conditions

func NodeReadyStatus

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

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

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

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

func PodIsGettingEvicted

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

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

func PodScheduled

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

PodScheduled checks if the pod has been scheduled

func PodScheduledIn

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

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

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

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 RemovePodFinalizers

func RemovePodFinalizers(cs clientset.Interface, t *testing.T, pods []*v1.Pod)

RemovePodFinalizers removes pod finalizers for the pods

func RemoveTaintOffNode

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

RemoveTaintOffNode removes a specific taint from a node

func RunPausePod

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

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 SyncInformerFactory

func SyncInformerFactory(testCtx *TestContext)

SyncInformerFactory starts informer and waits for caches to be synced

func UpdateNode

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

func UpdateNodeStatus

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

UpdateNodeStatus updates the status of node.

func WaitCachedPodsStable

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

WaitCachedPodsStable waits until scheduler cache has the given pods.

func WaitForNodeTaints

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

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

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

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

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

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

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

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

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

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

WaitForSchedulerCacheCleanup waits for cleanup of scheduler's cache to complete

Types

type PausePodConfig

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

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

func StartFakePVController

func StartFakePVController(clientSet clientset.Interface) ShutdownFunc

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, podInformer and the shutdown function to stop it.

type TestContext

type TestContext struct {
	CloseFn            framework.TearDownFunc
	NS                 *v1.Namespace
	ClientSet          clientset.Interface
	KubeConfig         *restclient.Config
	InformerFactory    informers.SharedInformerFactory
	DynInformerFactory dynamicinformer.DynamicSharedInformerFactory
	Scheduler          *scheduler.Scheduler
	Ctx                context.Context
	CancelFn           context.CancelFunc
}

TestContext store necessary context info

func InitTestAPIServer

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

InitTestAPIServer initializes a test environment and creates an API server with default configuration.

func InitTestDisablePreemption

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

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

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

func InitTestSchedulerWithNS

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

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.

Source Files

cloud.go util.go

Version
v1.26.0
Published
Dec 8, 2022
Platform
js/wasm
Imports
45 packages
Last checked
1 minute ago

Tools for package owners.