Skip to content

Commit aad87e8

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents c134b7c + 64ec6c8 commit aad87e8

File tree

4 files changed

+717
-0
lines changed

4 files changed

+717
-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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}
43+
44+
func GetAllJobs(test Test, namespace string) ([]batchv1.Job, error) {
45+
test.T().Helper()
46+
47+
jobs, err := test.Client().Core().BatchV1().Jobs(namespace).List(test.Ctx(), metav1.ListOptions{})
48+
if err != nil {
49+
return nil, err
50+
}
51+
52+
return jobs.Items, nil
53+
}

tests/common/support/jobset.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
func JobSets(t Test, namespace string) func(g gomega.Gomega) []*jobsetv1alpha2.JobSet {
27+
return func(g gomega.Gomega) []*jobsetv1alpha2.JobSet {
28+
jobsets, err := t.Client().JobSet().JobsetV1alpha2().JobSets(namespace).List(t.Ctx(), metav1.ListOptions{})
29+
g.Expect(err).NotTo(gomega.HaveOccurred())
30+
31+
jobsetsp := []*jobsetv1alpha2.JobSet{}
32+
for _, v := range jobsets.Items {
33+
jobsetsp = append(jobsetsp, &v)
34+
}
35+
36+
return jobsetsp
37+
}
38+
}
39+
40+
func SingleJobSet(t Test, namespace string) func(g gomega.Gomega) *jobsetv1alpha2.JobSet {
41+
return func(g gomega.Gomega) *jobsetv1alpha2.JobSet {
42+
jobsets := JobSets(t, namespace)(g)
43+
g.Expect(jobsets).To(gomega.HaveLen(1))
44+
return jobsets[0]
45+
}
46+
}
47+
48+
func JobSetReplicatedJobsCount(jobset *jobsetv1alpha2.JobSet) int {
49+
if jobset == nil {
50+
return 0
51+
}
52+
return len(jobset.Spec.ReplicatedJobs)
53+
}
54+
55+
func JobSetCondition(jobset *jobsetv1alpha2.JobSet, conditionType jobsetv1alpha2.JobSetConditionType) metav1.ConditionStatus {
56+
if jobset == nil {
57+
return metav1.ConditionUnknown
58+
}
59+
for _, condition := range jobset.Status.Conditions {
60+
if string(condition.Type) == string(conditionType) {
61+
return condition.Status
62+
}
63+
}
64+
return metav1.ConditionUnknown
65+
}
66+
67+
func JobSetConditionFailed(jobset *jobsetv1alpha2.JobSet) metav1.ConditionStatus {
68+
return JobSetCondition(jobset, jobsetv1alpha2.JobSetFailed)
69+
}
70+
71+
func JobSetFailureMessage(jobset *jobsetv1alpha2.JobSet) string {
72+
if jobset == nil {
73+
return ""
74+
}
75+
for _, condition := range jobset.Status.Conditions {
76+
if string(condition.Type) == string(jobsetv1alpha2.JobSetFailed) && condition.Status == metav1.ConditionTrue {
77+
return condition.Message
78+
}
79+
}
80+
return ""
81+
}

0 commit comments

Comments
 (0)