@@ -52,8 +52,9 @@ type ProjectMetadata struct {
5252type Data struct {
5353 ProjectMetadata ProjectMetadata
5454 ClusterID string
55- ImageSource string
5655 Arch string
56+ DeploymentID string
57+ ImageSource string
5758 NGFResourceCounts NGFResourceCounts
5859 NodeCount int
5960 NGFReplicaCount int
@@ -101,11 +102,21 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
101102 return Data {}, fmt .Errorf ("failed to collect NGF resource counts: %w" , err )
102103 }
103104
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 )
105111 if err != nil {
106112 return Data {}, fmt .Errorf ("failed to collect NGF replica count: %w" , err )
107113 }
108114
115+ deploymentID , err := getDeploymentID (replicaSet )
116+ if err != nil {
117+ return Data {}, fmt .Errorf ("failed to get NGF deploymentID: %w" , err )
118+ }
119+
109120 var clusterID string
110121 if clusterID , err = CollectClusterID (ctx , c .cfg .K8sClientReader ); err != nil {
111122 return Data {}, fmt .Errorf ("failed to collect clusterID: %w" , err )
@@ -118,10 +129,11 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
118129 Name : "NGF" ,
119130 Version : c .cfg .Version ,
120131 },
121- NGFReplicaCount : ngfReplicaCount ,
132+ NGFReplicaCount : replicaCount ,
122133 ClusterID : clusterID ,
123134 ImageSource : c .cfg .ImageSource ,
124135 Arch : runtime .GOARCH ,
136+ DeploymentID : deploymentID ,
125137 }
126138
127139 return data , nil
@@ -175,23 +187,27 @@ func collectGraphResourceCount(
175187 return ngfResourceCounts , nil
176188}
177189
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 ) {
179195 var pod v1.Pod
180196 if err := k8sClient .Get (
181197 ctx ,
182198 types.NamespacedName {Namespace : podNSName .Namespace , Name : podNSName .Name },
183199 & pod ,
184200 ); 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 )
186202 }
187203
188204 podOwnerRefs := pod .GetOwnerReferences ()
189205 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 ))
191207 }
192208
193209 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 )
195211 }
196212
197213 var replicaSet appsv1.ReplicaSet
@@ -200,16 +216,37 @@ func collectNGFReplicaCount(ctx context.Context, k8sClient client.Reader, podNSN
200216 types.NamespacedName {Namespace : podNSName .Namespace , Name : podOwnerRefs [0 ].Name },
201217 & replicaSet ,
202218 ); 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 )
204220 }
205221
222+ return & replicaSet , nil
223+ }
224+
225+ func getReplicas (replicaSet * appsv1.ReplicaSet ) (int , error ) {
206226 if replicaSet .Spec .Replicas == nil {
207227 return 0 , errors .New ("replica set replicas was nil" )
208228 }
209229
210230 return int (* replicaSet .Spec .Replicas ), nil
211231}
212232
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+
213250// CollectClusterID gets the UID of the kube-system namespace.
214251func CollectClusterID (ctx context.Context , k8sClient client.Reader ) (string , error ) {
215252 key := types.NamespacedName {
0 commit comments