util

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: Apache-2.0 Imports: 62 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TinyTimeout  = 10 * time.Millisecond
	ShortTimeout = time.Second
	Timeout      = 10 * time.Second
	// LongTimeout is meant for E2E tests when waiting for complex operations
	// such as running pods to completion.
	LongTimeout = 45 * time.Second
	// VeryLongTimeout is meant for E2E tests involving Ray which starts ray-project images (over 2GB)
	// and also synchronizes the cluster before it can be used
	VeryLongTimeout = 5 * time.Minute
	// StartUpTimeout is meant to be used for waiting for Kueue to startup, given
	// that cert updates can take up to 3 minutes to propagate to the filesystem.
	// Taken into account that after the certificates are ready, all Kueue's components
	// need started and the time it takes for a change in ready probe response triggers
	// a change in the deployment status.
	StartUpTimeout     = 5 * time.Minute
	ConsistentDuration = time.Second
	Interval           = time.Millisecond * 250
)
View Source
const (
	// E2eTestAgnHostImageOld is the image used for testing rolling update.
	E2eTestAgnHostImageOld = "registry.k8s.io/e2e-test-images/agnhost:2.52@sha256:b173c7d0ffe3d805d49f4dfe48375169b7b8d2e1feb81783efd61eb9d08042e6"
	// E2eTestAgnHostImage is the image used for testing.
	E2eTestAgnHostImage = "registry.k8s.io/e2e-test-images/agnhost:2.53@sha256:99c6b4bb4a1e1df3f0b3752168c89358794d02258ebebc26bf21c29399011a85"
)

Variables

View Source
var (
	IgnoreConditionTimestamps                      = cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime")
	IgnoreConditionTimestampsAndObservedGeneration = cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime", "ObservedGeneration")
	IgnoreConditionMessage                         = cmpopts.IgnoreFields(metav1.Condition{}, "Message")
	IgnoreObjectMetaResourceVersion                = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion")
	IgnoreDeploymentConditionTimestampsAndMessage  = cmpopts.IgnoreFields(appsv1.DeploymentCondition{}, "LastTransitionTime", "LastUpdateTime", "Message")
)
View Source
var (
	AutoscalerCrds       = filepath.Join(GetProjectBaseDir(), "dep-crds", "cluster-autoscaler")
	JobsetCrds           = filepath.Join(GetProjectBaseDir(), "dep-crds", "jobset-operator")
	TrainingOperatorCrds = filepath.Join(GetProjectBaseDir(), "dep-crds", "training-operator-crds")
	MpiOperatorCrds      = filepath.Join(GetProjectBaseDir(), "dep-crds", "mpi-operator")
	AppWrapperCrds       = filepath.Join(GetProjectBaseDir(), "dep-crds", "appwrapper-crds")
	RayOperatorCrds      = filepath.Join(GetProjectBaseDir(), "dep-crds", "ray-operator-crds")
	WebhookPath          = filepath.Join(GetProjectBaseDir(), "config", "components", "webhook")
)
View Source
var (

	// Starts a simple HTTP(S) with a few endpoints, one of which is the /exit endpoint which exits with `exit 0`
	BehaviorWaitForDeletion = []string{"netexec"}

	// Starts a container which always ends in failure on deletion.
	// To achieve this runs simple webserver, but does not register any signal handler.
	BehaviorWaitForDeletionFailOnExit = []string{"test-webserver"}

	// The agnhost container will print args passed and `exit 0`
	BehaviorExitFast = []string{"entrypoint-tester"}
)
View Source
var SetupLogger = sync.OnceFunc(func() {
	ctrl.SetLogger(NewTestingLogger(ginkgo.GinkgoWriter, logLevel()))
})

Functions

func ApplyKueueConfiguration added in v0.11.0

func ApplyKueueConfiguration(ctx context.Context, k8sClient client.Client, kueueCfg *configapi.Configuration)

func AwaitAndVerifyCreatedWorkload added in v0.5.0

func AwaitAndVerifyCreatedWorkload(ctx context.Context, client client.Client, wlLookupKey types.NamespacedName, createdJob metav1.Object) *kueue.Workload

func AwaitAndVerifyWorkloadQueueName added in v0.5.0

func AwaitAndVerifyWorkloadQueueName(ctx context.Context, client client.Client, createdWorkload *kueue.Workload, wlLookupKey types.NamespacedName, jobQueueName string)

func AwaitWorkloadEvictionByPodsReadyTimeout added in v0.6.3

func AwaitWorkloadEvictionByPodsReadyTimeout(ctx context.Context, k8sClient client.Client, wlKey client.ObjectKey, sleep time.Duration)

func BindPodWithNode added in v0.6.3

func BindPodWithNode(ctx context.Context, k8sClient client.Client, nodeName string, pods ...*corev1.Pod)

func CreateClientUsingCluster added in v0.6.0

func CreateClientUsingCluster(kContext string) (client.WithWatch, *rest.Config)

func CreateNamespaceFromPrefixWithLog added in v0.11.0

func CreateNamespaceFromPrefixWithLog(ctx context.Context, k8sClient client.Client, nsPrefix string) *corev1.Namespace

func CreateNamespaceWithLog added in v0.11.0

func CreateNamespaceWithLog(ctx context.Context, k8sClient client.Client, nsName string) *corev1.Namespace

func CreateNodesWithStatus added in v0.11.0

func CreateNodesWithStatus(ctx context.Context, c client.Client, nodes []corev1.Node)

func CreateRestClient added in v0.9.5

func CreateRestClient(cfg *rest.Config) *rest.RESTClient

CreateRestClient creates a *rest.RESTClient using the provided config.

func CreateVisibilityClient added in v0.6.0

func CreateVisibilityClient(user string) visibilityv1beta1.VisibilityV1beta1Interface

func DeleteAllAppWrappersInNamespace added in v0.11.0

func DeleteAllAppWrappersInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func DeleteAllJobSetsInNamespace added in v0.10.3

func DeleteAllJobSetsInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func DeleteAllJobsInNamespace added in v0.4.0

func DeleteAllJobsInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func DeleteAllLeaderWorkerSetsInNamespace added in v0.11.0

func DeleteAllLeaderWorkerSetsInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func DeleteAllMPIJobsInNamespace added in v0.10.0

func DeleteAllMPIJobsInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func DeleteAllPodsInNamespace added in v0.6.0

func DeleteAllPodsInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func DeleteAllPyTorchJobsInNamespace added in v0.10.0

func DeleteAllPyTorchJobsInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func DeleteAllRayJobsInNamespace added in v0.10.3

func DeleteAllRayJobsInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func DeleteNamespace

func DeleteNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

DeleteNamespace deletes all objects the tests typically create in the namespace.

func DeleteObject added in v0.8.0

func DeleteObject[PtrT objAsPtr[T], T any](ctx context.Context, c client.Client, o PtrT) error

func DeleteWorkloadsInNamespace

func DeleteWorkloadsInNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error

func ExpectAdmissionAttemptsMetric added in v0.6.1

func ExpectAdmissionAttemptsMetric(pending, admitted int)

func ExpectAdmittedWorkloadsTotalMetric

func ExpectAdmittedWorkloadsTotalMetric(cq *kueue.ClusterQueue, v int)

func ExpectAllPodsInNamespaceDeleted added in v0.10.3

func ExpectAllPodsInNamespaceDeleted(ctx context.Context, c client.Client, ns *corev1.Namespace)

func ExpectCQResourceBorrowingQuota added in v0.5.0

func ExpectCQResourceBorrowingQuota(cq *kueue.ClusterQueue, flavor, resource string, value float64)

func ExpectCQResourceNominalQuota added in v0.5.0

func ExpectCQResourceNominalQuota(cq *kueue.ClusterQueue, flavor, resource string, value float64)

func ExpectCQResourceReservations added in v0.5.0

func ExpectCQResourceReservations(cq *kueue.ClusterQueue, flavor, resource string, value float64)

func ExpectClusterQueueStatusMetric

func ExpectClusterQueueStatusMetric(cq *kueue.ClusterQueue, status metrics.ClusterQueueStatus)

func ExpectClusterQueueWeightedShareMetric added in v0.7.0

