Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Pod name using generated name #215

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller.v1/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = GenGeneralNamePrefix(metaObject.GetName(), rt, idxStr)

if podTemplate.Labels == nil {
podTemplate.Labels = make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions pkg/controller.v1/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func (jc *JobController) CreateNewService(job metav1.Object, rtype apiv1.Replica
service.Spec.Ports = append(service.Spec.Ports, svcPort)
}

//service name can't use the generated name, tensorflow using svc name for discovery.
service.Name = GenGeneralName(job.GetName(), rt, index)
service.Labels = labels
// Create OwnerReference.
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller.v1/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func (p ReplicasPriority) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}

func GenGeneralNamePrefix(jobName string, rtype string, index string) string {
n := jobName + "-" + strings.ToLower(rtype) + "-" + index + "-"
return strings.Replace(n, "/", "-", -1)
}

func GenGeneralName(jobName string, rtype string, index string) string {
n := jobName + "-" + strings.ToLower(rtype) + "-" + index
return strings.Replace(n, "/", "-", -1)
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller.v1/control/pod_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller.v1/control/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down