Skip to content

Commit

Permalink
chore: reduce more call to get platform (#1255)
Browse files Browse the repository at this point in the history
- we have get the Release can derive info from it.

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw authored Sep 23, 2024
1 parent d73b3da commit 8d3a6c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
16 changes: 6 additions & 10 deletions controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 4 additions & 10 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8d3a6c2

Please sign in to comment.