Skip to content

Commit 9eca275

Browse files
committed
cluster: set v1beta2 Paused condition
1 parent a40e4de commit 9eca275

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

internal/controllers/cluster/cluster_controller.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import (
4949
"sigs.k8s.io/cluster-api/util/collections"
5050
"sigs.k8s.io/cluster-api/util/conditions"
5151
"sigs.k8s.io/cluster-api/util/patch"
52-
"sigs.k8s.io/cluster-api/util/predicates"
5352
)
5453

5554
const (
@@ -80,15 +79,13 @@ type Reconciler struct {
8079
}
8180

8281
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
83-
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "cluster")
8482
c, err := ctrl.NewControllerManagedBy(mgr).
8583
For(&clusterv1.Cluster{}).
8684
Watches(
8785
&clusterv1.Machine{},
8886
handler.EnqueueRequestsFromMapFunc(r.controlPlaneMachineToCluster),
8987
).
9088
WithOptions(options).
91-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
9289
Build(r)
9390

9491
if err != nil {
@@ -120,21 +117,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
120117
return ctrl.Result{}, err
121118
}
122119

123-
// Return early if the object or Cluster is paused.
124-
if annotations.IsPaused(cluster, cluster) {
125-
log.Info("Reconciliation is paused for this object")
126-
return ctrl.Result{}, nil
127-
}
128-
129120
// Initialize the patch helper.
130121
patchHelper, err := patch.NewHelper(cluster, r.Client)
131122
if err != nil {
132123
return ctrl.Result{}, err
133124
}
134125

135126
defer func() {
136-
// Always reconcile the Status.Phase field.
137-
r.reconcilePhase(ctx, cluster)
127+
if isPaused := v1beta2conditions.SetPausedCondition(cluster, cluster); !isPaused {
128+
// Always reconcile the Status.Phase field.
129+
r.reconcilePhase(ctx, cluster)
130+
}
138131

139132
// Always attempt to Patch the Cluster object and status after each reconciliation.
140133
// Patch ObservedGeneration only if the reconciliation completed successfully
@@ -147,6 +140,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
147140
}
148141
}()
149142

143+
// Return early if the object or Cluster is paused.
144+
if annotations.IsPaused(cluster, cluster) {
145+
log.Info("Reconciliation is paused for this object")
146+
return ctrl.Result{}, nil
147+
}
148+
150149
// Handle deletion reconciliation loop.
151150
if !cluster.ObjectMeta.DeletionTimestamp.IsZero() {
152151
return r.reconcileDelete(ctx, cluster)
@@ -181,6 +180,9 @@ func patchCluster(ctx context.Context, patchHelper *patch.Helper, cluster *clust
181180
clusterv1.ControlPlaneReadyCondition,
182181
clusterv1.InfrastructureReadyCondition,
183182
}},
183+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
184+
clusterv1.MachinePausedV1Beta2Condition,
185+
}},
184186
)
185187
return patchHelper.Patch(ctx, cluster, options...)
186188
}

0 commit comments

Comments
 (0)