@@ -50,6 +50,7 @@ import (
50
50
"sigs.k8s.io/cluster-api/util"
51
51
"sigs.k8s.io/cluster-api/util/annotations"
52
52
"sigs.k8s.io/cluster-api/util/conditions"
53
+ v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
53
54
"sigs.k8s.io/cluster-api/util/patch"
54
55
"sigs.k8s.io/cluster-api/util/predicates"
55
56
)
@@ -279,6 +280,13 @@ func (r *Reconciler) reconcile(ctx context.Context, logger logr.Logger, cluster
279
280
Message : message ,
280
281
})
281
282
283
+ v1beta2conditions .Set (m , metav1.Condition {
284
+ Type : clusterv1 .MachineHealthCheckRemediationAllowedV1Beta2Condition ,
285
+ Status : metav1 .ConditionFalse ,
286
+ Reason : clusterv1 .MachineHealthCheckTooManyUnhealthyV1Beta2Reason ,
287
+ Message : message ,
288
+ })
289
+
282
290
// If there are no unhealthy target, skip publishing the `RemediationRestricted` event to avoid misleading.
283
291
if len (unhealthy ) != 0 {
284
292
r .recorder .Event (
@@ -321,6 +329,12 @@ func (r *Reconciler) reconcile(ctx context.Context, logger logr.Logger, cluster
321
329
m .Status .RemediationsAllowed = remediationCount
322
330
conditions .MarkTrue (m , clusterv1 .RemediationAllowedCondition )
323
331
332
+ v1beta2conditions .Set (m , metav1.Condition {
333
+ Type : clusterv1 .MachineHealthCheckRemediationAllowedV1Beta2Condition ,
334
+ Status : metav1 .ConditionTrue ,
335
+ Reason : clusterv1 .MachineHealthCheckRemediationAllowedV1Beta2Reason ,
336
+ })
337
+
324
338
errList := r .patchUnhealthyTargets (ctx , logger , unhealthy , cluster , m )
325
339
errList = append (errList , r .patchHealthyTargets (ctx , logger , healthy , m )... )
326
340
@@ -399,6 +413,13 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg
399
413
from , err := external .Get (ctx , r .Client , m .Spec .RemediationTemplate , t .Machine .Namespace )
400
414
if err != nil {
401
415
conditions .MarkFalse (m , clusterv1 .ExternalRemediationTemplateAvailableCondition , clusterv1 .ExternalRemediationTemplateNotFoundReason , clusterv1 .ConditionSeverityError , err .Error ())
416
+
417
+ v1beta2conditions .Set (t .Machine , metav1.Condition {
418
+ Type : clusterv1 .MachineExternallyRemediatedV1Beta2Condition ,
419
+ Status : metav1 .ConditionFalse ,
420
+ Reason : clusterv1 .MachineExternallyRemediatedRemediationTemplateNotFoundV1Beta2Reason ,
421
+ Message : fmt .Sprintf ("error retrieving remediation template %s %s" , m .Spec .RemediationTemplate .Kind , klog .KRef (t .Machine .Namespace , m .Spec .RemediationTemplate .Name )),
422
+ })
402
423
errList = append (errList , errors .Wrapf (err , "error retrieving remediation template %v %q for machine %q in namespace %q within cluster %q" , m .Spec .RemediationTemplate .GroupVersionKind (), m .Spec .RemediationTemplate .Name , t .Machine .Name , t .Machine .Namespace , m .Spec .ClusterName ))
403
424
return errList
404
425
}
@@ -428,16 +449,37 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg
428
449
// Create the external clone.
429
450
if err := r .Client .Create (ctx , to ); err != nil {
430
451
conditions .MarkFalse (m , clusterv1 .ExternalRemediationRequestAvailableCondition , clusterv1 .ExternalRemediationRequestCreationFailedReason , clusterv1 .ConditionSeverityError , err .Error ())
452
+
453
+ v1beta2conditions .Set (t .Machine , metav1.Condition {
454
+ Type : clusterv1 .MachineExternallyRemediatedV1Beta2Condition ,
455
+ Status : metav1 .ConditionFalse ,
456
+ Reason : clusterv1 .MachineExternallyRemediatedRemediationRequestCreationFailedV1Beta2Reason ,
457
+ Message : "Please check controller logs for errors" ,
458
+ })
431
459
errList = append (errList , errors .Wrapf (err , "error creating remediation request for machine %q in namespace %q within cluster %q" , t .Machine .Name , t .Machine .Namespace , t .Machine .Spec .ClusterName ))
432
460
return errList
433
461
}
462
+
463
+ v1beta2conditions .Set (t .Machine , metav1.Condition {
464
+ Type : clusterv1 .MachineExternallyRemediatedV1Beta2Condition ,
465
+ Status : metav1 .ConditionFalse ,
466
+ Reason : clusterv1 .MachineExternallyRemediatedWaitingForRemediationV1Beta2Reason ,
467
+ })
434
468
} else {
435
469
logger .Info ("Target has failed health check, marking for remediation" , "target" , t .string (), "reason" , condition .Reason , "message" , condition .Message )
436
470
// NOTE: MHC is responsible for creating MachineOwnerRemediatedCondition if missing or to trigger another remediation if the previous one is completed;
437
471
// instead, if a remediation is in already progress, the remediation owner is responsible for completing the process and MHC should not overwrite the condition.
438
472
if ! conditions .Has (t .Machine , clusterv1 .MachineOwnerRemediatedCondition ) || conditions .IsTrue (t .Machine , clusterv1 .MachineOwnerRemediatedCondition ) {
439
473
conditions .MarkFalse (t .Machine , clusterv1 .MachineOwnerRemediatedCondition , clusterv1 .WaitingForRemediationReason , clusterv1 .ConditionSeverityWarning , "" )
440
474
}
475
+
476
+ if ownerRemediatedCondition := v1beta2conditions .Get (t .Machine , clusterv1 .MachineOwnerRemediatedV1Beta2Condition ); ownerRemediatedCondition == nil || ownerRemediatedCondition .Status == metav1 .ConditionTrue {
477
+ v1beta2conditions .Set (t .Machine , metav1.Condition {
478
+ Type : clusterv1 .MachineOwnerRemediatedV1Beta2Condition ,
479
+ Status : metav1 .ConditionFalse ,
480
+ Reason : clusterv1 .MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason ,
481
+ })
482
+ }
441
483
}
442
484
}
443
485
0 commit comments