-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathnode_poll_handler_test.go
More file actions
651 lines (622 loc) · 25.9 KB
/
node_poll_handler_test.go
File metadata and controls
651 lines (622 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
package controller
import (
"github.com/F5Networks/k8s-bigip-ctlr/v2/pkg/test"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
dynamicfake "k8s.io/client-go/dynamic/fake"
k8sfake "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/util/workqueue"
)
var _ = Describe("Node Poller Handler", func() {
var mockCtlr *mockController
BeforeEach(func() {
mockCtlr = newMockController()
mockCtlr.multiClusterHandler = NewClusterHandler("")
mockWriter := &test.MockWriter{
FailStyle: test.Success,
Sections: make(map[string]interface{}),
}
mockCtlr.RequestHandler = newMockRequestHandler(mockWriter)
go mockCtlr.multiClusterHandler.ResourceEventWatcher()
// Handles the resource status updates
go mockCtlr.multiClusterHandler.ResourceStatusUpdater()
mockCtlr.multiClusterHandler.ClusterConfigs[""] = &ClusterConfig{kubeClient: k8sfake.NewSimpleClientset()}
mockCtlr.multiClusterHandler.ClusterConfigs[""].InformerStore = initInformerStore()
mockCtlr.multiClusterResources = newMultiClusterResourceStore()
})
AfterEach(func() {
mockCtlr.shutdown()
})
It("Nodes", func() {
mockCtlr.setNodeInformer("")
mockCtlr.UseNodeInternal = true
nodeAddr1 := v1.NodeAddress{
Type: v1.NodeInternalIP,
Address: "1.2.3.4",
}
nodeAddr2 := v1.NodeAddress{
Type: v1.NodeInternalIP,
Address: "1.2.3.5",
}
nodeAddr3 := v1.NodeAddress{
Type: v1.NodeInternalIP,
Address: "1.2.3.6",
}
nodecondition := v1.NodeCondition{Type: v1.NodeReady, Status: v1.ConditionFalse}
nodeObjs := []v1.Node{
*test.NewNode("worker1", "1", false,
[]v1.NodeAddress{nodeAddr1}, nil, nil),
*test.NewNode("worker2", "1", false,
[]v1.NodeAddress{nodeAddr2}, nil, nil),
*test.NewNode("worker3", "1", false,
[]v1.NodeAddress{nodeAddr3}, nil, []v1.NodeCondition{nodecondition}),
}
for _, node := range nodeObjs {
mockCtlr.addNode(&node)
}
Expect(len(mockCtlr.multiClusterHandler.ClusterConfigs[""].nodeInformer.nodeInformer.GetIndexer().List())).To(Equal(3))
nodes, err := mockCtlr.getNodes(nodeObjs)
//verify node with NotReady state not added to node list
Expect(len(nodes)).To(Equal(2))
Expect(nodes).ToNot(BeNil(), "Failed to get nodes")
Expect(err).To(BeNil(), "Failed to get nodes")
mockCtlr.UseNodeInternal = true
nodeObjs[0].Labels = make(map[string]string)
nodeObjs[0].Labels["app"] = "test"
nodes, err = mockCtlr.getNodes(nodeObjs)
Expect(nodes).ToNot(BeNil(), "Failed to get nodes")
Expect(err).To(BeNil(), "Failed to get nodes")
mockCtlr.multiClusterHandler.ClusterConfigs[""].oldNodes = nodes
// Negative case
nodes, err = mockCtlr.getNodes([]interface{}{nodeAddr1, nodeAddr2})
Expect(nodes).To(BeNil(), "Failed to Validate nodes")
Expect(err).ToNot(BeNil(), "Failed to Validate nodes")
nodes = mockCtlr.getNodesFromCache("")
Expect(nodes).ToNot(BeNil(), "Failed to get nodes from Cache")
nodes = mockCtlr.getNodesWithLabel("app=test", "")
Expect(nodes).ToNot(BeNil(), "Failed to get Nodes with Label")
nodes = mockCtlr.getNodesWithLabel("app", "")
Expect(nodes).To(BeNil(), "Failed to Validate Nodes with Label")
})
It("Nodes Update processing", func() {
mockCtlr.Partition = "test"
cisIdentifier := mockCtlr.Partition + "_127.0.0.1"
mockCtlr.setNodeInformer("")
mockCtlr.UseNodeInternal = true
namespace := "default"
mockCtlr.multiClusterHandler.ClusterConfigs[""].namespaces = make(map[string]struct{})
mockCtlr.multiClusterHandler.ClusterConfigs[""].namespaces[namespace] = struct{}{}
mockCtlr.multiClusterHandler.customResourceSelector, _ = createLabelSelector(DefaultCustomResourceLabel)
mockCtlr.addNamespacedInformers(namespace, false, "")
mockCtlr.resourceQueue = workqueue.NewNamedRateLimitingQueue(
workqueue.DefaultControllerRateLimiter(), "custom-resource-controller")
// Static routes with Node taints
nodeAddr1 := v1.NodeAddress{
Type: v1.NodeInternalIP,
Address: "10.244.1.1",
}
nodeObjs := []v1.Node{
*test.NewNode("worker1", "1", false,
[]v1.NodeAddress{nodeAddr1}, nil, nil),
}
for _, node := range nodeObjs {
mockCtlr.addNode(&node)
}
mockCtlr.StaticRoutingMode = true
mockCtlr.SetupNodeProcessing("")
mockWriter, ok := mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// Nodes without taints, CNI flannel, no podCIDR
for i, _ := range nodeObjs {
nodeObjs[i].Spec.Taints = []v1.Taint{}
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// Nodes without taints, CNI flannel, with podCIDR, InternalNodeIP
mockCtlr.UseNodeInternal = true
for i, _ := range nodeObjs {
nodeObjs[i].Spec.PodCIDR = "10.244.0.0/28"
nodeObjs[i].Status.Addresses = []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "1.2.3.4"},
}
mockCtlr.updateStatusNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
expectedRouteSection := routeSection{
Entries: []routeConfig{
{
Name: "k8s-worker1-1.2.3.4",
Network: "10.244.0.0/28",
Gateway: "1.2.3.4",
Description: cisIdentifier,
},
},
CISIdentifier: cisIdentifier,
}
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(expectedRouteSection))
// OrchestrationCNI = OVN_K8S no OVN annotation on node
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// OrchestrationCNI = OVN_K8S with incorrect OVN annotation on node
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
for i, _ := range nodeObjs {
nodeObjs[i].Annotations = make(map[string]string)
nodeObjs[i].Annotations["k8s.ovn.org/node-subnets"] = "{\"invalid\":\"invalid\"}"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// OrchestrationCNI = OVN_K8S with correct OVN annotation k8s.ovn.org/node-subnets on node with interface but no k8s.ovn.org/node-primary-ifaddr annotation
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
for i, _ := range nodeObjs {
nodeObjs[i].Annotations = make(map[string]string)
nodeObjs[i].Annotations["k8s.ovn.org/node-subnets"] = "{\"default\":[\"10.244.0.0/28\"]}"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// OrchestrationCNI = OVN_K8S with correct OVN annotation k8s.ovn.org/node-subnets on node but no k8s.ovn.org/node-primary-ifaddr annotation
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
for i, _ := range nodeObjs {
nodeObjs[i].Annotations = make(map[string]string)
nodeObjs[i].Annotations["k8s.ovn.org/node-subnets"] = "{\"default\":\"10.244.0.0/28\"}"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// OrchestrationCNI = OVN_K8S with StaticRouteNodeCIDR and invalid OVN annotation k8s.ovn.org/host-cidrss on node but no k8s.ovn.org/node-primary-ifaddr annotation
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
mockCtlr.StaticRouteNodeCIDR = "10.244.0.0/28"
for i, _ := range nodeObjs {
nodeObjs[i].Annotations["k8s.ovn.org/host-cidrs"] = "{\"default\":\"10.244.0.0/28\"}"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// OrchestrationCNI = OVN_K8S with correct OVN annotation on node invalid k8s.ovn.org/node-primary-ifaddr annotation
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
mockCtlr.StaticRouteNodeCIDR = ""
for i, _ := range nodeObjs {
nodeObjs[i].Annotations["k8s.ovn.org/node-primary-ifaddr"] = "{\"invalid\":\"invalid\"}"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// OrchestrationCNI = OVN_K8S with correct OVN annotation on node valid k8s.ovn.org/node-primary-ifaddr annotation
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
for i, _ := range nodeObjs {
nodeObjs[i].Annotations["k8s.ovn.org/node-primary-ifaddr"] = "{\"ipv4\":\"10.244.0.0/28\"}"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
expectedRouteSection = routeSection{
Entries: []routeConfig{
{
Name: "k8s-worker1-10.244.0.0",
Network: "10.244.0.0/28",
Gateway: "10.244.0.0",
Description: cisIdentifier,
},
},
CISIdentifier: cisIdentifier,
}
Expect(mockWriter.Sections["static-routes"]).To(Equal(expectedRouteSection))
// OrchestrationCNI = ovn_k8s and invalid hostaddresses annotation
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
mockCtlr.StaticRouteNodeCIDR = "10.244.0.0/28"
for i, _ := range nodeObjs {
nodeObjs[i].Annotations["k8s.ovn.org/host-addresses"] = "{\"default\":\"10.244.0.0/28\"}"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// OrchestrationCNI = ovn_k8s and node network CIDR
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
mockCtlr.StaticRouteNodeCIDR = "10.244.0.0/28"
for i, _ := range nodeObjs {
nodeObjs[i].Annotations["k8s.ovn.org/host-addresses"] = "[\"10.244.0.0\"]"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
expectedRouteSection = routeSection{
Entries: []routeConfig{
{
Name: "k8s-worker1-10.244.0.0",
Network: "10.244.0.0/28",
Gateway: "10.244.0.0",
Description: cisIdentifier,
},
},
CISIdentifier: cisIdentifier,
}
Expect(mockWriter.Sections["static-routes"]).To(Equal(expectedRouteSection))
// set valid hostcidrs annoation
mockCtlr.OrchestrationCNI = OVN_K8S
mockCtlr.UseNodeInternal = true
mockCtlr.StaticRouteNodeCIDR = "10.244.0.0/28"
for i, _ := range nodeObjs {
delete(nodeObjs[i].Annotations, "k8s.ovn.org/host-addresses")
nodeObjs[i].Annotations["k8s.ovn.org/host-cidrs"] = "[\"10.244.0.0/28\"]"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
expectedRouteSection = routeSection{
Entries: []routeConfig{
{
Name: "k8s-worker1-10.244.0.0",
Network: "10.244.0.0/28",
Gateway: "10.244.0.0",
Description: cisIdentifier,
},
},
CISIdentifier: cisIdentifier,
}
Expect(mockWriter.Sections["static-routes"]).To(Equal(expectedRouteSection))
// OrchestrationCNI = CILIUM_K8S with no valid cilium-k8s annotation
mockCtlr.OrchestrationCNI = CILIUM_K8S
mockCtlr.UseNodeInternal = true
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(routeSection{CISIdentifier: cisIdentifier}))
// OrchestrationCNI = CILIUM_K8S with network.cilium.io/ipv4-pod-cidr annotation
mockCtlr.OrchestrationCNI = CILIUM_K8S
mockCtlr.UseNodeInternal = true
for i, _ := range nodeObjs {
nodeObjs[i].Annotations["network.cilium.io/ipv4-pod-cidr"] = "10.244.0.0/28"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
expectedRouteSection = routeSection{
Entries: []routeConfig{
{
Name: "k8s-worker1-1.2.3.4",
Network: "10.244.0.0/28",
Gateway: "1.2.3.4",
Description: cisIdentifier,
},
},
CISIdentifier: cisIdentifier,
}
Expect(mockWriter.Sections["static-routes"]).To(Equal(expectedRouteSection))
// OrchestrationCNI = CILIUM_K8S with io.cilium.network.ipv4-pod-cidr annotation
mockCtlr.OrchestrationCNI = CILIUM_K8S
mockCtlr.UseNodeInternal = true
for i, _ := range nodeObjs {
delete(nodeObjs[i].Annotations, "network.cilium.io/ipv4-pod-cidr")
nodeObjs[i].Annotations["io.cilium.network.ipv4-pod-cidr"] = "10.244.0.0/28"
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
Expect(mockWriter.Sections["static-routes"]).To(Equal(expectedRouteSection))
// OrchestrationCNI = CALICO_K8S with static routing mode
mockCtlr.OrchestrationCNI = CALICO_K8S
mockCtlr.UseNodeInternal = true
mockCtlr.StaticRoutingMode = true
// Create a fake dynamic client
scheme := runtime.NewScheme()
// Register the Calico types
scheme.AddKnownTypeWithName(
schema.GroupVersionKind{
Group: "crd.projectcalico.org",
Version: "v1",
Kind: "BlockAffinity",
},
&unstructured.Unstructured{},
)
scheme.AddKnownTypeWithName(
schema.GroupVersionKind{
Group: "crd.projectcalico.org",
Version: "v1",
Kind: "BlockAffinityList",
},
&unstructured.UnstructuredList{},
)
dynamicClient := dynamicfake.NewSimpleDynamicClient(scheme)
// Add block affinity resources to the fake dynamic client
mockCtlr.multiClusterHandler.ClusterConfigs[""].dynamicClient = dynamicClient
// Add iinformers for dynamic client
mockCtlr.newDynamicInformersForCluster(dynamicClient, "")
//Add blockaffinity objects to dynamic client
mockCtlr.addBlockAffinity("blockaffinity-1", "", "worker1", "10.244.1.0/24", dynamicClient)
mockCtlr.addBlockAffinity("blockaffinity-2", "", "worker2", "10.244.2.0/24", dynamicClient)
bacidrs := mockCtlr.GetNodePodCIDRMap()
Expect(bacidrs).To(HaveLen(2))
Expect(bacidrs[0].baName).To(Equal("blockaffinity-1"))
Expect(bacidrs[1].baName).To(Equal("blockaffinity-2"))
// Update node with internal IP
for i, _ := range nodeObjs {
// update node with calico node ip annotation
nodeObjs[i].Annotations["projectcalico.org/IPv4Address"] = "1.2.3.4"
nodeObjs[i].Status.Addresses = []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "1.2.3.4"},
}
mockCtlr.updateNode(&nodeObjs[i], namespace)
}
mockCtlr.SetupNodeProcessing("")
mockCtlr.processBlockAffinities("")
mockWriter, ok = mockCtlr.PrimaryBigIPWorker.ConfigWriter.(*test.MockWriter)
Expect(ok).To(Equal(true))
Expect(len(mockWriter.Sections)).To(Equal(1))
expectedRouteSection = routeSection{
Entries: []routeConfig{
{
Name: "k8s-blockaffinity-1",
Network: "10.244.1.0/24",
Gateway: "1.2.3.4",
Description: cisIdentifier,
},
},
CISIdentifier: cisIdentifier,
}
Expect(mockWriter.Sections["static-routes"]).To(Equal(expectedRouteSection))
mockCtlr.resourceQueue.ShutDown()
})
//TODO fix this unit testcase for new node-update logic
//Describe("Processes CIS monitored resources on node update", func() {
// BeforeEach(func() {
// namespace := ""
// mockCtlr.kubeCRClient = crdfake.NewSimpleClientset()
// mockCtlr.kubeClient = k8sfake.NewSimpleClientset()
// mockCtlr.mode = CustomResourceMode
// mockCtlr.PoolMemberType = NodePort
// mockCtlr.crInformers = make(map[string]*CRInformer)
// mockCtlr.comInformers = make(map[string]*CommonInformer)
// _ = mockCtlr.addNamespacedInformers("", false)
// mockCtlr.resources = NewResourceStore()
// mockCtlr.crInformers[""].ilInformer = cisinfv1.NewFilteredIngressLinkInformer(
// mockCtlr.kubeCRClient,
// namespace,
// 0,
// cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
// func(options *metav1.ListOptions) {
// options.LabelSelector = mockCtlr.nativeResourceSelector.String()
// },
// )
// mockCtlr.resourceQueue = workqueue.NewNamedRateLimitingQueue(
// workqueue.DefaultControllerRateLimiter(), "custom-resource-controller")
//
// })
//
// AfterEach(func() {
// mockCtlr.resourceQueue.ShutDown()
// })
//
// It("Processes IngressLinks on node update", func() {
// // Create IngressLink struct
// meta := metav1.ObjectMeta{
// Name: "il1",
// Namespace: "nginx-ingress",
// }
// typeMeta := metav1.TypeMeta{
// Kind: IngressLink,
// }
// ingressLink := &cisapiv1.IngressLink{
// ObjectMeta: meta,
// TypeMeta: typeMeta,
// Spec: cisapiv1.IngressLinkSpec{
// Host: "abc.com",
// VirtualServerAddress: "10.11.12.13",
// },
// }
// vs := &cisapiv1.VirtualServer{
// ObjectMeta: meta,
// TypeMeta: typeMeta,
// Spec: cisapiv1.VirtualServerSpec{
// Host: "abc.com",
// VirtualServerAddress: "10.11.12.13",
// },
// }
// vs.ObjectMeta.Namespace = "default"
// ts := &cisapiv1.TransportServer{
// ObjectMeta: meta,
// TypeMeta: typeMeta,
// Spec: cisapiv1.TransportServerSpec{
// Host: "abc.com",
// VirtualServerAddress: "10.11.12.13",
// },
// }
// ts.ObjectMeta.Namespace = "default"
//
// // Add ingressLink resource to informer store
// err := mockCtlr.crInformers[""].ilInformer.GetStore().Add(ingressLink)
// Expect(err).To(BeNil(), "Failed to add ingressLink resource to informer store")
//
// // Add k8s node resources
// nodeAddr1 := v1.NodeAddress{
// Type: v1.NodeInternalIP,
// Address: "1.2.3.4",
// }
// nodeAddr2 := v1.NodeAddress{
// Type: v1.NodeExternalIP,
// Address: "1.2.3.5",
// }
// nodeAddr3 := v1.NodeAddress{
// Type: v1.NodeExternalIP,
// Address: "1.2.3.6",
// }
// nodeObjs := []v1.Node{
// *test.NewNode("worker1", "1", false,
// []v1.NodeAddress{nodeAddr1}, nil),
// *test.NewNode("worker2", "1", false,
// []v1.NodeAddress{nodeAddr2}, nil),
// }
// mockCtlr.oldNodes, err = mockCtlr.getNodes(nodeObjs)
// Expect(err).To(BeNil(), "Failed to get a list of node addresses")
//
// // Add the new K8S node and verify
// nodeObjs = append(nodeObjs, *test.NewNode("worker3", "1", false,
// []v1.NodeAddress{nodeAddr3}, nil))
// tempNodeObjs := nodeObjs
//
// mockCtlr.ProcessNodeUpdate(nil, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(0))
// mockCtlr.initState = true
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(0))
// mockCtlr.ProcessNodeUpdate(nil, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(0))
// mockCtlr.initState = false
// nodeObjs = tempNodeObjs
// mockCtlr.oldNodes = nil
// // Process Node update and verify that ingressLink is added to the resource queue for processing
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(1),
// "IngressLink not added to resource queue for processing")
// key, _ := mockCtlr.resourceQueue.Get()
// rKey := key.(*rqKey)
// Expect(rKey.rscName).To(Equal(ingressLink.Name),
// "IngressLink not added to resource queue for processing")
// mockCtlr.crInformers[""].ilInformer.GetStore().Delete(ingressLink)
//
// nodeObjs = nodeObjs[:len(nodeObjs)-1]
// err = mockCtlr.crInformers[""].vsInformer.GetStore().Add(vs)
// Expect(err).To(BeNil(), "Failed to add Virtual Server resource to informer store")
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(1),
// "Virtual Server not added to resource queue for processing")
// key, _ = mockCtlr.resourceQueue.Get()
// rKey = key.(*rqKey)
// Expect(rKey.rscName).To(Equal(vs.Name), "Virtual Server not added to resource queue for processing")
// mockCtlr.crInformers[""].vsInformer.GetStore().Delete(vs)
//
// nodeObjs = nodeObjs[:len(nodeObjs)-1]
// err = mockCtlr.crInformers[""].tsInformer.GetStore().Add(ts)
// Expect(err).To(BeNil(), "Failed to add Transport Server resource to informer store")
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(1),
// "Transport Server not added to resource queue for processing")
// key, _ = mockCtlr.resourceQueue.Get()
// rKey = key.(*rqKey)
// Expect(rKey.rscName).To(Equal(ts.Name), "Transport Server not added to resource queue for processing")
// mockCtlr.crInformers[""].tsInformer.GetStore().Delete(ts)
//
// nodeObjs = tempNodeObjs
// delete(mockCtlr.crInformers, "")
// mockCtlr.namespaces = map[string]bool{"nginx-ingress": true, "default": true}
//
// mockCtlr.crInformers["default"] = mockCtlr.newNamespacedCustomResourceInformerForCluster("default")
// mockCtlr.crInformers["nginx-ingress"] = mockCtlr.newNamespacedCustomResourceInformerForCluster("nginx-ingress")
// mockCtlr.crInformers["nginx-ingress"].ilInformer.GetStore().Add(ingressLink)
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(1),
// "IngressLink not added to resource queue for processing")
// key, _ = mockCtlr.resourceQueue.Get()
// rKey = key.(*rqKey)
// Expect(rKey.rscName).To(Equal(ingressLink.Name),
// "IngressLink not added to resource queue for processing")
// mockCtlr.crInformers["nginx-ingress"].ilInformer.GetStore().Delete(ingressLink)
//
// mockCtlr.crInformers["default"].vsInformer.GetStore().Add(vs)
// nodeObjs = nodeObjs[:len(nodeObjs)-1]
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(1),
// "Virtual Server not added to resource queue for processing")
// key, _ = mockCtlr.resourceQueue.Get()
// rKey = key.(*rqKey)
// Expect(rKey.rscName).To(Equal(vs.Name), "Virtual Server not added to resource queue for processing")
// mockCtlr.crInformers["default"].vsInformer.GetStore().Delete(vs)
//
// mockCtlr.crInformers["default"].tsInformer.GetStore().Add(ts)
// nodeObjs = nodeObjs[:len(nodeObjs)-1]
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(1),
// "Transport Server not added to resource queue for processing")
// key, _ = mockCtlr.resourceQueue.Get()
// rKey = key.(*rqKey)
// Expect(rKey.rscName).To(Equal(ts.Name), "Transport Server not added to resource queue for processing")
// mockCtlr.crInformers["default"].tsInformer.GetStore().Delete(ts)
//
// mockCtlr.crInformers = make(map[string]*CRInformer)
// _ = mockCtlr.addNamespacedInformers("", false)
// mockCtlr.crInformers[""].ilInformer = cisinfv1.NewFilteredIngressLinkInformer(
// mockCtlr.kubeCRClient,
// "",
// 0,
// cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
// func(options *metav1.ListOptions) {
// options.LabelSelector = mockCtlr.nativeResourceSelector.String()
// },
// )
// nodeObjs = tempNodeObjs
// mockCtlr.PoolMemberType = NodePort
// mockCtlr.crInformers[""].ilInformer.GetStore().Add(ingressLink)
// // Delete a K8S node and verify
// nodeObjs = nodeObjs[:len(nodeObjs)-1]
// // Process Node update and verify that ingressLink is added to the resource queue for processing
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(1),
// "IngressLink not added to resource queue for processing")
// key, _ = mockCtlr.resourceQueue.Get()
// rKey = key.(*rqKey)
// Expect(rKey.rscName).To(Equal(ingressLink.Name),
// "IngressLink not added to resource queue for processing")
//
// // Verify that ingressLink isn't added to the resource queue for processing if no node is added/deleted
// // Process Node update and verify
// mockCtlr.ProcessNodeUpdate(nodeObjs, "")
// Expect(mockCtlr.resourceQueue.Len()).To(Equal(0),
// "IngressLink should not be added to resource queue for processing")
// })
//})
})