@@ -102,11 +102,21 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
102102 return Data {}, fmt .Errorf ("failed to collect NGF resource counts: %w" , err )
103103 }
104104
105- ngfReplicaCount , deploymentID , err := collectNGFReplicaData (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 collect pod/replica set: %w" , err )
108+ }
109+
110+ replicaCount , err := getReplicas (replicaSet )
106111 if err != nil {
107112 return Data {}, fmt .Errorf ("failed to collect NGF replica count: %w" , err )
108113 }
109114
115+ deploymentID , err := getDeploymentID (replicaSet )
116+ if err != nil {
117+ return Data {}, fmt .Errorf ("failed to get NGF deploymentID: %w" , err )
118+ }
119+
110120 var clusterID string
111121 if clusterID , err = CollectClusterID (ctx , c .cfg .K8sClientReader ); err != nil {
112122 return Data {}, fmt .Errorf ("failed to collect clusterID: %w" , err )
@@ -119,7 +129,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
119129 Name : "NGF" ,
120130 Version : c .cfg .Version ,
121131 },
122- NGFReplicaCount : ngfReplicaCount ,
132+ NGFReplicaCount : replicaCount ,
123133 ClusterID : clusterID ,
124134 ImageSource : c .cfg .ImageSource ,
125135 Arch : runtime .GOARCH ,
@@ -177,31 +187,27 @@ func collectGraphResourceCount(
177187 return ngfResourceCounts , nil
178188}
179189
180- func collectNGFReplicaData (
190+ func getPodReplicaSet (
181191 ctx context.Context ,
182192 k8sClient client.Reader ,
183193 podNSName types.NamespacedName ,
184- ) (int , string , error ) {
194+ ) (* appsv1. ReplicaSet , error ) {
185195 var pod v1.Pod
186196 if err := k8sClient .Get (
187197 ctx ,
188198 types.NamespacedName {Namespace : podNSName .Namespace , Name : podNSName .Name },
189199 & pod ,
190200 ); err != nil {
191- return 0 , "" , fmt .Errorf ("failed to get NGF Pod: %w" , err )
201+ return nil , fmt .Errorf ("failed to get NGF Pod: %w" , err )
192202 }
193203
194204 podOwnerRefs := pod .GetOwnerReferences ()
195205 if len (podOwnerRefs ) != 1 {
196- 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 ))
197207 }
198208
199209 if podOwnerRefs [0 ].Kind != "ReplicaSet" {
200- return 0 , "" , fmt .Errorf ("expected pod owner reference to be ReplicaSet, got %s" , podOwnerRefs [0 ].Kind )
201- }
202-
203- if podOwnerRefs [0 ].UID == "" {
204- return 0 , "" , fmt .Errorf ("expected pod owner reference to have a UID: %v" , podOwnerRefs [0 ])
210+ return nil , fmt .Errorf ("expected pod owner reference to be ReplicaSet, got %s" , podOwnerRefs [0 ].Kind )
205211 }
206212
207213 var replicaSet appsv1.ReplicaSet
@@ -210,14 +216,26 @@ func collectNGFReplicaData(
210216 types.NamespacedName {Namespace : podNSName .Namespace , Name : podOwnerRefs [0 ].Name },
211217 & replicaSet ,
212218 ); err != nil {
213- 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 )
214220 }
215221
222+ return & replicaSet , nil
223+ }
224+
225+ func getReplicas (replicaSet * appsv1.ReplicaSet ) (int , error ) {
216226 if replicaSet .Spec .Replicas == nil {
217- return 0 , "" , errors .New ("replica set replicas was nil" )
227+ return 0 , errors .New ("replica set replicas was nil" )
228+ }
229+
230+ return int (* replicaSet .Spec .Replicas ), nil
231+ }
232+
233+ func getDeploymentID (replicaSet * appsv1.ReplicaSet ) (string , error ) {
234+ if replicaSet .GetUID () == "" {
235+ return "" , fmt .Errorf ("expected replicaSet to have a UID" )
218236 }
219237
220- return int ( * replicaSet .Spec . Replicas ), string ( podOwnerRefs [ 0 ]. UID ), nil
238+ return string ( replicaSet .GetUID () ), nil
221239}
222240
223241// CollectClusterID gets the UID of the kube-system namespace.
0 commit comments