func ExpectClusterQueueWeightedShareMetric(cq *kueue.ClusterQueue, value int64)

func ExpectClusterQueuesToBeActive added in v0.9.0

func ExpectClusterQueuesToBeActive(ctx context.Context, c client.Client, cqs ...*kueue.ClusterQueue)

func ExpectEventsForObjects added in v0.7.0

func ExpectEventsForObjects(eventWatcher watch.Interface, objs sets.Set[types.NamespacedName], filter func(*corev1.Event) bool)

func ExpectEvictedWorkloadsTotalMetric added in v0.7.0

func ExpectEvictedWorkloadsTotalMetric(cqName, reason string, v int)

func ExpectJobUnsuspendedWithNodeSelectors added in v0.11.0

func ExpectJobUnsuspendedWithNodeSelectors(ctx context.Context, c client.Client, key types.NamespacedName, nodeSelector map[string]string)

func ExpectLQAdmittedWorkloadsTotalMetric added in v0.10.0

func ExpectLQAdmittedWorkloadsTotalMetric(lq *kueue.LocalQueue, value int)

func ExpectLQByStatusMetric added in v0.10.0

func ExpectLQByStatusMetric(lq *kueue.LocalQueue, status metav1.ConditionStatus)

func ExpectLQPendingWorkloadsMetric added in v0.10.0

func ExpectLQPendingWorkloadsMetric(lq *kueue.LocalQueue, active, inadmissible int)

func ExpectLQReservingActiveWorkloadsMetric added in v0.10.0

func ExpectLQReservingActiveWorkloadsMetric(lq *kueue.LocalQueue, value int)

func ExpectLocalQueueResourceMetric added in v0.10.1

func ExpectLocalQueueResourceMetric(queue *kueue.LocalQueue, flavorName, resourceName string, value float64)

func ExpectLocalQueueResourceReservationsMetric added in v0.10.1

func ExpectLocalQueueResourceReservationsMetric(queue *kueue.LocalQueue, flavorName, resourceName string, value float64)

func ExpectLocalQueuesToBeActive added in v0.10.0

func ExpectLocalQueuesToBeActive(ctx context.Context, c client.Client, lqs ...*kueue.LocalQueue)

func ExpectObjectToBeDeleted added in v0.8.0

func ExpectObjectToBeDeleted[PtrT objAsPtr[T], T any](ctx context.Context, k8sClient client.Client, o PtrT, deleteNow bool)

func ExpectObjectToBeDeletedWithTimeout added in v0.9.0

func ExpectObjectToBeDeletedWithTimeout[PtrT objAsPtr[T], T any](ctx context.Context, k8sClient client.Client, o PtrT, deleteNow bool, timeout time.Duration)

func ExpectPendingWorkloadsMetric

func ExpectPendingWorkloadsMetric(cq *kueue.ClusterQueue, active, inadmissible int)

func ExpectPodUnsuspendedWithNodeSelectors added in v0.6.0

func ExpectPodUnsuspendedWithNodeSelectors(ctx context.Context, k8sClient client.Client, key types.NamespacedName, ns map[string]string)

func ExpectPodsFinalizedOrGone added in v0.9.0

func ExpectPodsFinalizedOrGone(ctx context.Context, k8sClient client.Client, keys ...types.NamespacedName)

func ExpectPodsJustFinalized added in v0.9.0

func ExpectPodsJustFinalized(ctx context.Context, k8sClient client.Client, keys ...types.NamespacedName)

func ExpectPreemptedCondition added in v0.8.0

func ExpectPreemptedCondition(ctx context.Context, k8sClient client.Client, reason string, status metav1.ConditionStatus, preemptedWl, preempteeWl *kueue.Workload, preemteeWorkloadUID, preempteeJobUID string)

func ExpectPreemptedWorkloadsTotalMetric added in v0.8.0

func ExpectPreemptedWorkloadsTotalMetric(preemptorCqName, reason string, v int)

func ExpectQuotaReservedWorkloadsTotalMetric added in v0.7.0

func ExpectQuotaReservedWorkloadsTotalMetric(cq *kueue.ClusterQueue, v int)

