-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
2026 lines (1736 loc) · 85.3 KB
/
Copy pathintegration_test.go
File metadata and controls
2026 lines (1736 loc) · 85.3 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
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package controllers_test
import (
"fmt"
"time"
v2 "github.com/metal-stack/firewall-controller-manager/api/v2"
"github.com/metal-stack/firewall-controller-manager/api/v2/defaults"
"github.com/metal-stack/metal-lib/httperrors"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/mock"
"sigs.k8s.io/controller-runtime/pkg/client"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testcommon "github.com/metal-stack/firewall-controller-manager/integration/common"
metalfirewall "github.com/metal-stack/metal-go/api/client/firewall"
"github.com/metal-stack/metal-go/api/client/image"
"github.com/metal-stack/metal-go/api/client/machine"
"github.com/metal-stack/metal-go/api/client/network"
"github.com/metal-stack/metal-go/api/models"
metalclient "github.com/metal-stack/metal-go/test/client"
)
var (
interval = 200 * time.Millisecond
namespace = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespaceName,
},
}
sshSecret = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "ssh-secret",
Namespace: namespaceName,
},
StringData: map[string]string{
"id_rsa": "private",
"id_rsa.pub": "public",
},
}
genericKubeconfigSecret = func(apiCA, apiHost, apiCert, apiKey string) *corev1.Secret {
return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "kubeconfig-secret-name",
Namespace: namespaceName,
},
Data: map[string][]byte{
"kubeconfig": fmt.Appendf(nil, `apiVersion: v1
clusters:
- cluster:
certificate-authority-data: %s
server: %s
name: shoot-name
contexts:
- context:
cluster: shoot-name
user: shoot-name
name: shoot-name
current-context: shoot-name
kind: Config
preferences: {}
users:
- name: shoot-name
user:
client-certificate-data: %s
client-key-data: %s
`, apiCA, apiHost, apiCert, apiKey)},
}
}
shootTokenSecret = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "token",
Namespace: namespaceName,
},
Data: map[string][]byte{
"token": []byte(`eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.NHVaYe26MbtOYhSKkoKYdFVomg4i8ZJd8_-RU8VNbftc4TSMb4bXP3l3YlNWACwyXPGffz5aXHc6lty1Y2t4SWRqGteragsVdZufDn5BlnJl9pdR_kdVFUsra2rWKEofkZeIC4yWytE58sMIihvo9H1ScmmVwBcQP6XETqYd0aSHp1gOa9RdUPDvoXQ5oqygTqVtxaDr6wUFKrKItgBMzWIdNZ6y7O9E0DhEPTbE9rfBo6KTFsHAZnMg4k68CDp2woYIaXbmYTWcvbzIuHO7_37GT79XdIwkm95QJ7hYC9RiwrV7mesbY4PAahERJawntho0my942XheVLmGwLMBkQ`),
},
}
// we need to fake the secret as there is no kube-controller-manager in the
// envtest setup which can issue a long-lived token for the secret
fakeTokenSecretSeed = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "firewall-controller-seed-access-test",
Namespace: namespaceName,
Annotations: map[string]string{
"kubernetes.io/service-account.name": "firewall-controller-seed-access-test",
},
},
StringData: map[string]string{
"token": "a-token",
"ca.crt": "ca-crt",
},
Type: corev1.SecretTypeServiceAccountToken,
}
fakeTokenSecretShoot = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "firewall-controller-shoot-access-test",
Namespace: namespaceName,
Annotations: map[string]string{
"kubernetes.io/service-account.name": "firewall-controller-shoot-access-test",
},
},
StringData: map[string]string{
"token": "a-token",
"ca.crt": "ca-crt",
},
Type: corev1.SecretTypeServiceAccountToken,
}
)
var _ = Context("integration test", Ordered, func() {
var (
deployment = func() *v2.FirewallDeployment {
return &v2.FirewallDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespaceName,
},
Spec: v2.FirewallDeploymentSpec{
Replicas: 1,
Template: v2.FirewallTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"purpose": "shoot-firewall",
},
},
Spec: v2.FirewallSpec{
Size: "n1-medium-x86",
Project: "project-a",
Partition: "partition-a",
Image: "firewall-ubuntu-2.0",
Networks: []string{"internet"},
ControllerURL: "http://controller.tar.gz",
ControllerVersion: "v2.0.0",
NftablesExporterURL: "http://exporter.tar.gz",
NftablesExporterVersion: "v1.0.0",
Interval: defaults.DefaultFirewallReconcileInterval,
},
},
},
}
}
)
BeforeAll(func() {
Expect(client.IgnoreAlreadyExists(k8sClient.Create(ctx, namespace.DeepCopy()))).To(Succeed())
Expect(client.IgnoreAlreadyExists(k8sClient.Create(ctx, fakeTokenSecretSeed.DeepCopy()))).To(Succeed())
Expect(client.IgnoreAlreadyExists(k8sClient.Create(ctx, fakeTokenSecretShoot.DeepCopy()))).To(Succeed())
Expect(client.IgnoreAlreadyExists(k8sClient.Create(ctx, sshSecret.DeepCopy()))).To(Succeed())
Expect(client.IgnoreAlreadyExists(k8sClient.Create(ctx, genericKubeconfigSecret(apiCA, apiHost, apiCert, apiKey)))).To(Succeed())
Expect(client.IgnoreAlreadyExists(k8sClient.Create(ctx, shootTokenSecret.DeepCopy()))).To(Succeed())
})
Describe("the rolling update", Ordered, func() {
When("creating a firewall deployment", Ordered, func() {
It("the creation works", func() {
swapMetalClient(&metalclient.MetalMockFns{
Firewall: func(m *mock.Mock) {
m.On("AllocateFirewall", mock.Anything, nil).Return(&metalfirewall.AllocateFirewallOK{Payload: firewall1}, nil).Maybe()
m.On("FindFirewall", mock.Anything, nil).Return(&metalfirewall.FindFirewallOK{Payload: firewall1}, nil).Maybe()
m.On("FindFirewalls", mock.Anything, nil).Return(&metalfirewall.FindFirewallsOK{Payload: []*models.V1FirewallResponse{firewall1}}, nil).Maybe()
},
Network: func(m *mock.Mock) {
m.On("FindNetwork", mock.Anything, nil).Return(&network.FindNetworkOK{Payload: network1}, nil).Maybe()
},
Machine: func(m *mock.Mock) {
m.On("UpdateMachine", mock.Anything, nil).Return(&machine.UpdateMachineOK{Payload: &models.V1MachineResponse{}}, nil).Maybe()
},
Image: func(m *mock.Mock) {
m.On("FindLatestImage", mock.Anything, nil).Return(&image.FindLatestImageOK{Payload: image1}, nil).Maybe()
},
})
Expect(k8sClient.Create(ctx, deployment())).To(Succeed())
})
It("the userdata was rendered by the defaulting webhook", func() {
deploy := &v2.FirewallDeployment{}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
Expect(deploy.Spec.Template.Spec.Userdata).NotTo(BeEmpty())
})
It("the update strategy is rolling update", func() {
deploy := &v2.FirewallDeployment{}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
Expect(deploy.Spec.Strategy).To(Equal(v2.StrategyRollingUpdate))
})
})
Describe("new resources will be spawned by the controller", Ordered, func() {
var (
fw *v2.Firewall
set *v2.FirewallSet
mon *v2.FirewallMonitor
)
It("should create a firewall set", func() {
set = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallSetList{}, func(l *v2.FirewallSetList) []*v2.FirewallSet {
return l.GetItems()
}, 15*time.Second)
})
It("should create a firewall", func() {
fw = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallList{}, func(l *v2.FirewallList) []*v2.Firewall {
return l.GetItems()
}, 15*time.Second)
})
It("should create a firewall monitor", func() {
mon = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallMonitorList{}, func(l *v2.FirewallMonitorList) []*v2.FirewallMonitor {
return l.GetItems()
}, 15*time.Second)
})
It("should allow an update of the firewall monitor", func() {
// simulating a firewall-controller updating the resource
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(mon), mon)).To(Succeed()) // refetch
mon.ControllerStatus = &v2.ControllerStatus{
Updated: metav1.NewTime(time.Now()),
SeedUpdated: metav1.NewTime(time.Now()),
Distance: v2.FirewallShortestDistance,
DistanceSupported: true,
}
Expect(k8sClient.Update(ctx, mon)).To(Succeed())
})
Context("the firewall resource", func() {
It("should be named after the namespace (it's the shoot name in the end)", func() {
Expect(fw.Name).To(HavePrefix(namespaceName + "-firewall-"))
})
It("should be in the same namespace as the set", func() {
Expect(fw.Namespace).To(Equal(set.Namespace))
})
It("should inherit the spec from the set", func() {
wantSpec := set.Spec.Template.Spec.DeepCopy()
Expect(&fw.Spec).To(BeComparableTo(wantSpec))
})
It("should have the set as an owner", func() {
Expect(fw.ObjectMeta.OwnerReferences).To(HaveLen(1))
Expect(fw.ObjectMeta.OwnerReferences[0].Name).To(Equal(set.Name))
})
It("should have the created condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallCreated, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Created"))
Expect(cond.Message).To(Equal(fmt.Sprintf("Firewall %q created successfully.", *firewall1.Allocation.Name)))
})
It("should populate the machine status", func() {
var status *v2.MachineStatus
var fw = fw.DeepCopy()
Eventually(func() *v2.MachineStatus {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(fw), fw)).To(Succeed())
status = fw.Status.MachineStatus
return status
}, 5*time.Second, interval).Should(Not(BeNil()))
Expect(status.MachineID).To(Equal(*firewall1.ID))
Expect(status.CrashLoop).To(Equal(false))
Expect(status.Liveliness).To(Equal("Alive"))
Expect(status.LastEvent).NotTo(BeNil())
Expect(status.LastEvent.Event).To(Equal("Phoned Home"))
Expect(status.LastEvent.Message).To(Equal("phoning home"))
})
It("should have the ready condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallReady, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Ready"))
Expect(cond.Message).To(Equal(fmt.Sprintf("Firewall %q is phoning home and alive.", *firewall1.Allocation.Name)))
})
It("should have the monitor condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallMonitorDeployed, v2.ConditionTrue, 5*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Deployed"))
Expect(cond.Message).To(Equal("Successfully deployed firewall-monitor."))
})
It("should have the firewall-controller connected condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallControllerConnected, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Connected"))
Expect(cond.Message).To(Equal(fmt.Sprintf("Controller reconciled shoot at %s.", mon.ControllerStatus.Updated.String())))
})
It("should have the firewall-controller connected to seed condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallControllerSeedConnected, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Connected"))
Expect(cond.Message).To(Equal(fmt.Sprintf("Controller reconciled firewall at %s.", mon.ControllerStatus.SeedUpdated.String())))
})
It("should have configured the distance", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDistanceConfigured, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Configured"))
Expect(cond.Message).To(Equal(fmt.Sprintf("Controller has configured the specified distance %d.", v2.FirewallShortestDistance)))
})
It("should be in the running phase", func() {
Eventually(func() v2.FirewallPhase {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(fw), fw)).To(Succeed())
return fw.Status.Phase
}, 5*time.Second, interval).Should(Equal(v2.FirewallPhaseRunning))
})
})
Context("the firewall set resource", func() {
It("should be named after the deployment", func() {
Expect(set.Name).To(HavePrefix(deployment().Name + "-"))
})
It("should be in the same namespace as the deployment", func() {
Expect(set.Namespace).To(Equal(deployment().Namespace))
})
It("should take the same replicas as defined by the deployment", func() {
Expect(set.Spec.Replicas).To(Equal(1))
})
It("should inherit the spec from the deployment", func() {
deploy := &v2.FirewallDeployment{}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
Expect(set.Spec.Template.Spec).To(BeComparableTo(deploy.Spec.Template.Spec))
})
It("should have the deployment as an owner", func() {
Expect(set.ObjectMeta.OwnerReferences).To(HaveLen(1))
Expect(set.ObjectMeta.OwnerReferences[0].Name).To(Equal(deployment().Name))
})
It("should populate the status", func() {
var set = set.DeepCopy()
Eventually(func() int {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(set), set)).To(Succeed())
return set.Status.ReadyReplicas
}, 15*time.Second, interval).Should(Equal(1), "reach ready replicas")
Expect(set.Status.TargetReplicas).To(Equal(1))
Expect(set.Status.ProgressingReplicas).To(Equal(0))
Expect(set.Status.UnhealthyReplicas).To(Equal(0))
Expect(set.Status.ObservedRevision).To(Equal(0)) // this is the first revision
})
})
Context("the firewall deployment resource", func() {
It("should default the update strategy to rolling update (so the mutating webhook is working)", func() {
deploy := &v2.FirewallDeployment{}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
Expect(deploy.Spec.Strategy).To(Equal(v2.StrategyRollingUpdate))
})
It("should have the rbac condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, deployment(), func(fd *v2.FirewallDeployment) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDeploymentRBACProvisioned, v2.ConditionTrue, 5*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Provisioned"))
Expect(cond.Message).To(Equal("RBAC provisioned successfully."))
})
It("should have the available condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, deployment(), func(fd *v2.FirewallDeployment) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDeploymentAvailable, v2.ConditionTrue, 5*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("MinimumReplicasAvailable"))
Expect(cond.Message).To(Equal("Deployment has minimum availability."))
})
It("should have the progress condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, deployment(), func(fd *v2.FirewallDeployment) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDeploymentProgressing, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Or(Equal("NewFirewallSetAvailable"), Equal("FirewallSetUpdated")))
Expect(cond.Message).To(Or(
Equal(fmt.Sprintf("FirewallSet %q has successfully progressed.", set.Name)),
Equal(fmt.Sprintf("Updated firewall set %q.", set.Name)),
))
})
It("should populate the status", func() {
deploy := &v2.FirewallDeployment{}
Eventually(func() int {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
return deploy.Status.ReadyReplicas
}, 15*time.Second, interval).Should(Equal(1), "reach ready replicas")
Expect(deploy.Status.TargetReplicas).To(Equal(1))
Expect(deploy.Status.ProgressingReplicas).To(Equal(0))
Expect(deploy.Status.UnhealthyReplicas).To(Equal(0))
Expect(deploy.Status.ObservedRevision).To(Equal(0)) // this is the first revision
})
})
})
When("the firewall gets annotated with a systemd service restart annotation", Ordered, func() {
var (
fw *v2.Firewall
mon *v2.FirewallMonitor
)
BeforeEach(func() {
fw = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallList{}, func(l *v2.FirewallList) []*v2.Firewall {
return l.GetItems()
}, 2*time.Second)
mon = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallMonitorList{}, func(l *v2.FirewallMonitorList) []*v2.FirewallMonitor {
return l.GetItems()
}, 2*time.Second)
})
It("setting the annotation works", func() {
fw.Annotations = map[string]string{
v2.FirewallRestartSystemdServicesAnnotation: "droptailer",
}
Expect(k8sClient.Update(ctx, fw)).To(Succeed())
})
It("the annotation gets removed from the firewall", func() {
Eventually(func() map[string]string {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(fw), fw)).To(Succeed())
return fw.Annotations
}, 5*time.Second, interval).Should(Not(HaveKey(v2.FirewallRestartSystemdServicesAnnotation)), "systemd service restart annotation was not removed")
})
It("the annotation was added to the firewall monitor", func() {
Eventually(func() map[string]string {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(mon), mon)).To(Succeed())
return mon.Annotations
}, 5*time.Second, interval).Should(HaveKey(v2.FirewallRestartSystemdServicesAnnotation), "systemd service restart annotation was not added to the firewall monitor")
})
It("removing the annotation from the monitor works", func() {
mon.Annotations = nil
Expect(k8sClient.Update(ctx, mon)).To(Succeed())
})
})
When("a significant change occurs", Ordered, func() {
var (
installingFirewall = firewall2("Installing", "is installing")
)
Context("the spec is updated", func() {
It("the update works", func() {
swapMetalClient(&metalclient.MetalMockFns{
Firewall: func(m *mock.Mock) {
m.On("AllocateFirewall", mock.Anything, nil).Return(&metalfirewall.AllocateFirewallOK{Payload: installingFirewall}, nil).Maybe()
m.On("FindFirewall", mock.Anything, nil).Return(&metalfirewall.FindFirewallOK{Payload: installingFirewall}, nil).Maybe()
m.On("FindFirewalls", mock.Anything, nil).Return(&metalfirewall.FindFirewallsOK{Payload: []*models.V1FirewallResponse{installingFirewall}}, nil).Maybe()
},
Network: func(m *mock.Mock) {
m.On("FindNetwork", mock.Anything, nil).Return(&network.FindNetworkOK{Payload: network1}, nil).Maybe()
},
Machine: func(m *mock.Mock) {
m.On("UpdateMachine", mock.Anything, nil).Return(&machine.UpdateMachineOK{Payload: &models.V1MachineResponse{}}, nil).Maybe()
},
Image: func(m *mock.Mock) {
m.On("FindLatestImage", mock.Anything, nil).Return(&image.FindLatestImageOK{Payload: image1}, nil).Maybe()
},
})
deploy := deployment()
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
deploy.Spec.Template.Spec.Size = "n2-medium-x86"
Expect(k8sClient.Update(ctx, deploy)).To(Succeed())
})
})
var (
fw *v2.Firewall
set *v2.FirewallSet
mon *v2.FirewallMonitor
)
Context("new resources will be spawned by the controller", func() {
It("should create another firewall set", func() {
set = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 2, &v2.FirewallSetList{}, func(l *v2.FirewallSetList) []*v2.FirewallSet {
return l.GetItems()
}, 15*time.Second)
})
It("should create another firewall", func() {
fw = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 2, &v2.FirewallList{}, func(l *v2.FirewallList) []*v2.Firewall {
return l.GetItems()
}, 15*time.Second)
})
It("should create another firewall monitor", func() {
mon = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 2, &v2.FirewallMonitorList{}, func(l *v2.FirewallMonitorList) []*v2.FirewallMonitor {
return l.GetItems()
}, 15*time.Second)
})
Context("the new firewall resource", func() {
It("should be named after the namespace (it's the shoot name in the end)", func() {
Expect(fw.Name).To(HavePrefix(namespaceName + "-firewall-"))
})
It("should be in the same namespace as the set", func() {
Expect(fw.Namespace).To(Equal(set.Namespace))
})
It("should inherit the spec from the set", func() {
wantSpec := set.Spec.Template.Spec.DeepCopy()
Expect(&fw.Spec).To(BeComparableTo(wantSpec))
})
It("should have the set as an owner", func() {
Expect(fw.ObjectMeta.OwnerReferences).To(HaveLen(1))
Expect(fw.ObjectMeta.OwnerReferences[0].Name).To(Equal(set.Name))
})
It("should have the created condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallCreated, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Created"))
Expect(cond.Message).To(Equal(fmt.Sprintf("Firewall %q created successfully.", *installingFirewall.Allocation.Name)))
})
It("should populate the machine status", func() {
var status *v2.MachineStatus
var fw = fw.DeepCopy()
Eventually(func() *v2.MachineStatus {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(fw), fw)).To(Succeed())
status = fw.Status.MachineStatus
return status
}, 5*time.Second, interval).Should(Not(BeNil()))
Expect(status.MachineID).To(Equal(*installingFirewall.ID))
Expect(status.CrashLoop).To(Equal(false))
Expect(status.Liveliness).To(Equal("Alive"))
Expect(status.LastEvent).NotTo(BeNil())
Expect(status.LastEvent.Event).To(Equal("Installing"))
Expect(status.LastEvent.Message).To(Equal("is installing"))
})
It("should have the ready condition false", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallReady, v2.ConditionFalse, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("NotReady"))
Expect(cond.Message).To(Equal(fmt.Sprintf("Firewall %q is not ready.", *installingFirewall.Allocation.Name)))
})
It("should not yet have a distance configured", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDistanceConfigured, v2.ConditionFalse, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("NotConnected"))
Expect(cond.Message).To(Equal("Controller has not yet connected."))
})
It("should have the monitor condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallMonitorDeployed, v2.ConditionTrue, 5*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Deployed"))
Expect(cond.Message).To(Equal("Successfully deployed firewall-monitor."))
})
It("should have the firewall-controller connected condition false", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallControllerConnected, v2.ConditionFalse, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
})
It("should be in the creating phase", func() {
Eventually(func() v2.FirewallPhase {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(fw), fw)).To(Succeed())
return fw.Status.Phase
}, 5*time.Second, interval).Should(Equal(v2.FirewallPhaseCreating))
})
It("should have firewall networks populated", func() {
var nws []v2.FirewallNetwork
var fw = fw.DeepCopy()
Eventually(func() []v2.FirewallNetwork {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(fw), fw)).To(Succeed())
nws = fw.Status.FirewallNetworks
return nws
}, 5*time.Second, interval).Should(HaveLen(1))
Expect(nws).To(BeComparableTo([]v2.FirewallNetwork{
{
ASN: installingFirewall.Allocation.Networks[0].Asn,
DestinationPrefixes: installingFirewall.Allocation.Networks[0].Destinationprefixes,
IPs: installingFirewall.Allocation.Networks[0].Ips,
Nat: installingFirewall.Allocation.Networks[0].Nat,
NetworkID: installingFirewall.Allocation.Networks[0].Networkid,
NetworkType: installingFirewall.Allocation.Networks[0].Networktype,
Prefixes: network1.Prefixes,
Vrf: installingFirewall.Allocation.Networks[0].Vrf,
},
}))
})
It("should have shoot access populated", func() {
var access *v2.ShootAccess
var fw = fw.DeepCopy()
Eventually(func() *v2.ShootAccess {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(fw), fw)).To(Succeed())
access = fw.Status.ShootAccess
return access
}, 5*time.Second, interval).Should(Not(BeNil()))
Expect(access).To(BeComparableTo(&v2.ShootAccess{
GenericKubeconfigSecretName: "kubeconfig-secret-name",
TokenSecretName: "token",
Namespace: namespaceName,
APIServerURL: apiHost,
}))
})
})
Context("the new firewall set resource", func() {
It("should be named after the deployment", func() {
Expect(set.Name).To(HavePrefix(deployment().Name + "-"))
})
It("should be in the same namespace as the deployment", func() {
Expect(set.Namespace).To(Equal(deployment().Namespace))
})
It("should take the same replicas as defined by the deployment", func() {
Expect(set.Spec.Replicas).To(Equal(1))
})
It("should inherit the spec from the deployment", func() {
deploy := &v2.FirewallDeployment{}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
wantSpec := deploy.Spec.Template.Spec.DeepCopy()
wantSpec.Size = "n2-medium-x86" // this is the change that triggered the rolling update
Expect(&set.Spec.Template.Spec).To(BeComparableTo(wantSpec))
})
It("should start with a higher distance", func() {
Expect(set.Spec.Distance).To(Equal(v2.FirewallRollingUpdateSetDistance))
})
It("should have the deployment as an owner", func() {
Expect(set.ObjectMeta.OwnerReferences).To(HaveLen(1))
Expect(set.ObjectMeta.OwnerReferences[0].Name).To(Equal(deployment().Name))
})
It("should populate the status", func() {
var set = set.DeepCopy()
Eventually(func() int {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(set), set)).To(Succeed())
return set.Status.ProgressingReplicas
}, 15*time.Second, interval).Should(Equal(1), "reach progressing replicas")
Expect(set.Status.TargetReplicas).To(Equal(1))
Expect(set.Status.ReadyReplicas).To(Equal(0))
Expect(set.Status.UnhealthyReplicas).To(Equal(0))
Expect(set.Status.ObservedRevision).To(Equal(1))
})
})
Context("the firewall deployment resource", func() {
It("should have the rbac condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, deployment(), func(fd *v2.FirewallDeployment) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDeploymentRBACProvisioned, v2.ConditionTrue, 5*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Provisioned"))
Expect(cond.Message).To(Equal("RBAC provisioned successfully."))
})
It("should have the available condition false", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, deployment(), func(fd *v2.FirewallDeployment) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDeploymentAvailable, v2.ConditionFalse, 5*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("MinimumReplicasUnavailable"))
Expect(cond.Message).To(Equal("Deployment does not have minimum availability."))
})
It("should have the progress condition true", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, deployment(), func(fd *v2.FirewallDeployment) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDeploymentProgressing, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Or(Equal("NewFirewallSetAvailable"), Equal("FirewallSetUpdated")))
Expect(cond.Message).To(Or(
Equal(fmt.Sprintf("FirewallSet %q has successfully progressed.", set.Name)),
Equal(fmt.Sprintf("Updated firewall set %q.", set.Name)),
))
})
It("should populate the status", func() {
deploy := &v2.FirewallDeployment{}
Eventually(func() int {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
return deploy.Status.ProgressingReplicas
}, 15*time.Second, interval).Should(Equal(1), "reach progressing replicas")
Expect(deploy.Status.TargetReplicas).To(Equal(1))
Expect(deploy.Status.ReadyReplicas).To(Equal(0))
Expect(deploy.Status.UnhealthyReplicas).To(Equal(0))
Expect(deploy.Status.ObservedRevision).To(Equal(1))
})
It("should not be possible to update deployment strategy while deployment has not converged", func() {
deploy := &v2.FirewallDeployment{}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
deploy.Spec.Strategy = v2.StrategyRecreate
err := k8sClient.Update(ctx, deploy)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(`Invalid value: "Recreate": strategy can not be updated until target replicas have been reached (i.e. deployment has converged)`))
})
})
// TODO: verify the monitor resource
})
var (
readyFirewall = firewall2("Phoned Home", "is phoning home")
)
When("the firewall gets ready and the firewall-controller connects", Ordered, func() {
It("should allow an update of the firewall monitor", func() {
swapMetalClient(&metalclient.MetalMockFns{
Machine: func(m *mock.Mock) {
m.On("FreeMachine", mock.Anything, nil).Return(&machine.FreeMachineOK{Payload: &models.V1MachineResponse{ID: firewall1.ID}}, nil).Maybe()
m.On("UpdateMachine", mock.Anything, nil).Return(&machine.UpdateMachineOK{Payload: &models.V1MachineResponse{}}, nil).Maybe()
},
Firewall: func(m *mock.Mock) {
m.On("FindFirewall", mock.Anything, nil).Return(&metalfirewall.FindFirewallOK{Payload: readyFirewall}, nil).Maybe()
m.On("FindFirewalls", mock.Anything, nil).Return(&metalfirewall.FindFirewallsOK{Payload: []*models.V1FirewallResponse{readyFirewall}}, nil).Maybe()
},
Network: func(m *mock.Mock) {
m.On("FindNetwork", mock.Anything, nil).Return(&network.FindNetworkOK{Payload: network1}, nil).Maybe()
},
Image: func(m *mock.Mock) {
m.On("FindLatestImage", mock.Anything, nil).Return(&image.FindLatestImageOK{Payload: image1}, nil).Maybe()
},
})
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(mon), mon)).To(Succeed()) // refetch
// simulating a firewall-controller updating the resource
mon.ControllerStatus = &v2.ControllerStatus{
Updated: metav1.NewTime(time.Now()),
SeedUpdated: metav1.NewTime(time.Now()),
Distance: v2.FirewallRollingUpdateSetDistance,
DistanceSupported: true,
}
Expect(k8sClient.Update(ctx, mon)).To(Succeed())
})
It("the firewall-controller reflects the distance during a rolling update", func() {
cond := testcommon.WaitForCondition(k8sClient, ctx, fw.DeepCopy(), func(fd *v2.Firewall) v2.Conditions {
return fd.Status.Conditions
}, v2.FirewallDistanceConfigured, v2.ConditionTrue, 15*time.Second)
Expect(cond.LastTransitionTime).NotTo(BeZero())
Expect(cond.LastUpdateTime).NotTo(BeZero())
Expect(cond.Reason).To(Equal("Configured"))
Expect(cond.Message).To(Equal(fmt.Sprintf("Controller has configured the specified distance %d.", v2.FirewallRollingUpdateSetDistance)))
})
Context("the old generation disappears", Ordered, func() {
var (
fw *v2.Firewall
set *v2.FirewallSet
)
It("should delete firewall monitor", func() {
mon := testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallMonitorList{}, func(l *v2.FirewallMonitorList) []*v2.FirewallMonitor {
return l.GetItems()
}, 15*time.Second)
Expect(mon.MachineStatus.MachineID).To(Equal(*readyFirewall.ID))
})
It("should delete the firewall", func() {
fw = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallList{}, func(l *v2.FirewallList) []*v2.Firewall {
return l.GetItems()
}, 15*time.Second)
Expect(fw.Status.MachineStatus.MachineID).To(Equal(*readyFirewall.ID))
})
It("should delete the firewall set", func() {
set = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallSetList{}, func(l *v2.FirewallSetList) []*v2.FirewallSet {
return l.GetItems()
}, 15*time.Second)
Expect(set.Status.ObservedRevision).To(Equal(1))
})
Context("the update is finalized", func() {
It("should populate the controller status field in the firewall resource", func() {
var fw = fw.DeepCopy()
Eventually(func() *v2.ControllerConnection {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(fw), fw)).To(Succeed())
return fw.Status.ControllerStatus
}, 15*time.Second, interval).Should(Not(BeNil()), "controller connection was not synced to firewall resource")
})
It("the firewall set should be updated to shortest distance as the update has succeeded", func() {
Eventually(func() v2.FirewallDistance {
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(set), set)).To(Succeed())
return set.Spec.Distance
}).Within(5 * time.Second).ProbeEvery(interval).Should(Equal(v2.FirewallShortestDistance))
Expect(set.Spec.Distance).To(Equal(v2.FirewallShortestDistance))
})
})
})
})
})
Describe("the deletion flow", Ordered, func() {
When("deleting the firewall deployment", func() {
It("the deletion finishes", func() {
swapMetalClient(&metalclient.MetalMockFns{
Firewall: func(m *mock.Mock) {
m.On("AllocateFirewall", mock.Anything, nil).Return(&metalfirewall.AllocateFirewallOK{Payload: firewall1}, nil).Maybe()
m.On("FindFirewall", mock.Anything, nil).Return(&metalfirewall.FindFirewallOK{Payload: firewall1}, nil).Maybe()
m.On("FindFirewalls", mock.Anything, nil).Return(&metalfirewall.FindFirewallsOK{Payload: []*models.V1FirewallResponse{firewall1}}, nil).Maybe()
},
Network: func(m *mock.Mock) {
m.On("FindNetwork", mock.Anything, nil).Return(&network.FindNetworkOK{Payload: network1}, nil).Maybe()
},
Machine: func(m *mock.Mock) {
m.On("FreeMachine", mock.Anything, nil).Return(&machine.FreeMachineOK{Payload: &models.V1MachineResponse{ID: firewall1.ID}}, nil).Maybe()
m.On("UpdateMachine", mock.Anything, nil).Return(&machine.UpdateMachineOK{Payload: &models.V1MachineResponse{}}, nil).Maybe()
},
Image: func(m *mock.Mock) {
m.On("FindLatestImage", mock.Anything, nil).Return(&image.FindLatestImageOK{Payload: image1}, nil).Maybe()
},
})
Expect(k8sClient.Delete(ctx, deployment())).To(Succeed())
_ = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 0, &v2.FirewallDeploymentList{}, func(l *v2.FirewallDeploymentList) []*v2.FirewallDeployment {
return l.GetItems()
}, 10*time.Second)
})
})
Context("all resources are cleaned up", func() {
It("should delete the firewall set", func() {
_ = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 0, &v2.FirewallSetList{}, func(l *v2.FirewallSetList) []*v2.FirewallSet {
return l.GetItems()
}, 10*time.Second)
})
It("should delete the firewall", func() {
_ = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 0, &v2.FirewallList{}, func(l *v2.FirewallList) []*v2.Firewall {
return l.GetItems()
}, 10*time.Second)
})
It("should delete firewall monitor", func() {
_ = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 0, &v2.FirewallMonitorList{}, func(l *v2.FirewallMonitorList) []*v2.FirewallMonitor {
return l.GetItems()
}, 10*time.Second)
})
})
})
})
Describe("the recreate update", Ordered, func() {
When("creating a firewall deployment", Ordered, func() {
It("the creation works", func() {
swapMetalClient(&metalclient.MetalMockFns{
Firewall: func(m *mock.Mock) {
m.On("AllocateFirewall", mock.Anything, nil).Return(&metalfirewall.AllocateFirewallOK{Payload: firewall1}, nil).Maybe()
m.On("FindFirewall", mock.Anything, nil).Return(&metalfirewall.FindFirewallOK{Payload: firewall1}, nil).Maybe()
m.On("FindFirewalls", mock.Anything, nil).Return(&metalfirewall.FindFirewallsOK{Payload: []*models.V1FirewallResponse{firewall1}}, nil).Maybe()
},
Network: func(m *mock.Mock) {
m.On("FindNetwork", mock.Anything, nil).Return(&network.FindNetworkOK{Payload: network1}, nil).Maybe()
},
Machine: func(m *mock.Mock) {
m.On("UpdateMachine", mock.Anything, nil).Return(&machine.UpdateMachineOK{Payload: &models.V1MachineResponse{}}, nil).Maybe()
},
Image: func(m *mock.Mock) {
m.On("FindLatestImage", mock.Anything, nil).Return(&image.FindLatestImageOK{Payload: image1}, nil).Maybe()
},
})
deploy := deployment()
deploy.Spec.Strategy = v2.StrategyRecreate
Expect(k8sClient.Create(ctx, deploy)).To(Succeed())
})
It("the userdata was rendered by the defaulting webhook", func() {
deploy := &v2.FirewallDeployment{}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
Expect(deploy.Spec.Template.Spec.Userdata).NotTo(BeEmpty())
})
It("the update strategy is recreate", func() {
deploy := &v2.FirewallDeployment{}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(deployment()), deploy)).To(Succeed())
Expect(deploy.Spec.Strategy).To(Equal(v2.StrategyRecreate))
})
})
Describe("new resources will be spawned by the controller", Ordered, func() {
var (
fw *v2.Firewall
set *v2.FirewallSet
mon *v2.FirewallMonitor
)
It("should create a firewall set", func() {
set = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallSetList{}, func(l *v2.FirewallSetList) []*v2.FirewallSet {
return l.GetItems()
}, 15*time.Second)
})
It("should create a firewall", func() {
fw = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallList{}, func(l *v2.FirewallList) []*v2.Firewall {
return l.GetItems()
}, 15*time.Second)
})
It("should create a firewall monitor", func() {
mon = testcommon.WaitForResourceAmount(k8sClient, ctx, namespaceName, 1, &v2.FirewallMonitorList{}, func(l *v2.FirewallMonitorList) []*v2.FirewallMonitor {
return l.GetItems()
}, 15*time.Second)
})
It("should allow an update of the firewall monitor", func() {
// simulating a firewall-controller updating the resource
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(mon), mon)).To(Succeed()) // refetch
mon.ControllerStatus = &v2.ControllerStatus{
Updated: metav1.NewTime(time.Now()),