tohjustin / kube-lineage

A CLI tool to display all dependencies or dependents of an object in a Kubernetes cluster.
Apache License 2.0
392 stars 24 forks source link

Support getting lineage for ArgoCD Applications #18

Open anandf opened 2 weeks ago

anandf commented 2 weeks ago

This is a wonderful and promising tool.

I have seen a note that currently it does not support ArgoCD Applications. When I tried running on it, I could just see the events generated by these applications instead of the actual child objects. I would like to enhance this tool to add support for ArgoCD applications as well.

argocd app create guestbook --core --repo https://github.com/anandf/argocd-example-apps.git --path kustomize-guestbook --dest-namespace guestbook --dest-server https://kubernetes.default.svc --sync-policy automated --self-heal --sync-option CreateNamespace=true
application 'guestbook' created
argocd app list --core
NAME              CLUSTER                         NAMESPACE  PROJECT  STATUS  HEALTH       SYNCPOLICY  CONDITIONS  REPO                                               PATH                 TARGET
argocd/guestbook  https://kubernetes.default.svc  guestbook  default  Synced  Progressing  Auto        <none>      https://github.com/anandf/argocd-example-apps.git  kustomize-guestbook

On running lineage command, I get this output

 k lineage application guestbook
NAME                                   READY   STATUS                                                                                     AGE
Application/guestbook                  -                                                                                                  26s
├── Event/guestbook.17f5a5a5b1bdf768   -       ResourceCreated: Unknown user created application                                          26s
├── Event/guestbook.17f5a5a5fa724984   -       OperationStarted: Initiated automated sync to 'd7927a27b4533926b7d86b5f249cd9ebe7625e90'   25s
├── Event/guestbook.17f5a5a5fa90d1f4   -       ResourceUpdated: Updated sync status:  -> OutOfSync                                        25s
├── Event/guestbook.17f5a5a5fabf4424   -       ResourceUpdated: Updated health status:  -> Missing                                        25s
├── Event/guestbook.17f5a5a67f31db2d   -       ResourceUpdated: Updated sync status: OutOfSync -> Synced                                  23s
├── Event/guestbook.17f5a5a67f483a16   -       OperationCompleted: Sync operation to d7927a27b4533926b7d86b5f249cd9ebe7625e90 succeeded   23s
└── Event/guestbook.17f5a5a67f551fb2   -       ResourceUpdated: Updated health status: Missing -> Progressing                             23s

Expected Output

|- Namespace/guestbook   -                8m45s
|- Deployment/kustomize-guestbook-ui                                           0/1                                                                                                                 5m44s
 └── ReplicaSet/kustomize-guestbook-ui-9b9c89b69                             0/1                                                                                                                 5m44s
    └── Pod/kustomize-guestbook-ui-9b9c89b69-qnr66                          0/1     ContainerCreating                                                                                           5m44s                                                                                                        5m44s
|- Service/kustomize-guestbook-ui                   -                7m36s
└── EndpointSlice/kustomize-guestbook-ui-b5xbb   -                7m36s
tohjustin commented 1 week ago

@anandf this is a great idea 😊

I suppose it's just matching Argo CD Application/<APP_NAME> custom resource with other k8s resources containing the argocd.argoproj.io/instance=<APP_NAME> label?

tohjustin commented 1 week ago

I haven't had much time these while to do maintenance on this tool, but do feel free to work on this & I'll do my best to review it & publish a version 🙏

anandf commented 1 week ago

ArgoCD uses either a label app.kubernetes.io/instance: some-application (or) an annotation argocd.argoproj.io/tracking-id (or) both to track application created resources. There is also an option to specify a custom label. Once the direct resources are identified, we need to track its individual children using existing logic. Custom label selector can be supported by having an additional optional argument for the lineage command

tohjustin commented 1 week ago

I see, thanks for sharing this! Would greatly appreciate if you can also update over here when you've started working on this 🙏