@@ -18,6 +18,9 @@ import (
18
18
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
19
19
20
20
ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1"
21
+ "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2"
22
+ "github.com/nginx/nginx-gateway-fabric/internal/framework/controller"
23
+ "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers"
21
24
"github.com/nginx/nginx-gateway-fabric/internal/framework/kinds"
22
25
"github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes/kubernetesfakes"
23
26
"github.com/nginx/nginx-gateway-fabric/internal/mode/static/config"
@@ -35,9 +38,7 @@ type listCallsFunc = func(
35
38
) error
36
39
37
40
func createListCallsFunc (objects ... client.ObjectList ) listCallsFunc {
38
- return func (_ context.Context , object client.ObjectList , option ... client.ListOption ) error {
39
- Expect (option ).To (BeEmpty ())
40
-
41
+ return func (_ context.Context , object client.ObjectList , _ ... client.ListOption ) error {
41
42
for _ , obj := range objects {
42
43
if reflect .TypeOf (obj ) == reflect .TypeOf (object ) {
43
44
reflect .ValueOf (object ).Elem ().Set (reflect .ValueOf (obj ).Elem ())
@@ -87,6 +88,7 @@ var _ = Describe("Collector", Ordered, func() {
87
88
baseListCalls listCallsFunc
88
89
flags config.Flags
89
90
nodeList * v1.NodeList
91
+ podList * v1.PodList
90
92
)
91
93
92
94
BeforeAll (func () {
@@ -155,6 +157,17 @@ var _ = Describe("Collector", Ordered, func() {
155
157
},
156
158
},
157
159
}
160
+
161
+ podList = & v1.PodList {
162
+ Items : []v1.Pod {
163
+ {
164
+ ObjectMeta : metav1.ObjectMeta {
165
+ Name : "ngf-pod-1" ,
166
+ Labels : map [string ]string {controller .AppNameLabel : "nginx-gateway-fabric" },
167
+ },
168
+ },
169
+ },
170
+ }
158
171
})
159
172
160
173
BeforeEach (func () {
@@ -170,7 +183,7 @@ var _ = Describe("Collector", Ordered, func() {
170
183
ClusterNodeCount : 1 ,
171
184
},
172
185
NGFResourceCounts : telemetry.NGFResourceCounts {},
173
- NGFReplicaCount : 1 ,
186
+ ControlPlanePodCount : 1 ,
174
187
ImageSource : "local" ,
175
188
FlagNames : flags .Names ,
176
189
FlagValues : flags .Values ,
@@ -198,7 +211,7 @@ var _ = Describe("Collector", Ordered, func() {
198
211
baseGetCalls = createGetCallsFunc (ngfPod , ngfReplicaSet , kubeNamespace )
199
212
k8sClientReader .GetCalls (baseGetCalls )
200
213
201
- baseListCalls = createListCallsFunc (nodeList )
214
+ baseListCalls = createListCallsFunc (nodeList , podList )
202
215
k8sClientReader .ListCalls (baseListCalls )
203
216
})
204
217
@@ -260,7 +273,24 @@ var _ = Describe("Collector", Ordered, func() {
260
273
},
261
274
}
262
275
263
- k8sClientReader .ListCalls (createListCallsFunc (nodes ))
276
+ podList := & v1.PodList {
277
+ Items : []v1.Pod {
278
+ {
279
+ ObjectMeta : metav1.ObjectMeta {
280
+ Name : "ngf-pod-1" ,
281
+ Labels : map [string ]string {controller .AppNameLabel : "nginx-gateway-fabric" },
282
+ },
283
+ },
284
+ {
285
+ ObjectMeta : metav1.ObjectMeta {
286
+ Name : "ngf-pod-2" ,
287
+ Labels : map [string ]string {controller .AppNameLabel : "nginx-gateway-fabric" },
288
+ },
289
+ },
290
+ },
291
+ }
292
+
293
+ k8sClientReader .ListCalls (createListCallsFunc (nodes , podList ))
264
294
265
295
secret1 := & v1.Secret {ObjectMeta : metav1.ObjectMeta {Name : "secret1" }}
266
296
secret2 := & v1.Secret {ObjectMeta : metav1.ObjectMeta {Name : "secret2" }}
@@ -270,11 +300,33 @@ var _ = Describe("Collector", Ordered, func() {
270
300
svc2 := & v1.Service {ObjectMeta : metav1.ObjectMeta {Name : "svc2" }}
271
301
nilsvc := & v1.Service {ObjectMeta : metav1.ObjectMeta {Name : "nilsvc" }}
272
302
303
+ gcNP := graph.NginxProxy {
304
+ Source : nil ,
305
+ ErrMsgs : nil ,
306
+ Valid : false ,
307
+ }
308
+
273
309
graph := & graph.Graph {
274
- GatewayClass : & graph.GatewayClass {},
310
+ GatewayClass : & graph.GatewayClass {NginxProxy : & gcNP },
275
311
Gateways : map [types.NamespacedName ]* graph.Gateway {
276
- {Name : "gateway1" }: {},
277
- {Name : "gateway2" }: {},
312
+ {Name : "gateway1" }: {
313
+ EffectiveNginxProxy : & graph.EffectiveNginxProxy {
314
+ Kubernetes : & v1alpha2.KubernetesSpec {
315
+ Deployment : & v1alpha2.DeploymentSpec {
316
+ Replicas : helpers .GetPointer (int32 (1 )),
317
+ },
318
+ },
319
+ },
320
+ },
321
+ {Name : "gateway2" }: {
322
+ EffectiveNginxProxy : & graph.EffectiveNginxProxy {
323
+ Kubernetes : & v1alpha2.KubernetesSpec {
324
+ Deployment : & v1alpha2.DeploymentSpec {
325
+ Replicas : helpers .GetPointer (int32 (3 )),
326
+ },
327
+ },
328
+ },
329
+ },
278
330
{Name : "gateway3" }: {},
279
331
},
280
332
IgnoredGatewayClasses : map [types.NamespacedName ]* gatewayv1.GatewayClass {
@@ -335,9 +387,11 @@ var _ = Describe("Collector", Ordered, func() {
335
387
}: {},
336
388
},
337
389
ReferencedNginxProxies : map [types.NamespacedName ]* graph.NginxProxy {
338
- {Namespace : "test" , Name : "NginxProxy-1" }: {},
339
- {Namespace : "test" , Name : "NginxProxy-2" }: {},
340
- }, SnippetsFilters : map [types.NamespacedName ]* graph.SnippetsFilter {
390
+ {Namespace : "test" , Name : "NginxProxy-1" }: & gcNP ,
391
+ {Namespace : "test" , Name : "NginxProxy-2" }: {Valid : true },
392
+ {Namespace : "test" , Name : "NginxProxy-3" }: {Valid : true },
393
+ },
394
+ SnippetsFilters : map [types.NamespacedName ]* graph.SnippetsFilter {
341
395
{Namespace : "test" , Name : "sf-1" }: {
342
396
Snippets : map [ngfAPI.NginxContext ]string {
343
397
ngfAPI .NginxContextMain : "worker_priority 0;" ,
@@ -432,9 +486,10 @@ var _ = Describe("Collector", Ordered, func() {
432
486
GatewayAttachedClientSettingsPolicyCount : 1 ,
433
487
RouteAttachedClientSettingsPolicyCount : 2 ,
434
488
ObservabilityPolicyCount : 1 ,
435
- NginxProxyCount : 2 ,
489
+ NginxProxyCount : 3 ,
436
490
SnippetsFilterCount : 3 ,
437
491
UpstreamSettingsPolicyCount : 1 ,
492
+ GatewayAttachedNpCount : 2 ,
438
493
}
439
494
expData .ClusterVersion = "1.29.2"
440
495
expData .ClusterPlatform = "kind"
@@ -462,6 +517,9 @@ var _ = Describe("Collector", Ordered, func() {
462
517
1 ,
463
518
}
464
519
520
+ expData .NginxPodCount = int64 (4 )
521
+ expData .ControlPlanePodCount = int64 (2 )
522
+
465
523
data , err := dataCollector .Collect (ctx )
466
524
Expect (err ).ToNot (HaveOccurred ())
467
525
@@ -527,7 +585,7 @@ var _ = Describe("Collector", Ordered, func() {
527
585
},
528
586
}
529
587
530
- k8sClientReader .ListCalls (createListCallsFunc (nodes ))
588
+ k8sClientReader .ListCalls (createListCallsFunc (nodes , podList ))
531
589
expData .ClusterVersion = "unknown"
532
590
expData .ClusterPlatform = "k3s"
533
591
@@ -543,7 +601,7 @@ var _ = Describe("Collector", Ordered, func() {
543
601
Describe ("node count collector" , func () {
544
602
When ("collecting node count data" , func () {
545
603
It ("collects correct data for one node" , func (ctx SpecContext ) {
546
- k8sClientReader .ListCalls (createListCallsFunc (nodeList ))
604
+ k8sClientReader .ListCalls (createListCallsFunc (nodeList , podList ))
547
605
548
606
expData .ClusterNodeCount = 1
549
607
@@ -593,7 +651,7 @@ var _ = Describe("Collector", Ordered, func() {
593
651
svc := & v1.Service {ObjectMeta : metav1.ObjectMeta {Name : "svc1" }}
594
652
595
653
graph1 = & graph.Graph {
596
- GatewayClass : & graph.GatewayClass {},
654
+ GatewayClass : & graph.GatewayClass {NginxProxy : & graph. NginxProxy { Valid : true } },
597
655
Gateways : map [types.NamespacedName ]* graph.Gateway {
598
656
{Name : "gateway1" }: {},
599
657
},
@@ -634,12 +692,14 @@ var _ = Describe("Collector", Ordered, func() {
634
692
}: {},
635
693
},
636
694
ReferencedNginxProxies : map [types.NamespacedName ]* graph.NginxProxy {
637
- {Namespace : "test" , Name : "NginxProxy-1" }: {},
638
- {Namespace : "test" , Name : "NginxProxy-2" }: {},
695
+ {Namespace : "test" , Name : "NginxProxy-1" }: {Valid : true },
639
696
},
640
697
SnippetsFilters : map [types.NamespacedName ]* graph.SnippetsFilter {
641
698
{Namespace : "test" , Name : "sf-1" }: {},
642
699
},
700
+ BackendTLSPolicies : map [types.NamespacedName ]* graph.BackendTLSPolicy {
701
+ {Namespace : "test" , Name : "BackendTLSPolicy-1" }: {},
702
+ },
643
703
}
644
704
645
705
config1 = []* dataplane.Configuration {
@@ -716,9 +776,11 @@ var _ = Describe("Collector", Ordered, func() {
716
776
GatewayAttachedClientSettingsPolicyCount : 1 ,
717
777
RouteAttachedClientSettingsPolicyCount : 1 ,
718
778
ObservabilityPolicyCount : 1 ,
719
- NginxProxyCount : 2 ,
779
+ NginxProxyCount : 1 ,
720
780
SnippetsFilterCount : 1 ,
721
781
UpstreamSettingsPolicyCount : 1 ,
782
+ GatewayAttachedNpCount : 1 ,
783
+ BackendTLSPolicyCount : 1 ,
722
784
}
723
785
724
786
data , err := dataCollector .Collect (ctx )
@@ -834,20 +896,6 @@ var _ = Describe("Collector", Ordered, func() {
834
896
Expect (err ).To (MatchError (expectedErr ))
835
897
})
836
898
837
- It ("should error if the replica set's replicas is nil" , func (ctx SpecContext ) {
838
- expectedErr := errors .New ("replica set replicas was nil" )
839
- k8sClientReader .GetCalls (mergeGetCallsWithBase (createGetCallsFunc (
840
- & appsv1.ReplicaSet {
841
- Spec : appsv1.ReplicaSetSpec {
842
- Replicas : nil ,
843
- },
844
- },
845
- )))
846
-
847
- _ , err := dataCollector .Collect (ctx )
848
- Expect (err ).To (MatchError (expectedErr ))
849
- })
850
-
851
899
It ("should error if the kubernetes client errored when getting the ReplicaSet" , func (ctx SpecContext ) {
852
900
expectedErr := errors .New ("there was an error getting the ReplicaSet" )
853
901
k8sClientReader .GetCalls (mergeGetCallsWithBase (
0 commit comments