Skip to content

Commit

Permalink
patch status in reconcile instead of update
Browse files Browse the repository at this point in the history
  • Loading branch information
Maanas-23 committed Feb 18, 2025
1 parent 072ac9b commit 66c1275
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions operator/internal/controller/opsCRD.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand Down Expand Up @@ -48,11 +49,14 @@ func (r *ElastiServiceReconciler) updateCRDStatus(ctx context.Context, crdNamesp
r.Logger.Error("Failed to get ElastiService for status update", zap.String("es", crdNamespacedName.String()), zap.Error(err))
return fmt.Errorf("failed to get elastiService for status update")
}
original := es.DeepCopy()

es.Status.LastReconciledTime = metav1.Now()
es.Status.Mode = mode
if err = r.Status().Update(ctx, es); err != nil {
r.Logger.Error("Failed to update status", zap.String("es", crdNamespacedName.String()), zap.Error(err))
return fmt.Errorf("failed to update CRD status")

if err = r.Status().Patch(ctx, es, client.MergeFrom(original)); err != nil {
r.Logger.Error("Failed to patch status", zap.String("es", crdNamespacedName.String()), zap.Error(err))
return fmt.Errorf("failed to patch CRD status")
}

r.Logger.Info("CRD Status updated successfully")
Expand Down

0 comments on commit 66c1275

Please sign in to comment.