@@ -108,11 +108,6 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
108
108
return Data {}, fmt .Errorf ("failed to collect cluster information: %w" , err )
109
109
}
110
110
111
- nodeCount , err := CollectNodeCount (ctx , c .cfg .K8sClientReader )
112
- if err != nil {
113
- return Data {}, fmt .Errorf ("failed to collect node count: %w" , err )
114
- }
115
-
116
111
graphResourceCount , err := collectGraphResourceCount (c .cfg .GraphGetter , c .cfg .ConfigurationGetter )
117
112
if err != nil {
118
113
return Data {}, fmt .Errorf ("failed to collect NGF resource counts: %w" , err )
@@ -142,7 +137,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
142
137
ClusterVersion : clusterInfo .Version ,
143
138
ClusterPlatform : clusterInfo .Platform ,
144
139
InstallationID : deploymentID ,
145
- ClusterNodeCount : int64 (nodeCount ),
140
+ ClusterNodeCount : int64 (clusterInfo . NodeCount ),
146
141
},
147
142
NGFResourceCounts : graphResourceCount ,
148
143
ImageSource : c .cfg .ImageSource ,
@@ -154,16 +149,6 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
154
149
return data , nil
155
150
}
156
151
157
- // CollectNodeCount returns the number of nodes in the cluster.
158
- func CollectNodeCount (ctx context.Context , k8sClient client.Reader ) (int , error ) {
159
- var nodes v1.NodeList
160
- if err := k8sClient .List (ctx , & nodes ); err != nil {
161
- return 0 , fmt .Errorf ("failed to get NodeList: %w" , err )
162
- }
163
-
164
- return len (nodes .Items ), nil
165
- }
166
-
167
152
func collectGraphResourceCount (
168
153
graphGetter GraphGetter ,
169
154
configurationGetter ConfigurationGetter ,
@@ -278,6 +263,7 @@ type clusterInformation struct {
278
263
Platform string
279
264
Version string
280
265
ClusterID string
266
+ NodeCount int
281
267
}
282
268
283
269
func collectClusterInformation (ctx context.Context , k8sClient client.Reader ) (clusterInformation , error ) {
@@ -287,9 +273,13 @@ func collectClusterInformation(ctx context.Context, k8sClient client.Reader) (cl
287
273
if err := k8sClient .List (ctx , & nodes ); err != nil {
288
274
return clusterInformation {}, fmt .Errorf ("failed to get NodeList: %w" , err )
289
275
}
290
- if len (nodes .Items ) == 0 {
276
+
277
+ nodeCount := len (nodes .Items )
278
+ if nodeCount == 0 {
291
279
return clusterInformation {}, errors .New ("failed to collect cluster information: NodeList length is zero" )
292
280
}
281
+ clusterInfo .NodeCount = nodeCount
282
+
293
283
node := nodes .Items [0 ]
294
284
295
285
kubeletVersion := node .Status .NodeInfo .KubeletVersion
0 commit comments