package test import ( "context" k8sclient "git.gz.internal.jumaiyx.cn/pkg/k8s-client" "git.gz.internal.jumaiyx.cn/pkg/log" v1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "testing" ) // pods=$(kubectl get pods --selector=job-name=room-hot-compute-job --output=jsonpath='{.items[*].metadata.name}') // echo $pods func TestCreateJob(t *testing.T) { l := log.DefaultLogger() job, err := k8sclient.NewJob(k8sclient.DevNamespace, l) if err != nil { t.Fatal(err) } ctx := context.TODO() ttl := int32(60) ttls := int64(60) _, err = job.Create(ctx, &v1.Job{ ObjectMeta: metav1.ObjectMeta{ Name: "room-hot-compute-job", Namespace: k8sclient.DevNamespace, }, Spec: v1.JobSpec{ ActiveDeadlineSeconds: &ttls, TTLSecondsAfterFinished: &ttl, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Name: "room-hot-compute-job", Labels: map[string]string{ "app": "room-job", }, }, Spec: corev1.PodSpec{ RestartPolicy: corev1.RestartPolicyNever, Containers: []corev1.Container{ { Name: "room-hot-compute-job", Image: "registry.internal.jumaiyx.cn/job/room-hot-compute:v1.0.0", }, }, ImagePullSecrets: []corev1.LocalObjectReference{ { Name: k8sclient.DockerRegistryHarbor, }, }, }, }, }, }) if err != nil { t.Fatal(err) } }