func ExpectReservingActiveWorkloadsMetric added in v0.5.0

func ExpectReservingActiveWorkloadsMetric(cq *kueue.ClusterQueue, value int)

func ExpectWorkloadToBeAdmittedAs

func ExpectWorkloadToBeAdmittedAs(ctx context.Context, k8sClient client.Client, wl *kueue.Workload, admission *kueue.Admission)

func ExpectWorkloadToFinish added in v0.6.0

func ExpectWorkloadToFinish(ctx context.Context, k8sClient client.Client, wlKey client.ObjectKey)

func ExpectWorkloadToHaveRequeueState added in v0.6.3

func ExpectWorkloadToHaveRequeueState(ctx context.Context, k8sClient client.Client, wlKey client.ObjectKey, expected *kueue.RequeueState, hasRequeueAt bool)

func ExpectWorkloadsFinalizedOrGone added in v0.9.0

func ExpectWorkloadsFinalizedOrGone(ctx context.Context, k8sClient client.Client, keys ...types.NamespacedName)

func ExpectWorkloadsToBeAdmitted

func ExpectWorkloadsToBeAdmitted(ctx context.Context, k8sClient client.Client, wls ...*kueue.Workload)

func ExpectWorkloadsToBeAdmittedCount added in v0.6.2

func ExpectWorkloadsToBeAdmittedCount(ctx context.Context, k8sClient client.Client, count int, wls ...*kueue.Workload)

func ExpectWorkloadsToBeFrozen

func ExpectWorkloadsToBeFrozen(ctx context.Context, k8sClient client.Client, cq string, wls ...*kueue.Workload)

func ExpectWorkloadsToBePending

func ExpectWorkloadsToBePending(ctx context.Context, k8sClient client.Client, wls ...*kueue.Workload)

func ExpectWorkloadsToBePreempted added in v0.5.0

func ExpectWorkloadsToBePreempted(ctx context.Context, k8sClient client.Client, wls ...*kueue.Workload)

func ExpectWorkloadsToBeWaiting

func ExpectWorkloadsToBeWaiting(ctx context.Context, k8sClient client.Client, wls ...*kueue.Workload)

func ExpectWorkloadsToHaveQuotaReservation added in v0.5.0

func ExpectWorkloadsToHaveQuotaReservation(ctx context.Context, k8sClient client.Client, cqName string, wls ...*kueue.Workload)

func FilterEvictedWorkloads added in v0.6.2

func FilterEvictedWorkloads(ctx context.Context, k8sClient client.Client, wls ...*kueue.Workload) []*kueue.Workload

func FindDeploymentCondition added in v0.11.0

func FindDeploymentCondition(deployment *appsv1.Deployment, deploymentType appsv1.DeploymentConditionType) *appsv1.DeploymentCondition

func FinishEvictionForWorkloads added in v0.4.0

func FinishEvictionForWorkloads(ctx context.Context, k8sClient client.Client, wls ...*kueue.Workload)

func FinishEvictionOfWorkloadsInCQ added in v0.10.4

func FinishEvictionOfWorkloadsInCQ(ctx context.Context, k8sClient client.Client, cq *kueue.ClusterQueue, n int)

func FinishRunningWorkloadsInCQ added in v0.10.4

func FinishRunningWorkloadsInCQ(ctx context.Context, k8sClient client.Client, cq *kueue.ClusterQueue, n int)

func FinishWorkloads

func FinishWorkloads(ctx context.Context, k8sClient client.Client, workloads ...*kueue.Workload)

func GetKuberayTestImage added in v0.10.3

func GetKuberayTestImage() string

func GetKueueConfiguration added in v0.11.0

func GetKueueConfiguration(ctx context.Context, k8sClient client.Client) *configapi.Configuration

func GetListOptsFromLabel added in v0.11.0

func GetListOptsFromLabel(label string) *client.ListOptions

func GetProjectBaseDir added in v0.11.0

func GetProjectBaseDir() string

GetProjectBaseDir retrieves the project base directory either from an environment variable or by searching for a Makefile. The fallback to the search is useful for running in IDEs like vs-code which don't set the PROJECT_DIR env. variable by default.

