|
| 1 | +/* |
| 2 | +Copyright 2024. |
| 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 | + kftov1 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v1" |
| 21 | + "github.com/onsi/gomega" |
| 22 | + |
| 23 | + corev1 "k8s.io/api/core/v1" |
| 24 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 25 | +) |
| 26 | + |
| 27 | +func PyTorchJob(t Test, namespace, name string) func(g gomega.Gomega) *kftov1.PyTorchJob { |
| 28 | + return func(g gomega.Gomega) *kftov1.PyTorchJob { |
| 29 | + job, err := t.Client().Kubeflow().KubeflowV1().PyTorchJobs(namespace).Get(t.Ctx(), name, metav1.GetOptions{}) |
| 30 | + g.Expect(err).NotTo(gomega.HaveOccurred()) |
| 31 | + return job |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func PyTorchJobs(t Test, namespace string) func(g gomega.Gomega) []kftov1.PyTorchJob { |
| 36 | + return func(g gomega.Gomega) []kftov1.PyTorchJob { |
| 37 | + jobs, err := t.Client().Kubeflow().KubeflowV1().PyTorchJobs(namespace).List(t.Ctx(), metav1.ListOptions{}) |
| 38 | + g.Expect(err).NotTo(gomega.HaveOccurred()) |
| 39 | + return jobs.Items |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func PyTorchJobConditionRunning(job *kftov1.PyTorchJob) corev1.ConditionStatus { |
| 44 | + return PyTorchJobCondition(job, kftov1.JobRunning) |
| 45 | +} |
| 46 | + |
| 47 | +func PyTorchJobConditionSucceeded(job *kftov1.PyTorchJob) corev1.ConditionStatus { |
| 48 | + return PyTorchJobCondition(job, kftov1.JobSucceeded) |
| 49 | +} |
| 50 | + |
| 51 | +func PyTorchJobConditionSuspended(job *kftov1.PyTorchJob) corev1.ConditionStatus { |
| 52 | + return PyTorchJobCondition(job, kftov1.JobSuspended) |
| 53 | +} |
| 54 | + |
| 55 | +func PyTorchJobConditionFailed(job *kftov1.PyTorchJob) corev1.ConditionStatus { |
| 56 | + return PyTorchJobCondition(job, kftov1.JobFailed) |
| 57 | +} |
| 58 | + |
| 59 | +func PyTorchJobCondition(job *kftov1.PyTorchJob, conditionType kftov1.JobConditionType) corev1.ConditionStatus { |
| 60 | + for _, condition := range job.Status.Conditions { |
| 61 | + if condition.Type == conditionType { |
| 62 | + return condition.Status |
| 63 | + } |
| 64 | + } |
| 65 | + return corev1.ConditionUnknown |
| 66 | +} |
0 commit comments