Skip to content

Commit de3bbf5

Browse files
WIP: Implement pausing for machine controller
1 parent ccec792 commit de3bbf5

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

internal/controllers/machine/machine_controller.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
183183
m.Spec.ClusterName, m.Name, m.Namespace)
184184
}
185185

186-
// Return early if the object or Cluster is paused.
187-
if annotations.IsPaused(cluster, m) {
188-
log.Info("Reconciliation is paused for this object")
189-
return ctrl.Result{}, nil
190-
}
191-
192186
// Initialize the patch helper
193187
patchHelper, err := patch.NewHelper(m, r.Client)
194188
if err != nil {
@@ -209,6 +203,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
209203
}
210204
}()
211205

206+
// Return early and set the paused condition to True if the object or Cluster
207+
// is paused.
208+
if annotations.IsPaused(cluster, m) {
209+
log.Info("Reconciliation is paused for this object")
210+
conditions.MarkTrue(m, clusterv1.PausedCondition)
211+
return ctrl.Result{}, nil
212+
}
213+
214+
conditions.MarkFalse(m, clusterv1.PausedCondition, clusterv1.ResourceNotPausedReason, clusterv1.ConditionSeverityInfo, "Resource is operating as expected")
215+
212216
// Reconcile labels.
213217
if m.Labels == nil {
214218
m.Labels = make(map[string]string)
@@ -275,6 +279,7 @@ func patchMachine(ctx context.Context, patchHelper *patch.Helper, machine *clust
275279
clusterv1.ReadyCondition,
276280
clusterv1.BootstrapReadyCondition,
277281
clusterv1.InfrastructureReadyCondition,
282+
clusterv1.PausedCondition,
278283
clusterv1.DrainingSucceededCondition,
279284
clusterv1.MachineHealthCheckSucceededCondition,
280285
clusterv1.MachineOwnerRemediatedCondition,

internal/controllers/machine/machine_controller_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,19 @@ func TestMachineConditions(t *testing.T) {
10501050
conditions.TrueCondition(clusterv1.ReadyCondition),
10511051
},
10521052
},
1053+
{
1054+
name: "paused initialises false",
1055+
infraReady: true,
1056+
bootstrapReady: true,
1057+
beforeFunc: func(_, _ *unstructured.Unstructured, m *clusterv1.Machine) {
1058+
// since these conditions are set by an external controller
1059+
conditions.MarkTrue(m, clusterv1.MachineHealthCheckSucceededCondition)
1060+
conditions.MarkTrue(m, clusterv1.MachineOwnerRemediatedCondition)
1061+
},
1062+
conditionsToAssert: []*clusterv1.Condition{
1063+
conditions.FalseCondition(clusterv1.PausedCondition, "ResourceNotPaused", clusterv1.ConditionSeverityInfo, "Resource is operating as expected"),
1064+
},
1065+
},
10531066
{
10541067
name: "infra condition consumes reason from the infra config",
10551068
infraReady: false,
@@ -1210,6 +1223,12 @@ func TestMachineConditions(t *testing.T) {
12101223
m = &clusterv1.Machine{}
12111224
g.Expect(r.Client.Get(ctx, client.ObjectKeyFromObject(&machine), m)).ToNot(HaveOccurred())
12121225

1226+
if tt.name == "paused initialises false" {
1227+
fmt.Printf("-----------\n-----------\n\n\n\n")
1228+
fmt.Printf("machine status: %+v\n\n", m.Status)
1229+
fmt.Printf("-----------\n-----------\n\n\n\n")
1230+
}
1231+
12131232
assertConditions(t, m, tt.conditionsToAssert...)
12141233
})
12151234
}

0 commit comments

Comments
 (0)