...

Package util

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

Overview ▾

Index ▾

Constants
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 NewMockGCECloud(cloud cloud.Cloud) (*gce.Cloud, error)
func NextPod(t *testing.T, testCtx *TestContext) *schedulerframework.QueuedPodInfo
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(cs clientset.Interface, nodeName string, taints []v1.Taint) wait.ConditionFunc
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(c clientset.Interface, podNamespace, podName string) wait.ConditionFunc
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(cs clientset.Interface, node *v1.Node, taints []v1.Taint) error
func WaitForNodesInCache(sched *scheduler.Scheduler, nodeCount int) error
func WaitForPDBsStable(testCtx *TestContext, pdbs []*policy.PodDisruptionBudget, pdbPodNum []int32) error
func WaitForPodSchedulingGated(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error
func WaitForPodToSchedule(cs clientset.Interface, pod *v1.Pod) error
func WaitForPodToScheduleWithTimeout(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error
func WaitForPodUnschedulable(cs clientset.Interface, pod *v1.Pod) error
func WaitForPodUnschedulableWithTimeout(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error
func WaitForReflection(t *testing.T, nodeLister corelisters.NodeLister, key string, passFunc func(n interface{}) bool) error
func WaitForSchedulerCacheCleanup(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

Package files

cloud.go util.go

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

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(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

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 CreateNode(cs clientset.Interface, node *v1.Node) (*v1.Node, error)

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

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 CreateResourceClaimController

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

func DeletePV

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

DeletePV deletes the given PV in the given namespace.

func DeletePVC

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

DeletePVC deletes the given PVC in the given namespace.

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. Note that this function leaks goroutines in the case of timeout; even after this function returns after timeout, the goroutine made by this function keep waiting to pop a pod from the queue.

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(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(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.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

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

RemovePodFinalizers removes pod finalizers for the pods

func RemovePodFinalizersInNamespace

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

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

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 RoundTripWrapper

type RoundTripWrapper func(http.RoundTripper, *http.Request) (*http.Response, error)

type ShutdownFunc

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

type ShutdownFunc func()

type TestContext

TestContext store necessary context info. It also contains some optional parameters for InitTestScheduler.

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]
}

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. 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

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.