-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
42 lines (39 loc) · 924 Bytes
/
job.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
39
40
41
42
package api
import (
"context"
"fmt"
batchv1 "k8s.io/api/batch/v1"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func CreateJob() {
fmt.Println("Creating Job . . .")
clientset := CreateClientSet()
jobClient := clientset.BatchV1().Jobs(apiv1.NamespaceDefault)
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "job-test",
},
Spec: batchv1.JobSpec{
Template: apiv1.PodTemplateSpec{
Spec: apiv1.PodSpec{
Containers: []apiv1.Container{
{
Name: "go-version",
Image: "golang:alpine",
Command: []string{"go", "version"},
},
},
RestartPolicy: apiv1.RestartPolicyNever,
},
},
BackoffLimit: int32Ptr(2),
},
}
result, err := jobClient.Create(context.TODO(), job, metav1.CreateOptions{})
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Created Job %q\n", result.GetObjectMeta().GetName())
}