Skip to content

Commit

Permalink
CARRY: Use env variable 'NAMESPACE' for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shilpa Chugh authored and astefanutti committed Feb 21, 2024
1 parent 2112951 commit a060137
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions test/util/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ import (
visibilityv1alpha1 "sigs.k8s.io/kueue/client-go/clientset/versioned/typed/visibility/v1alpha1"
)

const (
// The environment variable for namespace where Kueue is installed
namespaceEnvVar = "NAMESPACE"

// The namespace where kueue is installed in opendatahub
odhNamespace = "opendatahub"

// The namespace where kueue is installed in rhoai
rhoaiNamespace = "redhat-ods-applications"

// The default namespace where kueue is installed
kueueNamespace = "kueue-system"

undefinedNamespace = "undefined"
)

func CreateClientUsingCluster(kContext string) client.WithWatch {
cfg, err := config.GetConfigWithContext(kContext)
if err != nil {
Expand Down Expand Up @@ -70,14 +86,14 @@ func CreateVisibilityClient(user string) visibilityv1alpha1.VisibilityV1alpha1In

func WaitForKueueAvailability(ctx context.Context, k8sClient client.Client) {
kcmKey := types.NamespacedName{
Namespace: "kueue-system",
Namespace: GetNamespace(),
Name: "kueue-controller-manager",
}
deployment := &appsv1.Deployment{}
pods := corev1.PodList{}
gomega.EventuallyWithOffset(1, func(g gomega.Gomega) error {
g.Expect(k8sClient.Get(ctx, kcmKey, deployment)).To(gomega.Succeed())
g.Expect(k8sClient.List(ctx, &pods, client.InNamespace("kueue-system"), client.MatchingLabels(deployment.Spec.Selector.MatchLabels))).To(gomega.Succeed())
g.Expect(k8sClient.List(ctx, &pods, client.InNamespace(GetNamespace()), client.MatchingLabels(deployment.Spec.Selector.MatchLabels))).To(gomega.Succeed())
for _, pod := range pods.Items {
for _, cs := range pod.Status.ContainerStatuses {
if cs.RestartCount > 0 {
Expand All @@ -95,3 +111,23 @@ func WaitForKueueAvailability(ctx context.Context, k8sClient client.Client) {

}, StartUpTimeout, Interval).Should(gomega.Succeed())
}

func GetNamespace() string {
namespace, ok := os.LookupEnv(namespaceEnvVar)
if !ok {
fmt.Printf("Expected environment variable %s is unset, please use this environment variable to specify in which namespace Kueue is installed", namespaceEnvVar)
os.Exit(1)
}
switch namespace {
case "opendatahub":
return odhNamespace
case "redhat-ods-applications":
return rhoaiNamespace
case "kueue-system":
return kueueNamespace
default:
fmt.Printf("Expected environment variable %s contains an incorrect value", namespaceEnvVar)
os.Exit(1)
return undefinedNamespace
}
}

0 comments on commit a060137

Please sign in to comment.