@@ -118,18 +118,12 @@ func (kubernetes KubernetesScraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResul
118118
119119var IgnoredConfigsCache = sync.Map {}
120120
121- // ExtractResults extracts scrape results from the given list of kuberenetes objects.
122- // - withCluster: if true, will create & add a scrape result for the kubernetes cluster.
123- func ExtractResults (ctx * KubernetesContext , objs []* unstructured.Unstructured ) v1.ScrapeResults {
124- var (
125- results v1.ScrapeResults
126- changeResults v1.ScrapeResults
127- )
128-
129- clusterName := ctx .config .ClusterName
121+ func getClusterAsScrapeResult (config v1.Kubernetes ) v1.ScrapeResult {
122+ clusterName := config .ClusterName
130123 extID := "Kubernetes/Cluster/" + clusterName
131- cluster := v1.ScrapeResult {
132- BaseScraper : ctx .config .BaseScraper ,
124+
125+ return v1.ScrapeResult {
126+ BaseScraper : config .BaseScraper ,
133127 Name : clusterName ,
134128 ConfigClass : "Cluster" ,
135129 Type : ConfigTypePrefix + "Cluster" ,
@@ -139,8 +133,18 @@ func ExtractResults(ctx *KubernetesContext, objs []*unstructured.Unstructured) v
139133 ConfigID : lo .ToPtr (utils .IgnoreError (utils .LegacyDeterministicUUID (extID )).String ()),
140134 Tags : map [string ]string {"cluster" : clusterName },
141135 }
136+ }
142137
143- results = append (results , cluster )
138+ // ExtractResults extracts scrape results from the given list of kuberenetes objects.
139+ // - withCluster: if true, will create & add a scrape result for the kubernetes cluster.
140+ func ExtractResults (ctx * KubernetesContext , objs []* unstructured.Unstructured ) v1.ScrapeResults {
141+ var (
142+ results v1.ScrapeResults
143+ changeResults v1.ScrapeResults
144+ )
145+
146+ ctx .cluster = getClusterAsScrapeResult (ctx .config )
147+ clusterName := ctx .config .ClusterName
144148
145149 // Initialize RBAC extractor for config access tracking
146150 var rbac * rbacExtractor
@@ -583,9 +587,7 @@ func ExtractResults(ctx *KubernetesContext, objs []*unstructured.Unstructured) v
583587 results = append (results , rbac .results (ctx .config .BaseScraper ))
584588
585589 results = append (results , changeResults ... )
586- if ctx .IsIncrementalScrape () {
587- results = append ([]v1.ScrapeResult {ctx .cluster }, results ... )
588- }
590+ results = append ([]v1.ScrapeResult {ctx .cluster }, results ... )
589591
590592 for i := range results {
591593 results [i ].Labels = collections .MergeMap (map [string ]string (results [i ].Labels ), ctx .globalLabels )
0 commit comments