Skip to content

Commit

Permalink
Fix set scheduler error (#1448)
Browse files Browse the repository at this point in the history
* [fix]fix set scheduler error

Signed-off-by: bert.li <[email protected]>

* refactor gangScheduler set

Signed-off-by: bert.li <[email protected]>
  • Loading branch information
qiankunli authored Nov 4, 2021
1 parent 72e4387 commit 1a69a5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pkg/common/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ func GetReplicaTypes(specs map[commonv1.ReplicaType]*commonv1.ReplicaSpec) []com
}
return keys
}
func GetSchedulerName(replicas map[commonv1.ReplicaType]*commonv1.ReplicaSpec) string {
for _, spec := range replicas {
if len(spec.Template.Spec.SchedulerName) > 0 {
return spec.Template.Spec.SchedulerName
}
}
return ""
}
7 changes: 4 additions & 3 deletions pkg/controller.v1/tensorflow/tfjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,12 +829,13 @@ func (r *TFJobReconciler) createNewPod(tfjob *tfv1.TFJob, rt, index string, spec
// 1. if user has specified other scheduler, we report a warning without overriding any fields.
// 2. if no SchedulerName is set for pods, then we set the SchedulerName to "volcano".
if r.Config.EnableGangScheduling {
if !util.IsGangSchedulerSet(replicas, gangSchedulerName) {
podSchedulerName := util.GetSchedulerName(replicas)
if len(podSchedulerName) == 0 {
podTemplate.Spec.SchedulerName = gangSchedulerName
} else if strings.Compare(podSchedulerName, gangSchedulerName) != 0 {
errMsg := "Another scheduler is specified when gang-scheduling is enabled and it will not be overwritten"
logger.Warning(errMsg)
r.Recorder.Event(tfjob, v1.EventTypeWarning, podTemplateSchedulerNameReason, errMsg)
} else {
podTemplate.Spec.SchedulerName = gangSchedulerName
}

if podTemplate.Annotations == nil {
Expand Down

0 comments on commit 1a69a5e

Please sign in to comment.