From e57b7c358f2f5ef0d52a9211588f061cec131dde Mon Sep 17 00:00:00 2001 From: Michal Szadkowski Date: Thu, 12 Sep 2024 15:39:00 +0200 Subject: [PATCH] Avoid making copy of runPolicy --- pkg/controller.v1/common/job.go | 4 ++-- pkg/controller.v1/common/job_test.go | 2 +- pkg/controller.v1/mpi/mpijob_controller.go | 2 +- pkg/controller.v1/paddlepaddle/paddlepaddle_controller.go | 2 +- pkg/controller.v1/pytorch/pytorchjob_controller.go | 2 +- pkg/controller.v1/tensorflow/tfjob_controller.go | 2 +- pkg/controller.v1/xgboost/xgboostjob_controller.go | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/controller.v1/common/job.go b/pkg/controller.v1/common/job.go index da67e8a6cb..ae53b4a9b7 100644 --- a/pkg/controller.v1/common/job.go +++ b/pkg/controller.v1/common/job.go @@ -456,8 +456,8 @@ func (jc *JobController) calcPGMinResources(minMember int32, replicas map[apiv1. return CalcPGMinResources(minMember, replicas, jc.PriorityClassLister.Get) } -func (jc *JobController) ManagedByExternalController(rp apiv1.RunPolicy) *string { - if controllerName := rp.ManagedBy; controllerName != nil && *controllerName != apiv1.KubeflowJobsController { +func (jc *JobController) ManagedByExternalController(controllerName *string) *string { + if controllerName != nil && *controllerName != apiv1.KubeflowJobsController { return controllerName } return nil diff --git a/pkg/controller.v1/common/job_test.go b/pkg/controller.v1/common/job_test.go index cdd34fdb19..712ff6028c 100644 --- a/pkg/controller.v1/common/job_test.go +++ b/pkg/controller.v1/common/job_test.go @@ -253,7 +253,7 @@ func TestManagedByExternalController(T *testing.T) { ManagedBy: tc.managedBy, } - if got := jobController.ManagedByExternalController(*runPolicy); got != nil { + if got := jobController.ManagedByExternalController(runPolicy.ManagedBy); got != nil { if !tc.wantResult { t.Errorf("Unwanted manager controller: %s\n", *got) } diff --git a/pkg/controller.v1/mpi/mpijob_controller.go b/pkg/controller.v1/mpi/mpijob_controller.go index 10682d0981..e59fd15d66 100644 --- a/pkg/controller.v1/mpi/mpijob_controller.go +++ b/pkg/controller.v1/mpi/mpijob_controller.go @@ -135,7 +135,7 @@ func (jc *MPIJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct return ctrl.Result{}, client.IgnoreNotFound(err) } - if manager := jc.ManagedByExternalController(mpijob.Spec.RunPolicy); manager != nil { + if manager := jc.ManagedByExternalController(mpijob.Spec.RunPolicy.ManagedBy); manager != nil { logger.Info("Skipping MPIJob managed by a custom controller", "managed-by", manager) return ctrl.Result{}, nil } diff --git a/pkg/controller.v1/paddlepaddle/paddlepaddle_controller.go b/pkg/controller.v1/paddlepaddle/paddlepaddle_controller.go index 1f3cf2230f..b453f0eb8e 100644 --- a/pkg/controller.v1/paddlepaddle/paddlepaddle_controller.go +++ b/pkg/controller.v1/paddlepaddle/paddlepaddle_controller.go @@ -131,7 +131,7 @@ func (r *PaddleJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{}, client.IgnoreNotFound(err) } - if manager := r.ManagedByExternalController(paddlejob.Spec.RunPolicy); manager != nil { + if manager := r.ManagedByExternalController(paddlejob.Spec.RunPolicy.ManagedBy); manager != nil { logger.Info("Skipping PaddleJob managed by a custom controller", "managed-by", manager) return ctrl.Result{}, nil } diff --git a/pkg/controller.v1/pytorch/pytorchjob_controller.go b/pkg/controller.v1/pytorch/pytorchjob_controller.go index 9af3e4527d..a5effc5cc5 100644 --- a/pkg/controller.v1/pytorch/pytorchjob_controller.go +++ b/pkg/controller.v1/pytorch/pytorchjob_controller.go @@ -132,7 +132,7 @@ func (r *PyTorchJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) return ctrl.Result{}, client.IgnoreNotFound(err) } - if manager := r.ManagedByExternalController(pytorchjob.Spec.RunPolicy); manager != nil { + if manager := r.ManagedByExternalController(pytorchjob.Spec.RunPolicy.ManagedBy); manager != nil { logger.Info("Skipping PyTorchJob managed by a custom controller", "managed-by", manager) return ctrl.Result{}, nil } diff --git a/pkg/controller.v1/tensorflow/tfjob_controller.go b/pkg/controller.v1/tensorflow/tfjob_controller.go index b14c33f36d..8447d02f55 100644 --- a/pkg/controller.v1/tensorflow/tfjob_controller.go +++ b/pkg/controller.v1/tensorflow/tfjob_controller.go @@ -127,7 +127,7 @@ func (r *TFJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl return ctrl.Result{}, client.IgnoreNotFound(err) } - if manager := r.ManagedByExternalController(tfjob.Spec.RunPolicy); manager != nil { + if manager := r.ManagedByExternalController(tfjob.Spec.RunPolicy.ManagedBy); manager != nil { logger.Info("Skipping TFJob managed by a custom controller", "managed-by", manager) return ctrl.Result{}, nil } diff --git a/pkg/controller.v1/xgboost/xgboostjob_controller.go b/pkg/controller.v1/xgboost/xgboostjob_controller.go index da3889ce02..4733515bbe 100644 --- a/pkg/controller.v1/xgboost/xgboostjob_controller.go +++ b/pkg/controller.v1/xgboost/xgboostjob_controller.go @@ -130,7 +130,7 @@ func (r *XGBoostJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) return ctrl.Result{}, client.IgnoreNotFound(err) } - if manager := r.ManagedByExternalController(xgboostjob.Spec.RunPolicy); manager != nil { + if manager := r.ManagedByExternalController(xgboostjob.Spec.RunPolicy.ManagedBy); manager != nil { logger.Info("Skipping XGBoostJob managed by a custom controller", "managed-by", manager) return ctrl.Result{}, nil }