@@ -166,6 +166,47 @@ func TestReconcileUnhealthyMachines(t *testing.T) {
166
166
g .Expect (ret .IsZero ()).To (BeTrue ()) // Remediation skipped
167
167
g .Expect (err ).ToNot (HaveOccurred ())
168
168
})
169
+ t .Run ("remediation in progress is ignored when stale" , func (t * testing.T ) {
170
+ g := NewWithT (t )
171
+
172
+ m := createMachine (ctx , g , ns .Name , "m1-unhealthy-" , withStuckRemediation (), withWaitBeforeDeleteFinalizer ())
173
+ conditions .MarkFalse (m , clusterv1 .MachineHealthCheckSucceededCondition , clusterv1 .MachineHasFailureReason , clusterv1 .ConditionSeverityWarning , "" )
174
+ conditions .MarkFalse (m , clusterv1 .MachineOwnerRemediatedCondition , clusterv1 .WaitingForRemediationReason , clusterv1 .ConditionSeverityWarning , "" )
175
+ controlPlane := & internal.ControlPlane {
176
+ KCP : & controlplanev1.KubeadmControlPlane {
177
+ ObjectMeta : metav1.ObjectMeta {
178
+ Annotations : map [string ]string {
179
+ controlplanev1 .RemediationInProgressAnnotation : MustMarshalRemediationData (& RemediationData {
180
+ Machine : "foo" ,
181
+ Timestamp : metav1.Time {Time : time .Now ().Add (- 1 * time .Hour ).UTC ()},
182
+ RetryCount : 0 ,
183
+ }),
184
+ },
185
+ },
186
+ },
187
+ Cluster : & clusterv1.Cluster {},
188
+ Machines : collections .FromMachines (m ),
189
+ }
190
+ ret , err := r .reconcileUnhealthyMachines (ctx , controlPlane )
191
+
192
+ g .Expect (ret .IsZero ()).To (BeFalse ()) // Remediation completed, requeue
193
+ g .Expect (err ).ToNot (HaveOccurred ())
194
+
195
+ g .Expect (controlPlane .KCP .Annotations ).To (HaveKey (controlplanev1 .RemediationInProgressAnnotation ))
196
+ remediationData , err := RemediationDataFromAnnotation (controlPlane .KCP .Annotations [controlplanev1 .RemediationInProgressAnnotation ])
197
+ g .Expect (err ).ToNot (HaveOccurred ())
198
+ g .Expect (remediationData .Machine ).To (Equal (m .Name ))
199
+ g .Expect (remediationData .RetryCount ).To (Equal (0 ))
200
+
201
+ assertMachineCondition (ctx , g , m , clusterv1 .MachineOwnerRemediatedCondition , corev1 .ConditionFalse , clusterv1 .RemediationInProgressReason , clusterv1 .ConditionSeverityWarning , "" )
202
+
203
+ err = env .Get (ctx , client.ObjectKey {Namespace : m .Namespace , Name : m .Name }, m )
204
+ g .Expect (err ).ToNot (HaveOccurred ())
205
+ g .Expect (m .ObjectMeta .DeletionTimestamp .IsZero ()).To (BeFalse ())
206
+
207
+ removeFinalizer (g , m )
208
+ g .Expect (env .Cleanup (ctx , m )).To (Succeed ())
209
+ })
169
210
t .Run ("reconcileUnhealthyMachines return early if the machine to be remediated is already being deleted" , func (t * testing.T ) {
170
211
g := NewWithT (t )
171
212
0 commit comments