Skip to content

Commit 89303fb

Browse files
committed
Reconcile if ExcludeFromRemediation label is removed
In case ExcludeFromRemediation label is present, remediation is skipped. However if the Node is still unhealthy when the label is removed, it should be reconciled.
1 parent 9d59a03 commit 89303fb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Diff for: controllers/nodehealthcheck_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func (r *NodeHealthCheckReconciler) Reconcile(ctx context.Context, req ctrl.Requ
357357
}
358358

359359
if r.isNodeRemediationExcluded(&node) {
360-
msg := fmt.Sprintf("Skipped remediation because node %s is marked to exclude remediations", node.GetName())
360+
msg := fmt.Sprintf("Remediation skipped on node %s: node has Exclude from Remediation label", node.GetName())
361361
log.Info(msg)
362362
commonevents.WarningEvent(r.Recorder, nhc, utils.EventReasonRemediationSkipped, msg)
363363
continue

Diff for: controllers/shared.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
"github.com/go-logr/logr"
7+
commonLabels "github.com/medik8s/common/pkg/labels"
78

89
v1 "k8s.io/api/core/v1"
910
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -22,7 +23,17 @@ func nodeUpdateNeedsReconcile(ev event.UpdateEvent) bool {
2223
if newNode, ok = ev.ObjectNew.(*v1.Node); !ok {
2324
return false
2425
}
25-
return conditionsNeedReconcile(oldNode.Status.Conditions, newNode.Status.Conditions)
26+
27+
return labelsNeedsReconcile(oldNode.Labels, newNode.Labels) ||
28+
conditionsNeedReconcile(oldNode.Status.Conditions, newNode.Status.Conditions)
29+
}
30+
31+
func labelsNeedsReconcile(oldLabels, newLabels map[string]string) bool {
32+
// Check if the ExcludeFromRemediation label was added or removed
33+
_, existsInOldLabels := oldLabels[commonLabels.ExcludeFromRemediation]
34+
_, existsInNewLabels := newLabels[commonLabels.ExcludeFromRemediation]
35+
36+
return existsInOldLabels != existsInNewLabels
2637
}
2738

2839
func conditionsNeedReconcile(oldConditions, newConditions []v1.NodeCondition) bool {

0 commit comments

Comments
 (0)