Skip to content

Commit

Permalink
Use variable to hold fields instead of modifying controller state
Browse files Browse the repository at this point in the history
  • Loading branch information
terrytangyuan committed Jan 21, 2019
1 parent 036c760 commit e7f376a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/controllers/mpi_job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,20 @@ func (c *MPIJobController) syncHandler(key string) error {

// TODO (terrytangyuan): Remove these flags from main.go for next major release
// and update deploy/*.yaml
var gpusPerNode = c.gpusPerNode
var processingUnitsPerNode = c.processingUnitsPerNode
var processingResourceType = c.processingResourceType
if mpiJob.Spec.GPUsPerNode != nil {
c.gpusPerNode = int(*mpiJob.Spec.GPUsPerNode)
gpusPerNode = int(*mpiJob.Spec.GPUsPerNode)
}
if mpiJob.Spec.ProcessingUnitsPerNode != nil {
c.processingUnitsPerNode = int(*mpiJob.Spec.ProcessingUnitsPerNode)
processingUnitsPerNode = int(*mpiJob.Spec.ProcessingUnitsPerNode)
}
if mpiJob.Spec.ProcessingResourceType != "" {
c.processingResourceType = mpiJob.Spec.ProcessingResourceType
processingResourceType = mpiJob.Spec.ProcessingResourceType
}

workerReplicas, processingUnitsPerWorker, err := allocateProcessingUnits(mpiJob, c.gpusPerNode, c.processingUnitsPerNode, c.processingResourceType, done)
workerReplicas, processingUnitsPerWorker, err := allocateProcessingUnits(mpiJob, gpusPerNode, processingUnitsPerNode, processingResourceType, done)
if err != nil {
runtime.HandleError(err)
return nil
Expand Down Expand Up @@ -455,7 +458,7 @@ func (c *MPIJobController) syncHandler(key string) error {
}
}

worker, err := c.getOrCreateWorkerStatefulSet(mpiJob, workerReplicas, processingUnitsPerWorker, c.processingResourceType)
worker, err := c.getOrCreateWorkerStatefulSet(mpiJob, workerReplicas, processingUnitsPerWorker, processingResourceType)
if err != nil {
return err
}
Expand Down

0 comments on commit e7f376a

Please sign in to comment.