Skip to content

Commit

Permalink
Implement paused condition for machine healthcheck controller
Browse files Browse the repository at this point in the history
This change updates the machine health check controller to set the paused condition
based on if the cluster or machine health check is paused.
  • Loading branch information
theobarberbany committed Apr 30, 2024
1 parent 588774b commit cac790e
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
handler.EnqueueRequestsFromMapFunc(r.machineToMachineHealthCheck),
).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
WithEventFilter(predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
Watches(
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(r.clusterToMachineHealthCheck),
builder.WithPredicates(
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.All(ctrl.LoggerFrom(ctx),
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
predicates.ClusterCreateUpdateEvent(ctrl.LoggerFrom(ctx)),
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
),
),
Expand Down Expand Up @@ -139,12 +139,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
return ctrl.Result{}, err
}

// Return early if the object or Cluster is paused.
if annotations.IsPaused(cluster, m) {
log.Info("Reconciliation is paused for this object")
return ctrl.Result{}, nil
}

// Initialize the patch helper
patchHelper, err := patch.NewHelper(m, r.Client)
if err != nil {
Expand All @@ -163,6 +157,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
}
}()

// Return early if the object or Cluster is paused.
if annotations.IsPaused(cluster, m) {
log.Info("Reconciliation is paused for this object")
conditions.MarkTrue(m, clusterv1.PausedCondition)
return ctrl.Result{}, nil
}
conditions.MarkFalse(m, clusterv1.PausedCondition, clusterv1.ResourceNotPausedReason, clusterv1.ConditionSeverityInfo, "Resource is operating as expected")

// Reconcile labels.
if m.Labels == nil {
m.Labels = make(map[string]string)
Expand Down
Loading

0 comments on commit cac790e

Please sign in to comment.