func KExecute added in v0.9.5

func KExecute(ctx context.Context, cfg *rest.Config, client *rest.RESTClient, ns, pod, container string, command []string) ([]byte, []byte, error)

func NewNamespaceSelectorExcluding added in v0.10.0

func NewNamespaceSelectorExcluding(unmanaged ...string) labels.Selector

func NewTestingLogger added in v0.8.0

func NewTestingLogger(writer io.Writer, level int) logr.Logger

func RestartKueueController added in v0.11.0

func RestartKueueController(ctx context.Context, k8sClient client.Client)

func SetAdmissionCheckActive added in v0.5.0

func SetAdmissionCheckActive(ctx context.Context, k8sClient client.Client, admissionCheck *kueue.AdmissionCheck, status metav1.ConditionStatus)

func SetPodsPhase added in v0.6.0

func SetPodsPhase(ctx context.Context, k8sClient client.Client, phase corev1.PodPhase, pods ...*corev1.Pod)

func SetQuotaReservation added in v0.5.0

func SetQuotaReservation(ctx context.Context, k8sClient client.Client, wl *kueue.Workload, admission *kueue.Admission) error

func SetRequeuedConditionWithPodsReadyTimeout added in v0.7.0

func SetRequeuedConditionWithPodsReadyTimeout(ctx context.Context, k8sClient client.Client, wlKey client.ObjectKey)

func SetWorkloadsAdmissionCheck added in v0.5.0

func SetWorkloadsAdmissionCheck(ctx context.Context, k8sClient client.Client, wl *kueue.Workload, check string, state kueue.CheckState, expectExisting bool)

func SyncAdmittedConditionForWorkloads added in v0.5.0

func SyncAdmittedConditionForWorkloads(ctx context.Context, k8sClient client.Client, wls ...*kueue.Workload)

SyncAdmittedConditionForWorkloads sets the Admission condition of the provided workloads based on the state of quota reservation and admission checks. It should be use in tests that are not running the workload controller.

func UnholdClusterQueue added in v0.8.0

func UnholdClusterQueue(ctx context.Context, k8sClient client.Client, cq *kueue.ClusterQueue)

func UnholdLocalQueue added in v0.8.0

func UnholdLocalQueue(ctx context.Context, k8sClient client.Client, lq *kueue.LocalQueue)

func VerifyWorkloadPriority added in v0.5.0

func VerifyWorkloadPriority(createdWorkload *kueue.Workload, priorityClassName string, priorityValue int32)

func WaitForActivePodsAndTerminate added in v0.9.5

func WaitForActivePodsAndTerminate(ctx context.Context, k8sClient client.Client, restClient *rest.RESTClient, cfg *rest.Config, namespace string, activePodsCount, exitCode int, opts ...client.ListOption)

func WaitForAppWrapperAvailability added in v0.11.0

func WaitForAppWrapperAvailability(ctx context.Context, k8sClient client.Client)

func WaitForJobSetAvailability added in v0.7.1

func WaitForJobSetAvailability(ctx context.Context, k8sClient client.Client)

func WaitForKubeFlowMPIOperatorAvailability added in v0.9.0

func WaitForKubeFlowMPIOperatorAvailability(ctx context.Context, k8sClient client.Client)

func WaitForKubeFlowTrainingOperatorAvailability added in v0.9.0

func WaitForKubeFlowTrainingOperatorAvailability(ctx context.Context, k8sClient client.Client)

func WaitForKubeRayOperatorAvailability added in v0.10.3

func WaitForKubeRayOperatorAvailability(ctx context.Context, k8sClient client.Client)

func WaitForKueueAvailability added in v0.6.0

func WaitForKueueAvailability(ctx context.Context, k8sClient client.Client)

func WaitForLeaderWorkerSetAvailability added in v0.11.0

func WaitForLeaderWorkerSetAvailability(ctx context.Context, k8sClient client.Client)

func WaitForNextSecondAfterCreation added in v0.9.0

func WaitForNextSecondAfterCreation(obj client.Object)

WaitForNextSecondAfterCreation wait time between the start of the next second after creationTimestamp and the current time to ensure that the new created object has a later creation time.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