From 8d3a6c24e8fe9e07602ecc7a3bd94ac428196783 Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Mon, 23 Sep 2024 12:15:14 +0200 Subject: [PATCH] chore: reduce more call to get platform (#1255) - we have get the Release can derive info from it. Signed-off-by: Wen Zhou --- .../datasciencecluster_controller.go | 16 ++++++---------- .../dscinitialization_controller.go | 14 ++++---------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/controllers/datasciencecluster/datasciencecluster_controller.go b/controllers/datasciencecluster/datasciencecluster_controller.go index 85e0b75cca0..bfb85257af2 100644 --- a/controllers/datasciencecluster/datasciencecluster_controller.go +++ b/controllers/datasciencecluster/datasciencecluster_controller.go @@ -85,19 +85,15 @@ const ( func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { //nolint:maintidx,gocyclo r.Log.Info("Reconciling DataScienceCluster resources", "Request.Name", req.Name) - // Get platform - platform, err := cluster.GetPlatform(ctx, r.Client) - if err != nil { - r.Log.Error(err, "Failed to determine platform") - return ctrl.Result{}, err - } - - // Get information on version - currentOperatorReleaseVersion, err := cluster.GetRelease(ctx, r.Client) + // Get information on version and platform + currentOperatorRelease, err := cluster.GetRelease(ctx, r.Client) if err != nil { r.Log.Error(err, "failed to get operator release version") return ctrl.Result{}, err } + // Set platform + platform := currentOperatorRelease.Name + instances := &dscv1.DataScienceClusterList{} if err := r.Client.List(ctx, instances); err != nil { @@ -235,7 +231,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R instance, err = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dscv1.DataScienceCluster) { status.SetProgressingCondition(&saved.Status.Conditions, reason, message) saved.Status.Phase = status.PhaseProgressing - saved.Status.Release = currentOperatorReleaseVersion + saved.Status.Release = currentOperatorRelease }) if err != nil { _ = r.reportError(err, instance, fmt.Sprintf("failed to add conditions to status of DataScienceCluster resource name %s", req.Name)) diff --git a/controllers/dscinitialization/dscinitialization_controller.go b/controllers/dscinitialization/dscinitialization_controller.go index a96e916d164..9c2efff2610 100644 --- a/controllers/dscinitialization/dscinitialization_controller.go +++ b/controllers/dscinitialization/dscinitialization_controller.go @@ -78,11 +78,13 @@ type DSCInitializationReconciler struct { func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { //nolint:funlen,gocyclo,maintidx r.Log.Info("Reconciling DSCInitialization.", "DSCInitialization Request.Name", req.Name) - currentOperatorReleaseVersion, err := cluster.GetRelease(ctx, r.Client) + currentOperatorRelease, err := cluster.GetRelease(ctx, r.Client) if err != nil { r.Log.Error(err, "failed to get operator release version") return ctrl.Result{}, err } + // Set platform + platform := currentOperatorRelease.Name instances := &dsciv1.DSCInitializationList{} if err := r.Client.List(ctx, instances); err != nil { @@ -142,7 +144,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re instance, err = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dsciv1.DSCInitialization) { status.SetProgressingCondition(&saved.Status.Conditions, reason, message) saved.Status.Phase = status.PhaseProgressing - saved.Status.Release = currentOperatorReleaseVersion + saved.Status.Release = currentOperatorRelease }) if err != nil { r.Log.Error(err, "Failed to add conditions to status of DSCInitialization resource.", "DSCInitialization", req.Namespace, "Request.Name", req.Name) @@ -153,14 +155,6 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re } } - // Get platform - platform, err := cluster.GetPlatform(ctx, r.Client) - if err != nil { - r.Log.Error(err, "Failed to determine platform") - - return reconcile.Result{}, err - } - // Check namespace is not exist, then create namespace := instance.Spec.ApplicationsNamespace err = r.createOdhNamespace(ctx, instance, namespace, platform)