Skip to content
This repository was archived by the owner on Jul 5, 2025. It is now read-only.

Commit a654124

Browse files
committed
feat(controller): add read-only mode to LifecycleManager
1 parent a143444 commit a654124

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

controller/lifecycle/lifecycle.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type LifecycleManager struct {
3535
controllerName string
3636
spreadReconciles bool
3737
manageConditions bool
38+
readOnly bool
3839
prepareContextFunc PrepareContextFunc
3940
}
4041

@@ -154,7 +155,9 @@ func (l *LifecycleManager) Reconcile(ctx context.Context, req ctrl.Request, inst
154155
if !retry {
155156
l.markResourceAsFinal(instance, log, conditions, v1.ConditionFalse)
156157
}
157-
_ = updateStatus(ctx, l.client, originalCopy, instance, log, generationChanged, sentryTags)
158+
if !l.readOnly {
159+
_ = updateStatus(ctx, l.client, originalCopy, instance, log, generationChanged, sentryTags)
160+
}
158161
if !retry {
159162
return ctrl.Result{}, nil
160163
}
@@ -188,9 +191,11 @@ func (l *LifecycleManager) Reconcile(ctx context.Context, req ctrl.Request, inst
188191
MustToRuntimeObjectConditionsInterface(instance, log).SetConditions(conditions)
189192
}
190193

191-
err = updateStatus(ctx, l.client, originalCopy, instance, log, generationChanged, sentryTags)
192-
if err != nil {
193-
return result, err
194+
if !l.readOnly {
195+
err = updateStatus(ctx, l.client, originalCopy, instance, log, generationChanged, sentryTags)
196+
if err != nil {
197+
return result, err
198+
}
194199
}
195200

196201
if l.spreadReconciles && instance.GetDeletionTimestamp().IsZero() {
@@ -352,6 +357,10 @@ func (l *LifecycleManager) reconcileSubroutine(ctx context.Context, instance Run
352357
}
353358

354359
func (l *LifecycleManager) addFinalizersIfNeeded(ctx context.Context, instance RuntimeObject) error {
360+
if l.readOnly {
361+
return nil
362+
}
363+
355364
if !instance.GetDeletionTimestamp().IsZero() {
356365
return nil
357366
}
@@ -386,6 +395,10 @@ func (l *LifecycleManager) addFinalizerIfNeeded(instance RuntimeObject, subrouti
386395
}
387396

388397
func (l *LifecycleManager) removeFinalizerIfNeeded(ctx context.Context, instance RuntimeObject, subroutine Subroutine, result ctrl.Result) errors.OperatorError {
398+
if l.readOnly {
399+
return nil
400+
}
401+
389402
if !result.Requeue && result.RequeueAfter == 0 {
390403
update := false
391404
for _, f := range subroutine.Finalizers() {
@@ -436,3 +449,10 @@ func (l *LifecycleManager) WithPrepareContextFunc(prepareFunction PrepareContext
436449
l.prepareContextFunc = prepareFunction
437450
return l
438451
}
452+
453+
// WithReadOnly allows to set the controller to read-only mode
454+
// In read-only mode, the controller will not update the status of the instance
455+
func (l *LifecycleManager) WithReadOnly() *LifecycleManager {
456+
l.readOnly = true
457+
return l
458+
}

0 commit comments

Comments
 (0)