From 20c6d27bf32741e429189659667a414a877593da Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 26 Jun 2024 19:26:27 +0545 Subject: [PATCH] feat: Helm direct parent --- db/update.go | 4 ---- scrapers/kubernetes/kubernetes.go | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/db/update.go b/db/update.go index 9f5aba28..e282ef11 100644 --- a/db/update.go +++ b/db/update.go @@ -730,10 +730,6 @@ func extractConfigsAndChangesFromResults(ctx api.ScrapeContext, scrapeStartTime func setConfigParents(ctx api.ScrapeContext, parentTypeToConfigMap map[configExternalKey]string, allConfigs []*models.ConfigItem) error { for _, ci := range allConfigs { - if ci.ParentID != nil { - continue // existing item. Parent is already set. - } - if len(ci.Parents) == 0 { continue // these are root items. } diff --git a/scrapers/kubernetes/kubernetes.go b/scrapers/kubernetes/kubernetes.go index 415a4eac..e2fa2f19 100644 --- a/scrapers/kubernetes/kubernetes.go +++ b/scrapers/kubernetes/kubernetes.go @@ -614,7 +614,7 @@ func getKubernetesParent(obj *unstructured.Unstructured, exclusions v1.Kubernete if obj.GetNamespace() != "" { parentExternalID := resourceIDMap[""]["Namespace"][obj.GetNamespace()] if parentExternalID == "" { - // An incremental scraper maynot have the Namespace object. + // An incremental scraper may not have the Namespace object. // We can instead use the alias as the external id. parentExternalID = getKubernetesAlias("Namespace", "", obj.GetNamespace()) } @@ -645,6 +645,23 @@ func getKubernetesParent(obj *unstructured.Unstructured, exclusions v1.Kubernete } } + helmName := obj.GetLabels()["helm.toolkit.fluxcd.io/name"] + helmNamespace := obj.GetLabels()["helm.toolkit.fluxcd.io/namespace"] + if helmName != "" && helmNamespace != "" { + allParents = append([]v1.ConfigExternalKey{{ + Type: ConfigTypePrefix + "HelmRelease", + ExternalID: getKubernetesAlias("HelmRelease", helmNamespace, helmName), + }}, allParents...) + } + + // TODO: No Namespace or the argo app uid + // if argoApp, ok := obj.GetLabels()["argocd.argoproj.io/instance"]; ok { + // allParents = append([]v1.ConfigExternalKey{{ + // Type: ConfigTypePrefix + "Application", + // ExternalID: argoApp, + // }}, allParents...) + // } + return allParents }