argoproj / gitops-engine

Democratizing GitOps
https://pkg.go.dev/github.com/argoproj/gitops-engine?tab=subdirectories
Apache License 2.0
1.68k stars 252 forks source link

ApplicationSet UI: Tree does not show ApplicationSync status #486

Closed speedfl closed 1 year ago

speedfl commented 1 year ago

Summary

Currently when ApplicationSet is present in the tree, the generated Applications are present as well.

However the status is not displayed while for a deployment the RS and the Pod status is:

image

image

Here is a sample to test: https://github.com/speedfl/argocd-apps-of-applicationset

Motivation

It could be useful to see the status of the App (Healthy/Degraded/Unknow)

Bonus: Sync status

Proposal

While debuging UI I noticed that apps does not return the status of the Applications.

Go to Application grievances-five and sync it. Then go back on apps:

/api/v1/applications/apps/resource-tree?appNamespace=argocd

Returns without health status

...
{
    "group": "argoproj.io",
    "version": "v1alpha1",
    "kind": "Application",
    "namespace": "argocd",
    "name": "grievances-five",
    "uid": "2296e203-e5c3-4a72-a1a0-86248bdf813c",
    "parentRefs": [
        {
            "group": "argoproj.io",
            "kind": "ApplicationSet",
            "namespace": "argocd",
            "name": "grievances",
            "uid": "7bf3d8bd-6b84-49b0-966e-b780dc498502"
        }
    ],
    "resourceVersion": "3654",
    "createdAt": "2022-12-09T13:19:27Z"
}
...

Go to Application grievances-five

/api/v1/applications/grievances-five/resource-tree?appNamespace=

Returns with health status

...
{
    "version": "v1",
    "kind": "Pod",
    "namespace": "grievances",
    "name": "guestbook-ui-b848d5d9d-k7fdw",
    "uid": "cbec34c0-e2ca-4f61-8934-ea0637f11f2e",
    "parentRefs": [
        {
            "group": "apps",
            "kind": "ReplicaSet",
            "namespace": "grievances",
            "name": "guestbook-ui-b848d5d9d",
            "uid": "1e91e690-8953-42f3-8196-9dd228d82996"
        }
    ],
    "info": [
        {
            "name": "Status Reason",
            "value": "Running"
        },
        {
            "name": "Node",
            "value": "minikube"
        },
        {
            "name": "Containers",
            "value": "1/1"
        }
    ],
    "networkingInfo": {
        "labels": {
            "app": "guestbook-ui",
            "pod-template-hash": "b848d5d9d"
        }
    },
    "resourceVersion": "2660",
    "images": [
        "gcr.io/heptio-images/ks-guestbook-demo:0.2"
    ],
    "health": {
        "status": "Healthy"
    },
    "createdAt": "2022-12-09T13:27:58Z"
}
...

The issue is due to pkg/health/health.go

I tried to fix it with:

pkg/health/health.go

func GetHealthCheckFunc(gvk schema.GroupVersionKind) func(obj *unstructured.Unstructured) (*HealthStatus, error) {
    switch gvk.Group {
    ...
    case "argoproj.io":
        switch gvk.Kind {
        case "Workflow":
            return getArgoWorkflowHealth
        case "Application":
            return getArgoAppHealth
        }
        ...

pkg/health/health_argo.go

// An agnostic app object only considers Status.Phase and Status.Message. It is agnostic to the API version or any
// other fields.
type argoApp struct {
    Status struct {
        Health HealthStatus `json:"health,omitempty"`
    }
}

func getArgoAppHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
    var app argoApp
    err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &app)
    if err != nil {
        return nil, err
    }
    return &app.Status.health, nil
}

Link: https://github.com/speedfl/argocd-apps-of-applicationset/tree/feature/fix-e2e

Status seems returned in UI

ok

However I notice in Unit test that it is explicitely requested to have nil for Application: https://github.com/argoproj/gitops-engine/blob/master/pkg/health/health_test.go#L109-L112

Any reason ? Looking at all the usage in Argocd I don't see any reason why Application must be excluded

speedfl commented 1 year ago

https://argo-cd.readthedocs.io/en/stable/operator-manual/upgrading/1.7-1.8/#health-assessment-of-argoprojioapplication-crd-has-been-removed