Skip to content

Add function to get Kueue workloads #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions support/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,26 @@ func CreateKueueLocalQueue(t Test, namespace, clusterQueueName string) *kueuev1b

return localQueue
}

func GetKueueWorkloads(t Test, namespace string) []*kueuev1beta1.Workload {
t.T().Helper()

workloads, err := t.Client().Kueue().KueueV1beta1().Workloads(namespace).List(t.Ctx(), metav1.ListOptions{})
t.Expect(err).NotTo(gomega.HaveOccurred())

workloadsp := []*kueuev1beta1.Workload{}
for _, v := range workloads.Items {
workloadsp = append(workloadsp, &v)
}

return workloadsp
}

func KueueWorkloadAdmitted(workload *kueuev1beta1.Workload) bool {
for _, v := range workload.Status.Conditions {
if v.Type == "Admitted" && v.Status == "True" {
return true
}
}
return false
}
24 changes: 24 additions & 0 deletions support/kueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,27 @@ func TestCreateKueueLocalQueue(t *testing.T) {
test.Expect(lq.Namespace).To(gomega.Equal("ns-1"))
test.Expect(lq.Spec.ClusterQueue).To(gomega.Equal(kueuev1beta1.ClusterQueueReference("cq-1")))
}

func TestGetKueueWorkloads(t *testing.T) {
test := NewTest(t)

wl := &kueuev1beta1.Workload{
TypeMeta: metav1.TypeMeta{
APIVersion: kueuev1beta1.SchemeGroupVersion.String(),
Kind: "Workload",
},
ObjectMeta: metav1.ObjectMeta{
Name: "wl1",
},
}

_, err := test.Client().Kueue().KueueV1beta1().Workloads("ns-1").Create(test.ctx, wl, metav1.CreateOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "ns-1" always the same or should it be parameterized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is just a sample test value, can be anything

test.Expect(err).To(gomega.BeNil())

wls := GetKueueWorkloads(test, "ns-1")

test.Expect(wls).To(gomega.Not(gomega.BeNil()))
test.Expect(wls).To(gomega.HaveLen(1))
test.Expect(wls[0].Name).To(gomega.Equal("wl1"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as with "ns-1".

test.Expect(wls[0].Namespace).To(gomega.Equal("ns-1"))
}