From e7f376a0c89960ae8020316e58a09b0c0bbe9d28 Mon Sep 17 00:00:00 2001 From: terrytangyuan Date: Sun, 20 Jan 2019 22:03:05 -0500 Subject: [PATCH] Use variable to hold fields instead of modifying controller state --- pkg/controllers/mpi_job_controller.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/controllers/mpi_job_controller.go b/pkg/controllers/mpi_job_controller.go index b27310fd7..d12fd3f85 100644 --- a/pkg/controllers/mpi_job_controller.go +++ b/pkg/controllers/mpi_job_controller.go @@ -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 @@ -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 }