Skip to content

Commit 03e4df1

Browse files
fix: health fix for nodes in resource tree for missing state (#2606)
* fix * check added
1 parent a710c51 commit 03e4df1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

api/restHandler/AppListingRestHandler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter
725725
}
726726
}
727727
appDetail.ResourceTree = util2.InterfaceToMapAdapter(resp)
728-
handler.logger.Debugw("application environment status", "appId", appId, "envId", envId, "resp", resp)
729728
if resp.Status == string(health.HealthStatusHealthy) {
730729
err = handler.cdApplicationStatusUpdateHandler.SyncPipelineStatusForResourceTreeCall(acdAppName, appId, envId)
731730
if err != nil {

client/argocdServer/application/Application.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ func (c ServiceClientImpl) ResourceTree(ctxt context.Context, query *application
394394
if app != nil {
395395
appResp, err := app.Recv()
396396
if err == nil {
397+
// https://github.com/argoproj/argo-cd/issues/11234 workaround
398+
c.updateNodeHealthStatus(resp, appResp)
399+
397400
status = string(appResp.Application.Status.Health.Status)
398401
hash = appResp.Application.Status.Sync.Revision
399402
conditions = appResp.Application.Status.Conditions
@@ -410,6 +413,36 @@ func (c ServiceClientImpl) ResourceTree(ctxt context.Context, query *application
410413
return &ResourceTreeResponse{resp, newReplicaSets, status, hash, podMetadata, conditions}, err
411414
}
412415

416+
// fill the health status in node from app resources
417+
func (c ServiceClientImpl) updateNodeHealthStatus(resp *v1alpha1.ApplicationTree, appResp *v1alpha1.ApplicationWatchEvent) {
418+
if resp == nil || len(resp.Nodes) == 0 || appResp == nil || len(appResp.Application.Status.Resources) == 0 {
419+
return
420+
}
421+
422+
for index, node := range resp.Nodes {
423+
if node.Health != nil {
424+
continue
425+
}
426+
for _, resource := range appResp.Application.Status.Resources {
427+
if node.Group != resource.Group || node.Version != resource.Version || node.Kind != resource.Kind ||
428+
node.Name != resource.Name || node.Namespace != resource.Namespace {
429+
continue
430+
}
431+
resourceHealth := resource.Health
432+
if resourceHealth != nil {
433+
node.Health = &v1alpha1.HealthStatus{
434+
Message: resourceHealth.Message,
435+
Status: resourceHealth.Status,
436+
}
437+
// updating the element in slice
438+
// https://medium.com/@xcoulon/3-ways-to-update-elements-in-a-slice-d5df54c9b2f8
439+
resp.Nodes[index] = node
440+
}
441+
break
442+
}
443+
}
444+
}
445+
413446
func (c ServiceClientImpl) buildPodMetadata(resp *v1alpha1.ApplicationTree, responses []*Result) (podMetaData []*PodMetadata, newReplicaSets []string) {
414447
rolloutManifests := make([]map[string]interface{}, 0)
415448
statefulSetManifest := make(map[string]interface{})

0 commit comments

Comments
 (0)