Skip to content

Commit cac790e

Browse files
Implement paused condition for machine healthcheck controller
This change updates the machine health check controller to set the paused condition based on if the cluster or machine health check is paused.
1 parent 588774b commit cac790e

File tree

2 files changed

+135
-116
lines changed

2 files changed

+135
-116
lines changed

internal/controllers/machinehealthcheck/machinehealthcheck_controller.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
9292
handler.EnqueueRequestsFromMapFunc(r.machineToMachineHealthCheck),
9393
).
9494
WithOptions(options).
95-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
95+
WithEventFilter(predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
9696
Watches(
9797
&clusterv1.Cluster{},
9898
handler.EnqueueRequestsFromMapFunc(r.clusterToMachineHealthCheck),
9999
builder.WithPredicates(
100100
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
101101
predicates.All(ctrl.LoggerFrom(ctx),
102-
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
102+
predicates.ClusterCreateUpdateEvent(ctrl.LoggerFrom(ctx)),
103103
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
104104
),
105105
),
@@ -139,12 +139,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
139139
return ctrl.Result{}, err
140140
}
141141

142-
// Return early if the object or Cluster is paused.
143-
if annotations.IsPaused(cluster, m) {
144-
log.Info("Reconciliation is paused for this object")
145-
return ctrl.Result{}, nil
146-
}
147-
148142
// Initialize the patch helper
149143
patchHelper, err := patch.NewHelper(m, r.Client)
150144
if err != nil {
@@ -163,6 +157,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
163157
}
164158
}()
165159

160+
// Return early if the object or Cluster is paused.
161+
if annotations.IsPaused(cluster, m) {
162+
log.Info("Reconciliation is paused for this object")
163+
conditions.MarkTrue(m, clusterv1.PausedCondition)
164+
return ctrl.Result{}, nil
165+
}
166+
conditions.MarkFalse(m, clusterv1.PausedCondition, clusterv1.ResourceNotPausedReason, clusterv1.ConditionSeverityInfo, "Resource is operating as expected")
167+
166168
// Reconcile labels.
167169
if m.Labels == nil {
168170
m.Labels = make(map[string]string)

0 commit comments

Comments
 (0)