Skip to content

Commit 9501eb6

Browse files
CARRY: Use env variable 'NAMESPACE' for e2e tests
1 parent e224fcc commit 9501eb6

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

test/util/e2e.go

+38-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ import (
2323
visibilityv1alpha1 "sigs.k8s.io/kueue/client-go/clientset/versioned/typed/visibility/v1alpha1"
2424
)
2525

26+
const (
27+
// The environment variable for namespace where Kueue is installed
28+
namespaceEnvVar = "NAMESPACE"
29+
30+
// The namespace where kueue is installed in opendatahub
31+
odhNamespace = "opendatahub"
32+
33+
// The namespace where kueue is installed in rhoai
34+
rhoaiNamespace = "redhat-ods-applications"
35+
36+
// The default namespace where kueue is installed
37+
kueueNamespace = "kueue-system"
38+
39+
undefinedNamespace = "undefined"
40+
)
41+
2642
func CreateClientUsingCluster(kContext string) (client.WithWatch, *rest.Config) {
2743
cfg, err := config.GetConfigWithContext(kContext)
2844
if err != nil {
@@ -74,7 +90,7 @@ func waitForOperatorAvailability(ctx context.Context, k8sClient client.Client, k
7490
pods := &corev1.PodList{}
7591
gomega.EventuallyWithOffset(2, func(g gomega.Gomega) error {
7692
g.Expect(k8sClient.Get(ctx, key, deployment)).To(gomega.Succeed())
77-
g.Expect(k8sClient.List(ctx, pods, client.InNamespace(key.Namespace), client.MatchingLabels(deployment.Spec.Selector.MatchLabels))).To(gomega.Succeed())
93+
g.Expect(k8sClient.List(ctx, pods, client.InNamespace(GetNamespace()), client.MatchingLabels(deployment.Spec.Selector.MatchLabels))).To(gomega.Succeed())
7894
for _, pod := range pods.Items {
7995
for _, cs := range pod.Status.ContainerStatuses {
8096
// To make sure that we don't have restarts of controller-manager.
@@ -95,11 +111,31 @@ func waitForOperatorAvailability(ctx context.Context, k8sClient client.Client, k
95111
}
96112

97113
func WaitForKueueAvailability(ctx context.Context, k8sClient client.Client) {
98-
kcmKey := types.NamespacedName{Namespace: "kueue-system", Name: "kueue-controller-manager"}
114+
kcmKey := types.NamespacedName{Namespace: GetNamespace(), Name: "kueue-controller-manager"}
99115
waitForOperatorAvailability(ctx, k8sClient, kcmKey)
100116
}
101117

102118
func WaitForJobSetAvailability(ctx context.Context, k8sClient client.Client) {
103119
kcmKey := types.NamespacedName{Namespace: "jobset-system", Name: "jobset-controller-manager"}
104120
waitForOperatorAvailability(ctx, k8sClient, kcmKey)
105121
}
122+
123+
func GetNamespace() string {
124+
namespace, ok := os.LookupEnv(namespaceEnvVar)
125+
if !ok {
126+
fmt.Printf("Expected environment variable %s is unset, please use this environment variable to specify in which namespace Kueue is installed", namespaceEnvVar)
127+
os.Exit(1)
128+
}
129+
switch namespace {
130+
case "opendatahub":
131+
return odhNamespace
132+
case "redhat-ods-applications":
133+
return rhoaiNamespace
134+
case "kueue-system":
135+
return kueueNamespace
136+
default:
137+
fmt.Printf("Expected environment variable %s contains an incorrect value", namespaceEnvVar)
138+
os.Exit(1)
139+
return undefinedNamespace
140+
}
141+
}

0 commit comments

Comments
 (0)