@@ -14,6 +14,9 @@ import (
14
14
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph"
15
15
)
16
16
17
+ // kubeSystem indicates the name of kube-system namespace
18
+ const kubeSystem = "kube-system"
19
+
17
20
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . GraphGetter
18
21
19
22
// GraphGetter gets the latest Graph.
@@ -49,6 +52,7 @@ type ProjectMetadata struct {
49
52
// Note: this type might change once https://github.com/nginxinc/nginx-gateway-fabric/issues/1318 is implemented.
50
53
type Data struct {
51
54
ProjectMetadata ProjectMetadata
55
+ ClusterID string
52
56
NodeCount int
53
57
NGFResourceCounts NGFResourceCounts
54
58
NGFReplicaCount int
@@ -99,6 +103,11 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
99
103
return Data {}, fmt .Errorf ("failed to collect NGF replica count: %w" , err )
100
104
}
101
105
106
+ var clusterID string
107
+ if clusterID , err = collectClusterID (ctx , c .cfg .K8sClientReader ); err != nil {
108
+ return Data {}, fmt .Errorf ("failed to collect clusterID: %w" , err )
109
+ }
110
+
102
111
data := Data {
103
112
NodeCount : nodeCount ,
104
113
NGFResourceCounts : graphResourceCount ,
@@ -107,6 +116,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
107
116
Version : c .cfg .Version ,
108
117
},
109
118
NGFReplicaCount : ngfReplicaCount ,
119
+ ClusterID : clusterID ,
110
120
}
111
121
112
122
return data , nil
@@ -193,3 +203,15 @@ func collectNGFReplicaCount(ctx context.Context, k8sClient client.Reader, podNSN
193
203
194
204
return int (* replicaSet .Spec .Replicas ), nil
195
205
}
206
+
207
+ func collectClusterID (ctx context.Context , k8sClient client.Reader ) (string , error ) {
208
+ key := types.NamespacedName {
209
+ Name : kubeSystem ,
210
+ }
211
+ var kubeNamespace v1.Namespace
212
+ err := k8sClient .Get (ctx , key , & kubeNamespace )
213
+ if err != nil {
214
+ return "" , fmt .Errorf ("failed to get namespace :%w" , err )
215
+ }
216
+ return string (kubeNamespace .GetUID ()), nil
217
+ }
0 commit comments