-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
38 lines (33 loc) · 1.12 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package mpioperatortracker
import (
"context"
"time"
kubeflow "github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2beta1"
clientset "github.com/kubeflow/mpi-operator/v2/pkg/client/clientset/versioned"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
)
func NewMPIJob(spec kubeflow.MPIJobSpec) (job kubeflow.MPIJob) {
job.Namespace = "default"
job.GenerateName = "drmaa2-mpioperator-job-"
job.Spec = spec
return
}
func CreateJob(ctx context.Context, mpiClient clientset.Interface, mpiJob *kubeflow.MPIJob, waitForJob bool) (*kubeflow.MPIJob, error) {
mpiJob, err := mpiClient.KubeflowV2beta1().MPIJobs(mpiJob.Namespace).Create(ctx, mpiJob, metav1.CreateOptions{})
if err != nil {
return nil, err
}
// wait for the job to be finished
if waitForJob {
err = wait.Poll(time.Second*5, time.Hour*24*30, func() (bool, error) {
updatedJob, err := mpiClient.KubeflowV2beta1().MPIJobs(mpiJob.Namespace).Get(ctx, mpiJob.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
mpiJob = updatedJob
return mpiJob.Status.CompletionTime != nil, nil
})
}
return mpiJob, err
}