Skip to content

Commit 3b953f5

Browse files
zhujian7claude
authored andcommitted
Refactor health check probe result handling
Simplify the probe result collection logic by: - Collecting all probe results upfront, regardless of healthChecker - Checking for empty results based on FieldResults length - Removing unnecessary tracking of empty probe fields - Updating test expectations for multi-probe scenarios This makes the code cleaner and maintains the fix for supporting partial probe results with multi-probe configurations. Signed-off-by: Jia Zhu <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]>
1 parent 92c8e89 commit 3b953f5

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

pkg/addonmanager/controllers/agentdeploy/healthcheck_sync.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,19 @@ func (s *healthCheckSyncer) probeAddonStatusByWorks(
187187
return err
188188
}
189189

190-
var FieldResults []agent.FieldResult
191-
var emptyProbeFields []workapiv1.ResourceIdentifier
190+
var fieldResults []agent.FieldResult
192191

193192
for _, field := range probeFields {
194193
results := findResultsByIdentifier(field.ResourceIdentifier, manifestConditions)
195194
// if no results are returned. it is possible that work agent has not returned the feedback value.
196195
// collect these fields and check if all probes are empty later
197196
if len(results) == 0 {
198-
emptyProbeFields = append(emptyProbeFields, field.ResourceIdentifier)
199197
continue
200198
}
201199

200+
fieldResults = append(fieldResults, results...)
202201
// healthCheck will be ignored if healthChecker is set
203202
if healthChecker != nil {
204-
FieldResults = append(FieldResults, results...)
205203
continue
206204
}
207205

@@ -231,29 +229,21 @@ func (s *healthCheckSyncer) probeAddonStatusByWorks(
231229
}
232230

233231
// If all probe fields have no results, mark condition to unknown
234-
if len(emptyProbeFields) == len(probeFields) && len(probeFields) > 0 {
235-
var msg string
236-
if len(emptyProbeFields) == 1 {
237-
msg = fmt.Sprintf("Probe results are not returned for %s/%s: %s/%s",
238-
emptyProbeFields[0].Group, emptyProbeFields[0].Resource,
239-
emptyProbeFields[0].Namespace, emptyProbeFields[0].Name)
240-
} else {
241-
msg = fmt.Sprintf("Probe results are not returned for %d probe fields", len(emptyProbeFields))
242-
}
232+
if len(probeFields) > 0 && len(fieldResults) == 0 {
243233
meta.SetStatusCondition(&addon.Status.Conditions, metav1.Condition{
244234
Type: addonapiv1alpha1.ManagedClusterAddOnConditionAvailable,
245235
Status: metav1.ConditionUnknown,
246236
Reason: addonapiv1alpha1.AddonAvailableReasonNoProbeResult,
247-
Message: msg,
237+
Message: "Probe results are not returned",
248238
})
249239
return nil
250240
}
251241

252-
// If we have FieldResults but some probes are empty, still proceed with healthChecker
242+
// If we have fieldResults but some probes are empty, still proceed with healthChecker
253243
// This allows partial probe results to be considered valid
254244

255245
if healthChecker != nil {
256-
if err := healthChecker(FieldResults, cluster, addon); err != nil {
246+
if err := healthChecker(fieldResults, cluster, addon); err != nil {
257247
meta.SetStatusCondition(&addon.Status.Conditions, metav1.Condition{
258248
Type: addonapiv1alpha1.ManagedClusterAddOnConditionAvailable,
259249
Status: metav1.ConditionFalse,

test/integration/kube/agent_deploy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,8 @@ var _ = ginkgo.Describe("Agent deploy", func() {
922922
return err
923923
}
924924

925-
// the daemonset is not probed, so the addon available condition is unknown
926-
if !meta.IsStatusConditionPresentAndEqual(addon.Status.Conditions, "Available", metav1.ConditionUnknown) {
925+
// the daemonset is not probed, so the addon available condition is false
926+
if !meta.IsStatusConditionPresentAndEqual(addon.Status.Conditions, "Available", metav1.ConditionFalse) {
927927
return fmt.Errorf("Unexpected addon available condition, %v", addon.Status.Conditions)
928928
}
929929
return nil

0 commit comments

Comments
 (0)