From 31876245301673878ef9c4e3ac944d37c0b327f7 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Mon, 8 Jan 2024 12:34:04 +0545 Subject: [PATCH] feat: link eks cluster node to aws::eks cluster [skip ci] --- scrapers/kubernetes/kubernetes.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/scrapers/kubernetes/kubernetes.go b/scrapers/kubernetes/kubernetes.go index 46ef91b5..19bb541f 100644 --- a/scrapers/kubernetes/kubernetes.go +++ b/scrapers/kubernetes/kubernetes.go @@ -111,6 +111,26 @@ func (kubernetes KubernetesScraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResul } } + if obj.GetKind() == "Node" { + if clusterName, ok := obj.GetLabels()["alpha.eksctl.io/cluster-name"]; ok { + if clusterScrapeResult, ok := results[0].Config.(map[string]any); ok { + clusterScrapeResult["cluster-name"] = clusterName + } + + relationships = append(relationships, v1.RelationshipResult{ + ConfigExternalID: v1.ExternalID{ + ExternalID: []string{string(obj.GetUID())}, + ConfigType: ConfigTypePrefix + "Node", + }, + RelatedExternalID: v1.ExternalID{ + ExternalID: []string{clusterName}, + ConfigType: "AWS::EKS::Cluster", + }, + Relationship: "EKSClusterNode", + }) + } + } + if obj.GetNamespace() != "" { relationships = append(relationships, v1.RelationshipResult{ ConfigExternalID: v1.ExternalID{ @@ -191,9 +211,9 @@ func (kubernetes KubernetesScraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResul accountID = extractAccountIDFromARN(mapRolesYAML) } - if v, ok := results[0].Config.(map[string]any); ok { - v["aws-auth"] = cm - v["account-id"] = accountID + if clusterScrapeResult, ok := results[0].Config.(map[string]any); ok { + clusterScrapeResult["aws-auth"] = cm + clusterScrapeResult["account-id"] = accountID } } }