@@ -52,8 +52,9 @@ type ProjectMetadata struct {
52
52
type Data struct {
53
53
ProjectMetadata ProjectMetadata
54
54
ClusterID string
55
- ImageSource string
56
55
Arch string
56
+ DeploymentID string
57
+ ImageSource string
57
58
NGFResourceCounts NGFResourceCounts
58
59
NodeCount int
59
60
NGFReplicaCount int
@@ -101,11 +102,21 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
101
102
return Data {}, fmt .Errorf ("failed to collect NGF resource counts: %w" , err )
102
103
}
103
104
104
- ngfReplicaCount , err := collectNGFReplicaCount (ctx , c .cfg .K8sClientReader , c .cfg .PodNSName )
105
+ replicaSet , err := getPodReplicaSet (ctx , c .cfg .K8sClientReader , c .cfg .PodNSName )
106
+ if err != nil {
107
+ return Data {}, fmt .Errorf ("failed to get replica set for pod %s: %w" , c .cfg .PodNSName , err )
108
+ }
109
+
110
+ replicaCount , err := getReplicas (replicaSet )
105
111
if err != nil {
106
112
return Data {}, fmt .Errorf ("failed to collect NGF replica count: %w" , err )
107
113
}
108
114
115
+ deploymentID , err := getDeploymentID (replicaSet )
116
+ if err != nil {
117
+ return Data {}, fmt .Errorf ("failed to get NGF deploymentID: %w" , err )
118
+ }
119
+
109
120
var clusterID string
110
121
if clusterID , err = CollectClusterID (ctx , c .cfg .K8sClientReader ); err != nil {
111
122
return Data {}, fmt .Errorf ("failed to collect clusterID: %w" , err )
@@ -118,10 +129,11 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
118
129
Name : "NGF" ,
119
130
Version : c .cfg .Version ,
120
131
},
121
- NGFReplicaCount : ngfReplicaCount ,
132
+ NGFReplicaCount : replicaCount ,
122
133
ClusterID : clusterID ,
123
134
ImageSource : c .cfg .ImageSource ,
124
135
Arch : runtime .GOARCH ,
136
+ DeploymentID : deploymentID ,
125
137
}
126
138
127
139
return data , nil
@@ -175,23 +187,27 @@ func collectGraphResourceCount(
175
187
return ngfResourceCounts , nil
176
188
}
177
189
178
- func collectNGFReplicaCount (ctx context.Context , k8sClient client.Reader , podNSName types.NamespacedName ) (int , error ) {
190
+ func getPodReplicaSet (
191
+ ctx context.Context ,
192
+ k8sClient client.Reader ,
193
+ podNSName types.NamespacedName ,
194
+ ) (* appsv1.ReplicaSet , error ) {
179
195
var pod v1.Pod
180
196
if err := k8sClient .Get (
181
197
ctx ,
182
198
types.NamespacedName {Namespace : podNSName .Namespace , Name : podNSName .Name },
183
199
& pod ,
184
200
); err != nil {
185
- return 0 , fmt .Errorf ("failed to get NGF Pod: %w" , err )
201
+ return nil , fmt .Errorf ("failed to get NGF Pod: %w" , err )
186
202
}
187
203
188
204
podOwnerRefs := pod .GetOwnerReferences ()
189
205
if len (podOwnerRefs ) != 1 {
190
- return 0 , fmt .Errorf ("expected one owner reference of the NGF Pod, got %d" , len (podOwnerRefs ))
206
+ return nil , fmt .Errorf ("expected one owner reference of the NGF Pod, got %d" , len (podOwnerRefs ))
191
207
}
192
208
193
209
if podOwnerRefs [0 ].Kind != "ReplicaSet" {
194
- return 0 , fmt .Errorf ("expected pod owner reference to be ReplicaSet, got %s" , podOwnerRefs [0 ].Kind )
210
+ return nil , fmt .Errorf ("expected pod owner reference to be ReplicaSet, got %s" , podOwnerRefs [0 ].Kind )
195
211
}
196
212
197
213
var replicaSet appsv1.ReplicaSet
@@ -200,16 +216,37 @@ func collectNGFReplicaCount(ctx context.Context, k8sClient client.Reader, podNSN
200
216
types.NamespacedName {Namespace : podNSName .Namespace , Name : podOwnerRefs [0 ].Name },
201
217
& replicaSet ,
202
218
); err != nil {
203
- return 0 , fmt .Errorf ("failed to get NGF Pod's ReplicaSet: %w" , err )
219
+ return nil , fmt .Errorf ("failed to get NGF Pod's ReplicaSet: %w" , err )
204
220
}
205
221
222
+ return & replicaSet , nil
223
+ }
224
+
225
+ func getReplicas (replicaSet * appsv1.ReplicaSet ) (int , error ) {
206
226
if replicaSet .Spec .Replicas == nil {
207
227
return 0 , errors .New ("replica set replicas was nil" )
208
228
}
209
229
210
230
return int (* replicaSet .Spec .Replicas ), nil
211
231
}
212
232
233
+ func getDeploymentID (replicaSet * appsv1.ReplicaSet ) (string , error ) {
234
+ replicaOwnerRefs := replicaSet .GetOwnerReferences ()
235
+ if len (replicaOwnerRefs ) != 1 {
236
+ return "" , fmt .Errorf ("expected one owner reference of the NGF ReplicaSet, got %d" , len (replicaOwnerRefs ))
237
+ }
238
+
239
+ if replicaOwnerRefs [0 ].Kind != "Deployment" {
240
+ return "" , fmt .Errorf ("expected replicaSet owner reference to be Deployment, got %s" , replicaOwnerRefs [0 ].Kind )
241
+ }
242
+
243
+ if replicaOwnerRefs [0 ].UID == "" {
244
+ return "" , fmt .Errorf ("expected replicaSet owner reference to have a UID" )
245
+ }
246
+
247
+ return string (replicaOwnerRefs [0 ].UID ), nil
248
+ }
249
+
213
250
// CollectClusterID gets the UID of the kube-system namespace.
214
251
func CollectClusterID (ctx context.Context , k8sClient client.Reader ) (string , error ) {
215
252
key := types.NamespacedName {
0 commit comments