@@ -8,16 +8,6 @@ import (
88 "sigs.k8s.io/controller-runtime/pkg/client"
99)
1010
11- // AgentLabels contains the metadata information needed for reporting to Agent v3.
12- type AgentLabels struct {
13- ProductType string `json:"product-type"`
14- ProductVersion string `json:"product-version"`
15- ClusterID string `json:"cluster-id"`
16- ControlName string `json:"control-name"`
17- ControlID string `json:"control-id"`
18- ControlNamespace string `json:"control-namespace"`
19- }
20-
2111// LabelCollectorConfig holds configuration parameters for LabelCollector.
2212type LabelCollectorConfig struct {
2313 // K8sClientReader is a Kubernetes API client Reader.
@@ -42,41 +32,31 @@ func NewLabelCollector(
4232 }
4333}
4434
45- func (l * LabelCollector ) Collect (ctx context.Context ) (AgentLabels , error ) {
35+ // Collect gathers metadata labels needed for reporting to Agent v3.
36+ func (l * LabelCollector ) Collect (ctx context.Context ) (map [string ]string , error ) {
37+ agentLabels := make (map [string ]string )
38+
4639 clusterID , err := collectClusterID (ctx , l .cfg .K8sClientReader )
4740 if err != nil {
48- return AgentLabels {} , fmt .Errorf ("failed to collect cluster information: %w" , err )
41+ return nil , fmt .Errorf ("failed to collect cluster information: %w" , err )
4942 }
5043
5144 replicaSet , err := getPodReplicaSet (ctx , l .cfg .K8sClientReader , l .cfg .PodNSName )
5245 if err != nil {
53- return AgentLabels {} , fmt .Errorf ("failed to get replica set for pod %v: %w" , l .cfg .PodNSName , err )
46+ return nil , fmt .Errorf ("failed to get replica set for pod %v: %w" , l .cfg .PodNSName , err )
5447 }
5548
5649 deploymentID , err := getDeploymentID (replicaSet )
5750 if err != nil {
58- return AgentLabels {} , fmt .Errorf ("failed to get NGF deploymentID: %w" , err )
51+ return nil , fmt .Errorf ("failed to get NGF deploymentID: %w" , err )
5952 }
6053
61- agentLabels := AgentLabels {
62- ProductType : "ngf" ,
63- ProductVersion : l .cfg .Version ,
64- ClusterID : clusterID ,
65- ControlName : l .cfg .PodNSName .Name ,
66- ControlNamespace : l .cfg .PodNSName .Namespace ,
67- ControlID : deploymentID ,
68- }
54+ agentLabels ["product-type" ] = "ngf"
55+ agentLabels ["product-version" ] = l .cfg .Version
56+ agentLabels ["cluster-id" ] = clusterID
57+ agentLabels ["control-name" ] = l .cfg .PodNSName .Name
58+ agentLabels ["control-namespace" ] = l .cfg .PodNSName .Namespace
59+ agentLabels ["control-id" ] = deploymentID
6960
7061 return agentLabels , nil
7162}
72-
73- func AgentLabelsToMap (labels AgentLabels ) map [string ]string {
74- return map [string ]string {
75- "product-type" : labels .ProductType ,
76- "product-version" : labels .ProductVersion ,
77- "cluster-id" : labels .ClusterID ,
78- "control-name" : labels .ControlName ,
79- "control-namespace" : labels .ControlNamespace ,
80- "control-id" : labels .ControlID ,
81- }
82- }
0 commit comments