Skip to content

Commit 76c66cb

Browse files
committed
fix: a bug
Signed-off-by: Ajay Mishra <[email protected]>
1 parent fafa719 commit 76c66cb

File tree

1 file changed

+6
-7
lines changed
  • health-monitors/kubernetes-object-monitor/pkg/controller

1 file changed

+6
-7
lines changed

health-monitors/kubernetes-object-monitor/pkg/controller/reconciler.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type ResourceReconciler struct {
3838
publisher HealthEventPublisher
3939
policies []config.Policy
4040
gvk schema.GroupVersionKind
41-
matchStates map[string]bool
41+
matchStates map[string]string
4242
matchStatesMu sync.RWMutex
4343
}
4444

@@ -55,7 +55,7 @@ func NewResourceReconciler(
5555
publisher: pub,
5656
policies: policies,
5757
gvk: gvk,
58-
matchStates: make(map[string]bool),
58+
matchStates: make(map[string]string),
5959
}
6060
}
6161

@@ -106,16 +106,15 @@ func (r *ResourceReconciler) cleanupDeletedResource(ctx context.Context, req ctr
106106
stateKey := r.getStateKey(&p, obj)
107107

108108
r.matchStatesMu.RLock()
109-
wasMatched := r.matchStates[stateKey]
109+
nodeName, wasMatched := r.matchStates[stateKey]
110110
r.matchStatesMu.RUnlock()
111111

112112
if wasMatched {
113-
nodeName := obj.GetName()
114-
115113
if err := r.publisher.PublishHealthEvent(ctx, &p, nodeName, true); err != nil {
116114
slog.Error("Failed to publish healthy event for deleted resource",
117115
"policy", p.Name,
118116
"resource", req.NamespacedName,
117+
"node", nodeName,
119118
"error", err)
120119
metrics.HealthEventsPublishErrors.WithLabelValues(p.Name, "grpc_error").Inc()
121120
}
@@ -151,7 +150,7 @@ func (r *ResourceReconciler) reconcilePolicy(
151150
stateKey := r.getStateKey(p, obj)
152151

153152
r.matchStatesMu.RLock()
154-
wasMatched := r.matchStates[stateKey]
153+
_, wasMatched := r.matchStates[stateKey]
155154
r.matchStatesMu.RUnlock()
156155

157156
if matched && !wasMatched {
@@ -177,7 +176,7 @@ func (r *ResourceReconciler) handleUnhealthyTransition(
177176
}
178177

179178
r.matchStatesMu.Lock()
180-
r.matchStates[stateKey] = true
179+
r.matchStates[stateKey] = nodeName
181180
r.matchStatesMu.Unlock()
182181

183182
metrics.PolicyMatches.WithLabelValues(p.Name, nodeName, r.gvk.Kind).Inc()

0 commit comments

Comments
 (0)