Skip to content

Commit

Permalink
refactor: add GenPodGroupName method to extract podGroupName in diffe…
Browse files Browse the repository at this point in the history
…rent place (kubeflow#1034)

(cherry picked from commit eedd3bb)
  • Loading branch information
zlcnju authored and ChenYi015 committed Nov 6, 2024
1 parent eb8e676 commit 960159b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/common/jobcontroller/jobcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ func (jc *JobController) SyncPodGroup(job metav1.Object, minAvailableReplicas in

kubeBatchClientInterface := jc.KubeBatchClientSet
// Check whether podGroup exists or not
podGroup, err := kubeBatchClientInterface.SchedulingV1alpha1().PodGroups(job.GetNamespace()).Get(job.GetName(), metav1.GetOptions{})
podGroupName := GenPodGroupName(job.GetName())
podGroup, err := kubeBatchClientInterface.SchedulingV1alpha1().PodGroups(job.GetNamespace()).Get(podGroupName, metav1.GetOptions{})
if err == nil {
return podGroup, nil
}
Expand All @@ -226,7 +227,7 @@ func (jc *JobController) SyncPodGroup(job metav1.Object, minAvailableReplicas in
minAvailable := intstr.FromInt(int(minAvailableReplicas))
createPodGroup := &v1alpha1.PodGroup{
ObjectMeta: metav1.ObjectMeta{
Name: job.GetName(),
Name: podGroupName,
OwnerReferences: []metav1.OwnerReference{
*jc.GenOwnerReference(job),
},
Expand Down
5 changes: 5 additions & 0 deletions pkg/common/jobcontroller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ func GenExpectationPodsKey(jobKey, replicaType string) string {
func GenExpectationServicesKey(jobKey, replicaType string) string {
return jobKey + "/" + strings.ToLower(replicaType) + "/services"
}

// Gen PodGroupName for kube-batch, which is used for crd podGroup and annotation in pod
func GenPodGroupName(jobName string) string {
return jobName
}
3 changes: 1 addition & 2 deletions pkg/controller.v1/tensorflow/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ func (tc *TFController) createNewPod(tfjob *tfv1.TFJob, rt, index string, spec *
if podTemplate.Annotations == nil {
podTemplate.Annotations = map[string]string{}
}
// we create the podGroup with the same name as the tfjob
podTemplate.Annotations["scheduling.k8s.io/group-name"] = tfjob.Name
podTemplate.Annotations["scheduling.k8s.io/group-name"] = jobcontroller.GenPodGroupName(tfjob.Name)
}

err = tc.PodControl.CreatePodsWithControllerRef(tfjob.Namespace, podTemplate, tfjob, controllerRef)
Expand Down

0 comments on commit 960159b

Please sign in to comment.