Skip to content

Commit

Permalink
fix: update release version in DSCI and DSC .status for upgrade case (o…
Browse files Browse the repository at this point in the history
…pendatahub-io#1287)

- DSCI: if current version is not matching, update it
- DSC: in both reconcile pass and fail case, update it

Signed-off-by: Wen Zhou <wenzhou@redhat.com>
(cherry picked from commit 59cade9)
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw committed Oct 10, 2024
1 parent b0dcf4e commit 5a583cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
r.Log.Info("Reconciling DataScienceCluster resources", "Request.Name", req.Name)

// Get information on version
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
Expand Down Expand Up @@ -227,7 +227,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 All @@ -251,6 +251,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
status.SetCompleteCondition(&saved.Status.Conditions, status.ReconcileCompletedWithComponentErrors,
fmt.Sprintf("DataScienceCluster resource reconciled with component errors: %v", componentErrors))
saved.Status.Phase = status.PhaseReady
saved.Status.Release = currentOperatorRelease
})
if err != nil {
r.Log.Error(err, "failed to update DataScienceCluster conditions with incompleted reconciliation")
Expand All @@ -265,6 +266,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
instance, err = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dscv1.DataScienceCluster) {
status.SetCompleteCondition(&saved.Status.Conditions, status.ReconcileCompleted, "DataScienceCluster resource reconciled successfully")
saved.Status.Phase = status.PhaseReady
saved.Status.Release = currentOperatorRelease
})

if err != nil {
Expand Down
18 changes: 16 additions & 2 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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
Expand Down Expand Up @@ -141,7 +141,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 @@ -151,6 +151,20 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
}
}

// upgrade case to update release version in status
if !instance.Status.Release.Version.Equals(currentOperatorRelease.Version.Version) {
message := "Updating DSCInitialization status"
instance, err := status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dsciv1.DSCInitialization) {
saved.Status.Release = currentOperatorRelease
})
if err != nil {
r.Log.Error(err, "Failed to update release version for DSCInitialization resource.", "DSCInitialization", req.Namespace, "Request.Name", req.Name)
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "DSCInitializationReconcileError",
"%s for instance %s", message, instance.Name)
return reconcile.Result{}, err
}
}

// Check namespace is not exist, then create
namespace := instance.Spec.ApplicationsNamespace
err = r.createOdhNamespace(ctx, instance, namespace)
Expand Down

0 comments on commit 5a583cc

Please sign in to comment.