Skip to content

Commit 9de4c34

Browse files
committed
Add test coverage for JobSet Workflow Orchestration
1 parent 54395f4 commit 9de4c34

File tree

4 files changed

+616
-0
lines changed

4 files changed

+616
-0
lines changed

tests/common/support/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
_ "k8s.io/client-go/plugin/pkg/client/auth"
2828
"k8s.io/client-go/rest"
2929
"k8s.io/client-go/tools/clientcmd"
30+
jobsetclient "sigs.k8s.io/jobset/client-go/clientset/versioned"
3031
kueueclient "sigs.k8s.io/kueue/client-go/clientset/versioned"
3132

3233
imagev1 "github.com/openshift/client-go/image/clientset/versioned"
@@ -40,6 +41,7 @@ type Client interface {
4041
Core() kubernetes.Interface
4142
Trainer() trainerclient.Interface
4243
Kubeflow() kubeflowclient.Interface
44+
JobSet() jobsetclient.Interface
4345
Kueue() kueueclient.Interface
4446
Machine() machinev1.Interface
4547
Route() routev1.Interface
@@ -53,6 +55,7 @@ type testClient struct {
5355
core kubernetes.Interface
5456
trainer trainerclient.Interface
5557
kubeflow kubeflowclient.Interface
58+
jobset jobsetclient.Interface
5659
kueue kueueclient.Interface
5760
machine machinev1.Interface
5861
route routev1.Interface
@@ -76,6 +79,10 @@ func (t *testClient) Kubeflow() kubeflowclient.Interface {
7679
return t.kubeflow
7780
}
7881

82+
func (t *testClient) JobSet() jobsetclient.Interface {
83+
return t.jobset
84+
}
85+
7986
func (t *testClient) Kueue() kueueclient.Interface {
8087
return t.kueue
8188
}
@@ -131,6 +138,11 @@ func newTestClient(cfg *rest.Config) (Client, *rest.Config, error) {
131138
return nil, nil, err
132139
}
133140

141+
jobsetClient, err := jobsetclient.NewForConfig(cfg)
142+
if err != nil {
143+
return nil, nil, err
144+
}
145+
134146
kueueClient, err := kueueclient.NewForConfig(cfg)
135147
if err != nil {
136148
return nil, nil, err
@@ -170,6 +182,7 @@ func newTestClient(cfg *rest.Config) (Client, *rest.Config, error) {
170182
core: kubeClient,
171183
trainer: trainerClient,
172184
kubeflow: kubeflowClient,
185+
jobset: jobsetClient,
173186
kueue: kueueClient,
174187
machine: machineClient,
175188
route: routeClient,

tests/common/support/jobs.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package support
18+
19+
import (
20+
"strings"
21+
22+
batchv1 "k8s.io/api/batch/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
)
25+
26+
func GetJobByNamePattern(test Test, namespace, pattern string) (*batchv1.Job, error) {
27+
test.T().Helper()
28+
29+
jobs, err := test.Client().Core().BatchV1().Jobs(namespace).List(test.Ctx(), metav1.ListOptions{})
30+
if err != nil {
31+
return nil, err
32+
}
33+
34+
for i := range jobs.Items {
35+
job := &jobs.Items[i]
36+
if strings.Contains(job.Name, pattern) {
37+
return job, nil
38+
}
39+
}
40+
41+
return nil, nil
42+
}

tests/common/support/jobset.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package support
18+
19+
import (
20+
. "github.com/onsi/gomega"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
jobsetv1alpha2 "sigs.k8s.io/jobset/api/jobset/v1alpha2"
24+
)
25+
26+
// GetSingleJobSet returns the single JobSet in the namespace, expecting exactly one to exist
27+
func GetSingleJobSet(test Test, namespace string) (*jobsetv1alpha2.JobSet, error) {
28+
test.T().Helper()
29+
30+
jobsets, err := test.Client().JobSet().JobsetV1alpha2().JobSets(namespace).List(
31+
test.Ctx(), metav1.ListOptions{})
32+
if err != nil {
33+
return nil, err
34+
}
35+
36+
test.Expect(jobsets.Items).To(HaveLen(1), "Expected exactly one JobSet in namespace")
37+
return &jobsets.Items[0], nil
38+
}

0 commit comments

Comments
 (0)