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

Commit

Permalink
Pod name using generated name
Browse files Browse the repository at this point in the history
Signed-off-by: yowenter <[email protected]>
  • Loading branch information
yowenter committed Apr 26, 2023
1 parent fdb9739 commit 9080844
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 6 deletions.
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 = GenGeneralName(metaObject.GetName(), rt, idxStr)

if podTemplate.Labels == nil {
podTemplate.Labels = make(map[string]string)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/controller.v1/common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-",
},
}

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

0 comments on commit 9080844

Please sign in to comment.