package util
import "k8s.io/kubernetes/test/integration/util"
Index ¶
- func AddTaintToNode(cs clientset.Interface, nodeName string, taint v1.Taint) error
- func CleanupNodes(cs clientset.Interface, t *testing.T)
- func CleanupPods(ctx context.Context, cs clientset.Interface, t *testing.T, pods []*v1.Pod)
- func CleanupTest(t *testing.T, testCtx *TestContext)
- func CreateAndWaitForNodesInCache(testCtx *TestContext, prefix string, wrapper *st.NodeWrapper, numNodes int) ([]*v1.Node, error)
- func CreateGCController(ctx context.Context, tb ktesting.TB, restConfig restclient.Config, informerSet informers.SharedInformerFactory) func()
- func CreateNamespaceController(ctx context.Context, tb ktesting.TB, restConfig restclient.Config, informerSet informers.SharedInformerFactory) func()
- func CreateNamespacesWithLabels(cs clientset.Interface, namespaces []string, labels map[string]string) error
- func CreateNode(cs clientset.Interface, node *v1.Node) (*v1.Node, error)
- func CreatePV(cs clientset.Interface, pv *v1.PersistentVolume) (*v1.PersistentVolume, error)
- func CreatePVC(cs clientset.Interface, pvc *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error)
- func CreatePausePod(cs clientset.Interface, p *v1.Pod) (*v1.Pod, error)
- func CreatePausePodWithResource(cs clientset.Interface, podName string, nsName string, res *v1.ResourceList) (*v1.Pod, error)
- func CreateResourceClaimController(ctx context.Context, tb ktesting.TB, clientSet clientset.Interface, informerFactory informers.SharedInformerFactory) func()
- func DeletePV(cs clientset.Interface, pvName string) error
- func DeletePVC(cs clientset.Interface, pvcName string, nsName string) error
- func DeletePod(cs clientset.Interface, podName string, nsName string) error
- func GetPod(cs clientset.Interface, podName string, podNamespace string) (*v1.Pod, error)
- func GetTolerationSeconds(tolerations []v1.Toleration) (int64, error)
- func InitDisruptionController(t *testing.T, testCtx *TestContext) *disruption.DisruptionController
- func InitPausePod(conf *PausePodConfig) *v1.Pod
- func InitPodWithContainers(cs clientset.Interface, conf *PodWithContainersConfig) *v1.Pod
- func NextPodOrDie(t *testing.T, testCtx *TestContext) *schedulerframework.QueuedPodInfo
- func NodeCopyWithConditions(node *v1.Node, conditions []v1.NodeCondition) *v1.Node
- func NodeReadyStatus(conditions []v1.NodeCondition) (v1.ConditionStatus, error)
- func NodeTainted(ctx context.Context, cs clientset.Interface, nodeName string, taints []v1.Taint) wait.ConditionWithContextFunc
- func PodDeleted(ctx context.Context, c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
- func PodIsGettingEvicted(c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
- func PodScheduled(c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
- func PodScheduledIn(c clientset.Interface, podNamespace, podName string, nodeNames []string) wait.ConditionWithContextFunc
- func PodSchedulingError(c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
- func PodSchedulingGated(ctx context.Context, c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
- func PodUnschedulable(c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
- func PodsCleanedUp(ctx context.Context, c clientset.Interface, namespace string) wait.ConditionWithContextFunc
- func RemovePodFinalizers(ctx context.Context, cs clientset.Interface, t *testing.T, pods ...v1.Pod)
- func RemovePodFinalizersInNamespace(ctx context.Context, cs clientset.Interface, t *testing.T, ns string)
- func RemoveTaintOffNode(cs clientset.Interface, nodeName string, taint v1.Taint) error
- func RunPausePod(cs clientset.Interface, pod *v1.Pod) (*v1.Pod, error)
- func RunPodWithContainers(cs clientset.Interface, pod *v1.Pod) (*v1.Pod, error)
- func StartFakePVController(ctx context.Context, clientSet clientset.Interface, informerFactory informers.SharedInformerFactory)
- func StartScheduler(ctx context.Context, clientSet clientset.Interface, kubeConfig *restclient.Config, cfg *kubeschedulerconfig.KubeSchedulerConfiguration, outOfTreePluginRegistry frameworkruntime.Registry) (*scheduler.Scheduler, informers.SharedInformerFactory)
- func SyncSchedulerInformerFactory(testCtx *TestContext)
- func UpdateNode(cs clientset.Interface, node *v1.Node) (*v1.Node, error)
- func UpdateNodeStatus(cs clientset.Interface, node *v1.Node) error
- func WaitCachedPodsStable(testCtx *TestContext, pods []*v1.Pod) error
- func WaitForNodeTaints(ctx context.Context, cs clientset.Interface, node *v1.Node, taints []v1.Taint) error
- func WaitForNodesInCache(ctx context.Context, sched *scheduler.Scheduler, nodeCount int) error
- func WaitForNominatedNodeName(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error
- func WaitForNominatedNodeNameWithTimeout(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error
- func WaitForPDBsStable(testCtx *TestContext, pdbs []*policy.PodDisruptionBudget, pdbPodNum []int32) error
- func WaitForPodSchedulingGated(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error
- func WaitForPodToSchedule(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error
- func WaitForPodToScheduleWithTimeout(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error
- func WaitForPodUnschedulable(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error
- func WaitForPodUnschedulableWithTimeout(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error
- func WaitForReflection(ctx context.Context, t *testing.T, nodeLister corelisters.NodeLister, key string, passFunc func(n interface{}) bool) error
- func WaitForSchedulerCacheCleanup(ctx context.Context, sched *scheduler.Scheduler, t *testing.T)
- type PausePodConfig
- type PodWithContainersConfig
- type RoundTripWrapper
- type ShutdownFunc
- type TestContext
- func InitTestAPIServer(t *testing.T, nsPrefix string, admission admission.Interface) *TestContext
- func InitTestDisablePreemption(t *testing.T, nsPrefix string) *TestContext
- func InitTestScheduler( t *testing.T, testCtx *TestContext, ) *TestContext
- func InitTestSchedulerWithNS(t *testing.T, nsPrefix string, opts ...scheduler.Option) *TestContext
- func InitTestSchedulerWithOptions( t *testing.T, testCtx *TestContext, resyncPeriod time.Duration, opts ...scheduler.Option, ) *TestContext
Functions ¶
func AddTaintToNode ¶
AddTaintToNode add taints to specific node
func CleanupNodes ¶
CleanupNodes cleans all nodes which were created during integration test
func CleanupPods ¶
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 CreateGCController ¶
func CreateGCController(ctx context.Context, tb ktesting.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 ¶
func CreateNamespaceController(ctx context.Context, tb ktesting.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 ¶
func CreateNamespacesWithLabels(cs clientset.Interface, namespaces []string, labels map[string]string) error
func CreateNode ¶
func CreatePV ¶
func CreatePV(cs clientset.Interface, pv *v1.PersistentVolume) (*v1.PersistentVolume, error)
CreatePV creates a PersistentVolume with the given config and returns its pointer and error status.
func CreatePVC ¶
func CreatePVC(cs clientset.Interface, pvc *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error)
CreatePVC creates a PersistentVolumeClaim with the given config and returns its pointer and error status.
func CreatePausePod ¶
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 CreateResourceClaimController ¶
func CreateResourceClaimController(ctx context.Context, tb ktesting.TB, clientSet clientset.Interface, informerFactory informers.SharedInformerFactory) func()
func DeletePV ¶
DeletePV deletes the given PV in the given namespace.
func DeletePVC ¶
DeletePVC deletes the given PVC in the given namespace.
func DeletePod ¶
DeletePod deletes the given pod in the given namespace.
func GetPod ¶
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 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 ¶
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(ctx context.Context, cs clientset.Interface, nodeName string, taints []v1.Taint) wait.ConditionWithContextFunc
NodeTainted return a condition function that returns true if the given node contains the taints.
func PodDeleted ¶
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 ¶
func PodIsGettingEvicted(c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
PodIsGettingEvicted returns true if the pod's deletion timestamp is set.
func PodScheduled ¶
func PodScheduled(c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
PodScheduled checks if the pod has been scheduled
func PodScheduledIn ¶
func PodScheduledIn(c clientset.Interface, podNamespace, podName string, nodeNames []string) wait.ConditionWithContextFunc
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.ConditionWithContextFunc
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(ctx context.Context, c clientset.Interface, podNamespace, podName string) wait.ConditionWithContextFunc
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.ConditionWithContextFunc
PodUnschedulable returns a condition function that returns true if the given pod gets unschedulable status of reason 'Unschedulable'.
func PodsCleanedUp ¶
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 ¶
RemovePodFinalizers removes pod finalizers for the pods
func RemovePodFinalizersInNamespace ¶
func RemovePodFinalizersInNamespace(ctx context.Context, cs clientset.Interface, t *testing.T, ns string)
func RemoveTaintOffNode ¶
RemoveTaintOffNode removes a specific taint from a node
func RunPausePod ¶
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 ¶
RunPodWithContainers creates a pod with given config and containers and waits until it is scheduled. It returns its pointer and error status.
func StartFakePVController ¶
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 ¶
func StartScheduler(ctx context.Context, clientSet clientset.Interface, kubeConfig *restclient.Config, cfg *kubeschedulerconfig.KubeSchedulerConfiguration, outOfTreePluginRegistry frameworkruntime.Registry) (*scheduler.Scheduler, informers.SharedInformerFactory)
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 ¶
func SyncSchedulerInformerFactory(testCtx *TestContext)
SyncSchedulerInformerFactory starts informer and waits for caches to be synced
func UpdateNode ¶
func UpdateNodeStatus ¶
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(ctx context.Context, 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 ¶
WaitForNodesInCache ensures at least <nodeCount> nodes are present in scheduler cache within 30 seconds; otherwise returns false.
func WaitForNominatedNodeName ¶
func WaitForNominatedNodeNameWithTimeout ¶
func WaitForNominatedNodeNameWithTimeout(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error
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(ctx context.Context, 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 ¶
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(ctx context.Context, 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 ¶
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(ctx context.Context, 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(ctx context.Context, 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 ¶
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 RoundTripWrapper ¶
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 ¶
type TestContext struct { // DisableEventSink, if set to true before calling InitTestScheduler, // will skip the eventBroadcaster.StartRecordingToSink and thus // some extra goroutines which are tricky to get rid of after // a test. DisableEventSink bool 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 // RoundTrip, if set, will be called for every HTTP request going to the apiserver. // It can be used for error injection. RoundTrip atomic.Pointer[RoundTripWrapper] }
TestContext store necessary context info. It also contains some optional parameters for InitTestScheduler.
func InitTestAPIServer ¶
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 ¶
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 ¶
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 ¶
util.go
- Version
- v1.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 57 packages
- Last checked
- 3 hours ago –
Tools for package owners.