Skip to content

Commit 97540a0

Browse files
Merge pull request #780 from anahas-redhat/localqueueqe
OCPKUEUE-288 - In a LocalQueue Default namespace, jobs and pod should be executed as expected (yaml files test)
2 parents 035c4db + 4e3dfa6 commit 97540a0

File tree

7 files changed

+150
-0
lines changed

7 files changed

+150
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
generateName: e2e-kueue-
5+
labels:
6+
openshift.io/cluster-monitoring: "true"
7+
kueue.openshift.io/managed: "true"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: kueue.x-k8s.io/v1beta1
2+
kind: ClusterQueue
3+
metadata:
4+
name: test-clusterqueue
5+
spec:
6+
namespaceSelector: {} # allows all namespaces
7+
resourceGroups:
8+
- coveredResources: ["cpu", "memory"]
9+
flavors:
10+
- name: default
11+
resources:
12+
- name: cpu
13+
nominalQuota: '100'
14+
- name: memory
15+
nominalQuota: 100Gi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kueue.x-k8s.io/v1beta1
2+
kind: ResourceFlavor
3+
metadata:
4+
name: default
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kueue.x-k8s.io/v1beta1
2+
kind: LocalQueue
3+
metadata:
4+
name: default
5+
spec:
6+
clusterQueue: test-clusterqueue
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: kueuejob2
5+
spec:
6+
parallelism: 1
7+
completions: 1
8+
template:
9+
spec:
10+
restartPolicy: Never
11+
containers:
12+
- name: hello
13+
image: busybox
14+
command: ["echo", "Hello from Kueue!"]
15+
resources:
16+
requests:
17+
cpu: 100m
18+
memory: 128Mi
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: pod1
5+
spec:
6+
securityContext:
7+
runAsNonRoot: true
8+
seccompProfile:
9+
type: RuntimeDefault
10+
containers:
11+
- name: my-container
12+
image: registry.access.redhat.com/ubi8/ubi-minimal:latest
13+
command: ["/bin/sh", "-c"]
14+
args: ["while true; do echo 'Testing'; sleep 30; done"]
15+
securityContext:
16+
allowPrivilegeEscalation: false
17+
capabilities:
18+
drop:
19+
- ALL

test/e2e/e2e_operator_qe_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
. "github.com/onsi/ginkgo/v2"
8+
. "github.com/onsi/gomega"
9+
kueueoperatorv1 "github.com/openshift/kueue-operator/pkg/apis/kueueoperator/v1"
10+
"github.com/openshift/kueue-operator/test/e2e/bindata"
11+
"github.com/openshift/kueue-operator/test/e2e/testutils"
12+
corev1 "k8s.io/api/core/v1"
13+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
15+
"sigs.k8s.io/yaml"
16+
)
17+
18+
var _ = Describe("KueueOperatorQE", Ordered, func() {
19+
var namespaceName string
20+
21+
AfterAll(func(ctx context.Context) {
22+
deleteNamespace(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespaceName}})
23+
deleteClusterQueueAndResourceFlavor(ctx, kueueClient)
24+
testutils.CleanUpKueuInstance(ctx, clients.KueueClient, "cluster")
25+
})
26+
27+
When("LocalQueueDefaulting - Should label and admit Pod and Job in a managed namespace", func() {
28+
It("Should label and admit Job and Pod", func(ctx context.Context) {
29+
kueueClient = clients.UpstreamKueueClient
30+
Expect(deployOperand()).To(Succeed(), "operand deployment should not fail")
31+
kueueInstance, err := clients.KueueClient.KueueV1().Kueues().Get(ctx, "cluster", metav1.GetOptions{})
32+
Expect(err).ToNot(HaveOccurred(), "Failed to fetch Kueue instance")
33+
kueueInstance.Spec.Config.WorkloadManagement.LabelPolicy = kueueoperatorv1.LabelPolicyNone
34+
applyKueueConfig(ctx, kueueInstance.Spec.Config, kubeClient)
35+
namespace := createResource("assets/qe/01_namespace.yaml")
36+
namespaceName = namespace.GetName()
37+
verifyResourceExists(namespace, "Namespace", namespaceName)
38+
resourceFlavor := createResource("assets/qe/10_resource_flavor.yaml")
39+
verifyResourceExists(resourceFlavor, "ResourceFlavor", "default")
40+
clusterQueue := createResource("assets/qe/09_cluster_queue.yaml")
41+
verifyResourceExists(clusterQueue, "ClusterQueue", "test-clusterqueue")
42+
localQueue := createResource("assets/qe/11_local_queue.yaml", namespaceName)
43+
verifyResourceExistsInNamespace(localQueue, "LocalQueue", "default", namespaceName)
44+
job := createResource("assets/qe/12_job.yaml", namespaceName)
45+
verifyResourceExistsInNamespace(job, "Job", "kueuejob2", namespaceName)
46+
Expect(job.GetLabels()).To(HaveKeyWithValue(testutils.QueueLabel, testutils.DefaultLocalQueueName))
47+
verifyWorkloadCreated(kueueClient, namespaceName, string(job.GetUID()))
48+
pod := createResource("assets/qe/13_pod.yaml", namespaceName)
49+
verifyResourceExistsInNamespace(pod, "Pod", "pod1", namespaceName)
50+
Expect(pod.GetLabels()).To(HaveKeyWithValue(testutils.QueueLabel, testutils.DefaultLocalQueueName))
51+
verifyWorkloadCreated(kueueClient, namespaceName, string(pod.GetUID()))
52+
})
53+
})
54+
55+
})
56+
57+
func createResource(assetPath string, namespaceName ...string) *unstructured.Unstructured {
58+
yamlBytes := bindata.MustAsset(assetPath)
59+
resource := &unstructured.Unstructured{}
60+
err := yaml.Unmarshal(yamlBytes, resource)
61+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to unmarshal YAML from %s: %v", assetPath, err))
62+
if resource.GetKind() == "LocalQueue" || resource.GetKind() == "Job" || resource.GetKind() == "Pod" {
63+
Expect(namespaceName).NotTo(BeEmpty(), fmt.Sprintf("%s resource must have a namespace provided", resource.GetKind()))
64+
resource.SetNamespace(namespaceName[0])
65+
}
66+
err = clients.GenericClient.Create(context.Background(), resource)
67+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to create %s: %v", resource.GetKind(), err))
68+
By(fmt.Sprintf("Created %s: %s", resource.GetKind(), resource.GetName()))
69+
return resource
70+
}
71+
72+
func verifyResourceExistsInNamespace(resource *unstructured.Unstructured, kind, name, namespace string) {
73+
Expect(resource.GetKind()).To(Equal(kind), "Resource kind mismatch")
74+
Expect(resource.GetName()).To(Equal(name), "Resource name mismatch")
75+
Expect(resource.GetNamespace()).To(Equal(namespace), "Resource namespace mismatch")
76+
}
77+
78+
func verifyResourceExists(resource *unstructured.Unstructured, kind, name string) {
79+
Expect(resource.GetKind()).To(Equal(kind), "Resource kind mismatch")
80+
Expect(resource.GetName()).To(Equal(name), "Resource name mismatch")
81+
}

0 commit comments

Comments
 (0)