diff --git a/pkg/controller.v1/common/pod.go b/pkg/controller.v1/common/pod.go index 6c7816a9..c0f81341 100644 --- a/pkg/controller.v1/common/pod.go +++ b/pkg/controller.v1/common/pod.go @@ -396,7 +396,7 @@ func (jc *JobController) createNewPod(job interface{}, rt string, index int, spe idxStr := strconv.Itoa(index) // Set name for the template. - podTemplate.Name = GenGeneralName(metaObject.GetName(), rt, idxStr) + podTemplate.GenerateName = GenGeneralName(metaObject.GetName(), rt, idxStr) if podTemplate.Labels == nil { podTemplate.Labels = make(map[string]string) diff --git a/pkg/controller.v1/common/service.go b/pkg/controller.v1/common/service.go index 6601cb43..292d1483 100644 --- a/pkg/controller.v1/common/service.go +++ b/pkg/controller.v1/common/service.go @@ -239,7 +239,7 @@ func (jc *JobController) CreateNewService(job metav1.Object, rtype apiv1.Replica service.Spec.Ports = append(service.Spec.Ports, svcPort) } - service.Name = GenGeneralName(job.GetName(), rt, index) + service.GenerateName = GenGeneralName(job.GetName(), rt, index) service.Labels = labels // Create OwnerReference. controllerRef := jc.GenOwnerReference(job) diff --git a/pkg/controller.v1/common/util.go b/pkg/controller.v1/common/util.go index 9e084925..377c95cb 100644 --- a/pkg/controller.v1/common/util.go +++ b/pkg/controller.v1/common/util.go @@ -48,7 +48,7 @@ func (p ReplicasPriority) Swap(i, j int) { } func GenGeneralName(jobName string, rtype string, index string) string { - n := jobName + "-" + strings.ToLower(rtype) + "-" + index + n := jobName + "-" + strings.ToLower(rtype) + "-" + index + "-" return strings.Replace(n, "/", "-", -1) } diff --git a/pkg/controller.v1/common/util_test.go b/pkg/controller.v1/common/util_test.go index ecaab7aa..e03ba831 100644 --- a/pkg/controller.v1/common/util_test.go +++ b/pkg/controller.v1/common/util_test.go @@ -33,13 +33,13 @@ func TestGenGeneralName(t *testing.T) { index: "1", key: "1/2/3/4/5", replicaType: "worker", - expectedName: "1-2-3-4-5-worker-1", + expectedName: "1-2-3-4-5-worker-1-", }, { index: "1", key: "1/2/3/4/5", replicaType: "WORKER", - expectedName: "1-2-3-4-5-worker-1", + expectedName: "1-2-3-4-5-worker-1-", }, } diff --git a/pkg/controller.v1/control/pod_control.go b/pkg/controller.v1/control/pod_control.go index 257625b7..00bfa64d 100644 --- a/pkg/controller.v1/control/pod_control.go +++ b/pkg/controller.v1/control/pod_control.go @@ -21,7 +21,7 @@ import ( commonutil "github.com/kubeflow/common/pkg/util" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -130,6 +130,9 @@ func GetPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Objec Finalizers: desiredFinalizers, }, } + if template.GenerateName != "" { + pod.ObjectMeta.GenerateName = template.GenerateName + } if controllerRef != nil { pod.OwnerReferences = append(pod.OwnerReferences, *controllerRef) } diff --git a/pkg/controller.v1/control/utils.go b/pkg/controller.v1/control/utils.go index 62b910d3..de639c59 100644 --- a/pkg/controller.v1/control/utils.go +++ b/pkg/controller.v1/control/utils.go @@ -18,6 +18,7 @@ package control import ( "fmt" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime"