@@ -8,16 +8,6 @@ import (
8
8
"sigs.k8s.io/controller-runtime/pkg/client"
9
9
)
10
10
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
-
21
11
// LabelCollectorConfig holds configuration parameters for LabelCollector.
22
12
type LabelCollectorConfig struct {
23
13
// K8sClientReader is a Kubernetes API client Reader.
@@ -42,41 +32,31 @@ func NewLabelCollector(
42
32
}
43
33
}
44
34
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
+
46
39
clusterID , err := collectClusterID (ctx , l .cfg .K8sClientReader )
47
40
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 )
49
42
}
50
43
51
44
replicaSet , err := getPodReplicaSet (ctx , l .cfg .K8sClientReader , l .cfg .PodNSName )
52
45
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 )
54
47
}
55
48
56
49
deploymentID , err := getDeploymentID (replicaSet )
57
50
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 )
59
52
}
60
53
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
69
60
70
61
return agentLabels , nil
71
62
}
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