Skip to content

Commit

Permalink
RHODS-12956: removing CR update from the operator reconciliation loop…
Browse files Browse the repository at this point in the history
… to avoid infinite loop (opendatahub-io#128)
  • Loading branch information
etirelli authored Nov 21, 2023
1 parent acbd9e1 commit 9851edc
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"context"
"errors"
"fmt"
"reflect"
"time"

"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/rest"
"reflect"
"time"

"github.com/go-logr/logr"
v1 "github.com/openshift/api/operator/v1"
Expand Down Expand Up @@ -168,13 +169,6 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
return ctrl.Result{}, errors.New("only one instance of DSCInitialization object is allowed")
}

// Ensure all omitted components show up as explicitly disabled
instance, err = r.updateComponents(ctx, instance)
if err != nil {
_ = r.reportError(err, instance, "error updating list of components in the CR")
return ctrl.Result{}, err
}

// Initialize error list, instead of returning errors after every component is deployed
var componentErrors *multierror.Error

Expand Down Expand Up @@ -247,6 +241,7 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context
component components.ComponentInterface,
) (*dsc.DataScienceCluster, error) {
componentName := component.GetComponentName()

enabled := component.GetManagementState() == v1.Managed
// First set conditions to reflect a component is about to be reconciled
instance, err := r.updateStatus(ctx, instance, func(saved *dsc.DataScienceCluster) {
Expand Down Expand Up @@ -354,23 +349,6 @@ func (r *DataScienceClusterReconciler) updateStatus(ctx context.Context, origina
return saved, err
}

func (r *DataScienceClusterReconciler) updateComponents(ctx context.Context, original *dsc.DataScienceCluster) (*dsc.DataScienceCluster, error) {
saved := &dsc.DataScienceCluster{}
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
err := r.Client.Get(ctx, client.ObjectKeyFromObject(original), saved)
if err != nil {
return err
}

// Try to update
err = r.Client.Update(context.TODO(), saved)
// Return err itself here (not wrapped inside another error)
// so that RetryOnConflict can identify it correctly.
return err
})
return saved, err
}

func (r *DataScienceClusterReconciler) watchDataScienceClusterResources(a client.Object) (requests []reconcile.Request) {
instanceList := &dsc.DataScienceClusterList{}
err := r.Client.List(context.TODO(), instanceList)
Expand Down

0 comments on commit 9851edc

Please sign in to comment.