-
Notifications
You must be signed in to change notification settings - Fork 262
/
Copy pathe2e_test.go
1064 lines (936 loc) · 45 KB
/
e2e_test.go
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
//go:build e2e
// +build e2e
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"time"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks"
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apimachinerytypes "k8s.io/apimachinery/pkg/types"
utilrand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/noderefutil"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
crclient "sigs.k8s.io/controller-runtime/pkg/client"
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-openstack/test/e2e/shared"
)
const specName = "e2e"
var _ = Describe("e2e tests [PR-Blocking]", func() {
var (
namespace *corev1.Namespace
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
ctx context.Context
// Cleanup functions which cannot run until after the cluster has been deleted
postClusterCleanup []func()
)
BeforeEach(func() {
Expect(e2eCtx.Environment.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. BootstrapClusterProxy can't be nil")
ctx = context.TODO()
// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx)
clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult)
Expect(e2eCtx.E2EConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName)
Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.KubernetesVersion))
postClusterCleanup = nil
})
Describe("Workload cluster (default)", func() {
It("should be creatable and deletable", func() {
shared.Logf("Creating a cluster")
clusterName := fmt.Sprintf("cluster-%s", namespace.Name)
configCluster := defaultConfigCluster(clusterName, namespace.Name)
configCluster.ControlPlaneMachineCount = ptr.To(int64(1))
configCluster.WorkerMachineCount = ptr.To(int64(1))
configCluster.Flavor = shared.FlavorDefault
createCluster(ctx, configCluster, clusterResources)
md := clusterResources.MachineDeployments
workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
MachineDeployment: *md[0],
})
controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
})
Expect(workerMachines).To(HaveLen(1))
Expect(controlPlaneMachines).To(HaveLen(1))
shared.Logf("Waiting for worker nodes to be in Running phase")
statusChecks := []framework.MachineStatusCheck{framework.MachinePhaseCheck(string(clusterv1.MachinePhaseRunning))}
machineStatusInput := framework.WaitForMachineStatusCheckInput{
Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
Machine: &workerMachines[0],
StatusChecks: statusChecks,
}
framework.WaitForMachineStatusCheck(ctx, machineStatusInput, e2eCtx.E2EConfig.GetIntervals(specName, "wait-machine-status")...)
workloadCluster := e2eCtx.Environment.BootstrapClusterProxy.GetWorkloadCluster(ctx, namespace.Name, clusterName)
waitForDaemonSetRunning(ctx, workloadCluster.GetClient(), "kube-system", "openstack-cloud-controller-manager")
waitForNodesReadyWithoutCCMTaint(ctx, workloadCluster.GetClient(), 2)
openStackCluster, err := shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
// Tag: clusterName is declared on OpenStackCluster and gets propagated to all machines, including the bastion.
allServers, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Tags: clusterName})
Expect(err).NotTo(HaveOccurred())
Expect(allServers).To(HaveLen(3))
// When listing servers with multiple tags, nova api requires a single, comma-separated string
// with all the tags
controlPlaneTags := fmt.Sprintf("%s,%s", clusterName, "control-plane")
controlPlaneServers, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Tags: controlPlaneTags})
Expect(err).NotTo(HaveOccurred())
Expect(controlPlaneServers).To(HaveLen(1))
machineTags := fmt.Sprintf("%s,%s", clusterName, "machine")
machineServers, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Tags: machineTags})
Expect(err).NotTo(HaveOccurred())
Expect(machineServers).To(HaveLen(1))
networksList, err := shared.DumpOpenStackNetworks(e2eCtx, networks.ListOpts{Tags: clusterName})
Expect(err).NotTo(HaveOccurred())
Expect(networksList).To(HaveLen(1))
subnetsList, err := shared.DumpOpenStackSubnets(e2eCtx, subnets.ListOpts{Tags: clusterName})
Expect(err).NotTo(HaveOccurred())
Expect(subnetsList).To(HaveLen(1))
routersList, err := shared.DumpOpenStackRouters(e2eCtx, routers.ListOpts{Tags: clusterName})
Expect(err).NotTo(HaveOccurred())
Expect(routersList).To(HaveLen(1))
securityGroupsList, err := shared.DumpOpenStackSecurityGroups(e2eCtx, groups.ListOpts{Tags: clusterName})
Expect(err).NotTo(HaveOccurred())
Expect(securityGroupsList).To(HaveLen(3))
calicoSGRules, err := shared.DumpCalicoSecurityGroupRules(e2eCtx, openStackCluster)
Expect(err).NotTo(HaveOccurred())
// We expect 4 security group rules that allow Calico traffic on the control plane
// from both the control plane and worker machines and vice versa, that makes 8 rules.
Expect(calicoSGRules).To(Equal(8))
shared.Logf("Check the bastion")
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
bastionSpec := openStackCluster.Spec.Bastion
Expect(openStackCluster.Status.Bastion).NotTo(BeNil(), "OpenStackCluster.Status.Bastion has not been populated")
bastionServerName := openStackCluster.Status.Bastion.Name
bastionServer, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Name: bastionServerName})
Expect(err).NotTo(HaveOccurred())
Expect(bastionServer).To(HaveLen(1), "Did not find the bastion in OpenStack")
shared.Logf("Disable the bastion")
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
openStackClusterDisabledBastion := openStackCluster.DeepCopy()
openStackClusterDisabledBastion.Spec.Bastion.Enabled = ptr.To(false)
Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Update(ctx, openStackClusterDisabledBastion)).To(Succeed())
Eventually(
func() (bool, error) {
bastionServer, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Name: bastionServerName})
Expect(err).NotTo(HaveOccurred())
if len(bastionServer) == 0 {
return true, nil
}
return false, errors.New("Bastion was not deleted in OpenStack")
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-bastion")...,
).Should(BeTrue())
Eventually(
func() (bool, error) {
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
if openStackCluster.Status.Bastion == nil {
return true, nil
}
return false, errors.New("Bastion was not removed in OpenStackCluster.Status")
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-bastion")...,
).Should(BeTrue())
shared.Logf("Delete the bastion")
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
openStackClusterWithoutBastion := openStackCluster.DeepCopy()
openStackClusterWithoutBastion.Spec.Bastion = nil
Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Update(ctx, openStackClusterWithoutBastion)).To(Succeed())
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
Eventually(
func() (bool, error) {
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
if openStackCluster.Spec.Bastion == nil {
return true, nil
}
return false, errors.New("Bastion was not removed in OpenStackCluster.Spec")
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-bastion")...,
).Should(BeTrue())
shared.Logf("Create the bastion with a new flavor")
bastionNewFlavorName := e2eCtx.E2EConfig.GetVariable(shared.OpenStackBastionFlavorAlt)
bastionNewFlavor, err := shared.GetFlavorFromName(e2eCtx, bastionNewFlavorName)
Expect(err).NotTo(HaveOccurred())
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
openStackClusterWithNewBastionFlavor := openStackCluster.DeepCopy()
openStackClusterWithNewBastionFlavor.Spec.Bastion = bastionSpec
openStackClusterWithNewBastionFlavor.Spec.Bastion.Spec.Flavor = bastionNewFlavorName
Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Update(ctx, openStackClusterWithNewBastionFlavor)).To(Succeed())
Eventually(
func() (bool, error) {
bastionServer, err := shared.DumpOpenStackServers(e2eCtx, servers.ListOpts{Name: bastionServerName, Flavor: bastionNewFlavor.ID})
Expect(err).NotTo(HaveOccurred())
if len(bastionServer) == 1 {
return true, nil
}
return false, errors.New("Bastion with new flavor was not created in OpenStack")
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-bastion")...,
).Should(BeTrue())
openStackCluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
Expect(openStackCluster.Spec.Bastion).To(Equal(openStackClusterWithNewBastionFlavor.Spec.Bastion))
Expect(openStackCluster.Status.Bastion).NotTo(BeNil(), "OpenStackCluster.Status.Bastion with new flavor has not been populated")
})
})
Describe("Workload cluster (no bastion)", func() {
It("should be creatable and deletable", func() {
shared.Logf("Creating a cluster")
clusterName := fmt.Sprintf("cluster-%s", namespace.Name)
configCluster := defaultConfigCluster(clusterName, namespace.Name)
configCluster.ControlPlaneMachineCount = ptr.To(int64(1))
configCluster.WorkerMachineCount = ptr.To(int64(1))
configCluster.Flavor = shared.FlavorNoBastion
createCluster(ctx, configCluster, clusterResources)
md := clusterResources.MachineDeployments
workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
MachineDeployment: *md[0],
})
controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
})
Expect(workerMachines).To(HaveLen(1))
Expect(controlPlaneMachines).To(HaveLen(1))
shared.Logf("Waiting for worker nodes to be in Running phase")
statusChecks := []framework.MachineStatusCheck{framework.MachinePhaseCheck(string(clusterv1.MachinePhaseRunning))}
machineStatusInput := framework.WaitForMachineStatusCheckInput{
Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
Machine: &workerMachines[0],
StatusChecks: statusChecks,
}
framework.WaitForMachineStatusCheck(ctx, machineStatusInput, e2eCtx.E2EConfig.GetIntervals(specName, "wait-machine-status")...)
})
})
Describe("Workload cluster (flatcar)", func() {
It("should be creatable and deletable", func() {
// Flatcar default user is "core"
shared.SetEnvVar(shared.SSHUserMachine, "core", false)
shared.Logf("Creating a cluster")
clusterName := fmt.Sprintf("cluster-%s", namespace.Name)
configCluster := defaultConfigCluster(clusterName, namespace.Name)
configCluster.ControlPlaneMachineCount = ptr.To(int64(1))
configCluster.WorkerMachineCount = ptr.To(int64(1))
configCluster.Flavor = shared.FlavorFlatcar
createCluster(ctx, configCluster, clusterResources)
md := clusterResources.MachineDeployments
workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
MachineDeployment: *md[0],
})
controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
})
Expect(workerMachines).To(HaveLen(1))
Expect(controlPlaneMachines).To(HaveLen(1))
shared.Logf("Waiting for worker nodes to be in Running phase")
statusChecks := []framework.MachineStatusCheck{framework.MachinePhaseCheck(string(clusterv1.MachinePhaseRunning))}
machineStatusInput := framework.WaitForMachineStatusCheckInput{
Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
Machine: &workerMachines[0],
StatusChecks: statusChecks,
}
framework.WaitForMachineStatusCheck(ctx, machineStatusInput, e2eCtx.E2EConfig.GetIntervals(specName, "wait-machine-status")...)
workloadCluster := e2eCtx.Environment.BootstrapClusterProxy.GetWorkloadCluster(ctx, namespace.Name, clusterName)
waitForDaemonSetRunning(ctx, workloadCluster.GetClient(), "kube-system", "openstack-cloud-controller-manager")
waitForNodesReadyWithoutCCMTaint(ctx, workloadCluster.GetClient(), 2)
})
})
Describe("Workload cluster (flatcar-sysext)", func() {
It("should be creatable and deletable", func() {
// Flatcar default user is "core"
shared.SetEnvVar(shared.SSHUserMachine, "core", false)
shared.Logf("Creating a cluster")
clusterName := fmt.Sprintf("cluster-%s", namespace.Name)
configCluster := defaultConfigCluster(clusterName, namespace.Name)
configCluster.ControlPlaneMachineCount = ptr.To(int64(1))
configCluster.WorkerMachineCount = ptr.To(int64(1))
configCluster.Flavor = shared.FlavorFlatcarSysext
createCluster(ctx, configCluster, clusterResources)
md := clusterResources.MachineDeployments
workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
MachineDeployment: *md[0],
})
controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
})
Expect(workerMachines).To(HaveLen(1))
Expect(controlPlaneMachines).To(HaveLen(1))
shared.Logf("Waiting for worker nodes to be in Running phase")
statusChecks := []framework.MachineStatusCheck{framework.MachinePhaseCheck(string(clusterv1.MachinePhaseRunning))}
machineStatusInput := framework.WaitForMachineStatusCheckInput{
Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
Machine: &workerMachines[0],
StatusChecks: statusChecks,
}
framework.WaitForMachineStatusCheck(ctx, machineStatusInput, e2eCtx.E2EConfig.GetIntervals(specName, "wait-machine-status")...)
workloadCluster := e2eCtx.Environment.BootstrapClusterProxy.GetWorkloadCluster(ctx, namespace.Name, clusterName)
waitForDaemonSetRunning(ctx, workloadCluster.GetClient(), "kube-system", "openstack-cloud-controller-manager")
waitForNodesReadyWithoutCCMTaint(ctx, workloadCluster.GetClient(), 2)
})
})
Describe("Workload cluster (without lb)", func() {
It("should create port(s) with custom options", func() {
shared.Logf("Creating a cluster")
clusterName := fmt.Sprintf("cluster-%s", namespace.Name)
configCluster := defaultConfigCluster(clusterName, namespace.Name)
configCluster.ControlPlaneMachineCount = ptr.To(int64(1))
configCluster.WorkerMachineCount = ptr.To(int64(1))
configCluster.Flavor = shared.FlavorWithoutLB
createCluster(ctx, configCluster, clusterResources)
md := clusterResources.MachineDeployments
workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
MachineDeployment: *md[0],
})
controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
})
Expect(workerMachines).To(HaveLen(1))
Expect(controlPlaneMachines).To(HaveLen(1))
shared.Logf("Creating MachineDeployment with custom port options")
md3Name := clusterName + "-md-3"
testSecurityGroupName := "testSecGroup"
// create required test security group
Eventually(func() int {
err := shared.CreateOpenStackSecurityGroup(e2eCtx, testSecurityGroupName, "Test security group")
Expect(err).To(BeNil())
return 1
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(1))
customPortOptions := &[]infrav1.PortOpts{
{
Description: ptr.To("primary"),
},
{
Description: ptr.To("trunked"),
Trunk: ptr.To(true),
},
{
SecurityGroups: []infrav1.SecurityGroupParam{{Filter: &infrav1.SecurityGroupFilter{Name: testSecurityGroupName}}},
},
}
testTag := utilrand.String(6)
machineTags := []string{testTag}
// Note that as the bootstrap config does not have cloud.conf, the node will not be added to the cluster.
// We still expect the port for the machine to be created.
framework.CreateMachineDeployment(ctx, framework.CreateMachineDeploymentInput{
Creator: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
MachineDeployment: makeMachineDeployment(namespace.Name, md3Name, clusterName, "", 1),
BootstrapConfigTemplate: makeJoinBootstrapConfigTemplate(namespace.Name, md3Name),
InfraMachineTemplate: makeOpenStackMachineTemplateWithPortOptions(namespace.Name, clusterName, md3Name, customPortOptions, machineTags),
})
shared.Logf("Waiting for custom port to be created")
var plist []ports.Port
var err error
Eventually(func() int {
plist, err = shared.DumpOpenStackPorts(e2eCtx, ports.ListOpts{Description: "primary", Tags: testTag})
Expect(err).To(BeNil())
return len(plist)
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(1))
port := plist[0]
Expect(port.Description).To(Equal("primary"))
Expect(port.Tags).To(ContainElement(testTag))
// assert trunked port is created.
Eventually(func() int {
plist, err = shared.DumpOpenStackPorts(e2eCtx, ports.ListOpts{Description: "trunked", Tags: testTag})
Expect(err).To(BeNil())
return len(plist)
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(1))
port = plist[0]
Expect(port.Description).To(Equal("trunked"))
Expect(port.Tags).To(ContainElement(testTag))
// assert trunk data.
var trunk *trunks.Trunk
Eventually(func() int {
trunk, err = shared.DumpOpenStackTrunks(e2eCtx, port.ID)
Expect(err).To(BeNil())
Expect(trunk).NotTo(BeNil())
return 1
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(1))
Expect(trunk.PortID).To(Equal(port.ID))
// assert port level security group is created by name using SecurityGroupFilters
securityGroupsList, err := shared.DumpOpenStackSecurityGroups(e2eCtx, groups.ListOpts{Name: testSecurityGroupName})
Expect(err).NotTo(HaveOccurred())
Expect(securityGroupsList).To(HaveLen(1))
})
})
Describe("Workload cluster (multiple attached networks)", func() {
var (
clusterName string
configCluster clusterctl.ConfigClusterInput
md []*clusterv1.MachineDeployment
extraNet1, extraNet2 *networks.Network
)
BeforeEach(func() {
var err error
// Create 2 additional networks to be attached to all cluster nodes
// We can't clean up these networks in a corresponding AfterEach because they will still be in use by the cluster.
// Instead we clean them up after the cluster has been deleted.
shared.Logf("Creating additional networks")
extraNet1, err = shared.CreateOpenStackNetwork(e2eCtx, fmt.Sprintf("%s-extraNet1", namespace.Name), "10.14.0.0/24")
Expect(err).NotTo(HaveOccurred())
postClusterCleanup = append(postClusterCleanup, func() {
shared.Logf("Deleting additional network %s", extraNet1.Name)
err := shared.DeleteOpenStackNetwork(e2eCtx, extraNet1.ID)
Expect(err).NotTo(HaveOccurred())
})
extraNet2, err = shared.CreateOpenStackNetwork(e2eCtx, fmt.Sprintf("%s-extraNet2", namespace.Name), "10.14.1.0/24")
Expect(err).NotTo(HaveOccurred())
postClusterCleanup = append(postClusterCleanup, func() {
shared.Logf("Deleting additional network %s", extraNet2.Name)
err := shared.DeleteOpenStackNetwork(e2eCtx, extraNet2.ID)
Expect(err).NotTo(HaveOccurred())
})
os.Setenv("CLUSTER_EXTRA_NET_1", extraNet1.ID)
os.Setenv("CLUSTER_EXTRA_NET_2", extraNet2.ID)
shared.Logf("Creating a cluster")
clusterName = fmt.Sprintf("cluster-%s", namespace.Name)
configCluster = defaultConfigCluster(clusterName, namespace.Name)
configCluster.ControlPlaneMachineCount = ptr.To(int64(1))
configCluster.WorkerMachineCount = ptr.To(int64(1))
configCluster.Flavor = shared.FlavorMultiNetwork
createCluster(ctx, configCluster, clusterResources)
md = clusterResources.MachineDeployments
})
It("should attach all machines to multiple networks", func() {
workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
MachineDeployment: *md[0],
})
controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
})
Expect(workerMachines).To(HaveLen(int(*configCluster.WorkerMachineCount)))
Expect(controlPlaneMachines).To(HaveLen(int(*configCluster.ControlPlaneMachineCount)))
openStackCluster, err := shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
var allMachines []clusterv1.Machine
allMachines = append(allMachines, controlPlaneMachines...)
allMachines = append(allMachines, workerMachines...)
// We expect each machine to have 3 ports in each of these 3 networks with the given description.
expectedPorts := map[string]string{
openStackCluster.Status.Network.ID: "primary",
extraNet1.ID: "Extra Network 1",
extraNet2.ID: "Extra Network 2",
}
for i := range allMachines {
machine := &allMachines[i]
shared.Logf("Checking ports for machine %s", machine.Name)
instanceID := getInstanceIDForMachine(machine)
shared.Logf("Fetching ports for instance %s", instanceID)
ports, err := shared.DumpOpenStackPorts(e2eCtx, ports.ListOpts{
DeviceID: instanceID,
})
Expect(err).NotTo(HaveOccurred())
Expect(ports).To(HaveLen(len(expectedPorts)))
var seenNetworks []string
var seenAddresses clusterv1.MachineAddresses
for j := range ports {
port := &ports[j]
// Check that the port has an expected network ID and description
Expect(expectedPorts).To(HaveKeyWithValue(port.NetworkID, port.Description))
// We don't expect to see another port with this network on this machine
Expect(seenNetworks).ToNot(ContainElement(port.NetworkID))
seenNetworks = append(seenNetworks, port.NetworkID)
for k := range port.FixedIPs {
seenAddresses = append(seenAddresses, clusterv1.MachineAddress{
Type: clusterv1.MachineInternalIP,
Address: port.FixedIPs[k].IPAddress,
})
}
}
// All IP addresses on all ports should be reported in Addresses
Expect(machine.Status.Addresses).To(ContainElements(seenAddresses))
// Expect an InternalDNS entry matching the name of the OpenStack server
Expect(machine.Status.Addresses).To(ContainElement(clusterv1.MachineAddress{
Type: clusterv1.MachineInternalDNS,
Address: machine.Spec.InfrastructureRef.Name,
}))
}
})
})
Describe("MachineDeployment misconfigurations", func() {
It("should fail to create MachineDeployment with invalid subnet or invalid availability zone", func() {
shared.Logf("Creating a cluster")
clusterName := fmt.Sprintf("cluster-%s", namespace.Name)
configCluster := defaultConfigCluster(clusterName, namespace.Name)
configCluster.ControlPlaneMachineCount = ptr.To(int64(1))
configCluster.WorkerMachineCount = ptr.To(int64(0))
configCluster.Flavor = shared.FlavorWithoutLB
createCluster(ctx, configCluster, clusterResources)
shared.Logf("Creating Machine Deployment in an invalid Availability Zone")
mdInvalidAZName := clusterName + "-md-invalid-az"
framework.CreateMachineDeployment(ctx, framework.CreateMachineDeploymentInput{
Creator: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
MachineDeployment: makeMachineDeployment(namespace.Name, mdInvalidAZName, clusterName, "invalid-az", 1),
BootstrapConfigTemplate: makeJoinBootstrapConfigTemplate(namespace.Name, mdInvalidAZName),
InfraMachineTemplate: makeOpenStackMachineTemplate(namespace.Name, clusterName, mdInvalidAZName),
})
shared.Logf("Looking for failure event to be reported")
Eventually(func() bool {
eventList := getEvents(namespace.Name)
azError := "The requested availability zone is not available"
return isErrorEventExists(namespace.Name, mdInvalidAZName, "FailedCreateServer", azError, eventList)
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(BeTrue())
})
})
Describe("Workload cluster (multi-AZ)", func() {
var (
clusterName string
md []*clusterv1.MachineDeployment
failureDomain, failureDomainAlt string
volumeTypeAlt string
cluster *infrav1.OpenStackCluster
)
BeforeEach(func() {
failureDomain = e2eCtx.E2EConfig.GetVariable(shared.OpenStackFailureDomain)
failureDomainAlt = e2eCtx.E2EConfig.GetVariable(shared.OpenStackFailureDomainAlt)
volumeTypeAlt = e2eCtx.E2EConfig.GetVariable(shared.OpenStackVolumeTypeAlt)
// We create the second compute host asynchronously, so
// we need to ensure the alternate failure domain exists
// before running these tests.
//
// For efficiency we run the multi-AZ tests late in the
// test suite. In practise this should mean that the
// second compute is already up by the time we get here,
// and we don't have to wait.
Eventually(func() []string {
shared.Logf("Waiting for the alternate AZ '%s' to be created", failureDomainAlt)
return shared.GetComputeAvailabilityZones(e2eCtx)
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-alt-az")...).Should(ContainElement(failureDomainAlt))
shared.Logf("Creating a cluster")
clusterName = fmt.Sprintf("cluster-%s", namespace.Name)
configCluster := defaultConfigCluster(clusterName, namespace.Name)
configCluster.ControlPlaneMachineCount = ptr.To(int64(3))
configCluster.WorkerMachineCount = ptr.To(int64(2))
configCluster.Flavor = shared.FlavorMultiAZ
createCluster(ctx, configCluster, clusterResources)
md = clusterResources.MachineDeployments
var err error
cluster, err = shared.ClusterForSpec(ctx, e2eCtx, namespace)
Expect(err).NotTo(HaveOccurred())
})
It("should be creatable and deletable", func() {
workerMachines := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
MachineDeployment: *md[0],
})
controlPlaneMachines := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: clusterName,
Namespace: namespace.Name,
})
Expect(controlPlaneMachines).To(
HaveLen(3),
fmt.Sprintf("Cluster %s does not have the expected number of control plane machines", cluster.Name))
Expect(workerMachines).To(
HaveLen(2),
fmt.Sprintf("Cluster %s does not have the expected number of worker machines", cluster.Name))
getAZsForMachines := func(machines []clusterv1.Machine) []string {
azs := make(map[string]struct{})
for _, machine := range machines {
failureDomain := machine.Spec.FailureDomain
if failureDomain == nil {
continue
}
azs[*failureDomain] = struct{}{}
}
azSlice := make([]string, 0, len(azs))
for az := range azs {
azSlice = append(azSlice, az)
}
return azSlice
}
// The control plane should be spread across both AZs
controlPlaneAZs := getAZsForMachines(controlPlaneMachines)
Expect(controlPlaneAZs).To(
ConsistOf(failureDomain, failureDomainAlt),
fmt.Sprintf("Cluster %s: control plane machines were not scheduled in the expected AZs", cluster.Name))
// All workers should be in the alt AZ
workerAZs := getAZsForMachines(workerMachines)
Expect(workerAZs).To(
ConsistOf(failureDomainAlt),
fmt.Sprintf("Cluster %s: worker machines were not scheduled in the expected AZ", cluster.Name))
// Check that all machines were actually scheduled in the correct AZ
var allMachines []clusterv1.Machine
allMachines = append(allMachines, controlPlaneMachines...)
allMachines = append(allMachines, workerMachines...)
machineNames := sets.New[string]()
for _, machine := range allMachines {
machineNames.Insert(machine.Spec.InfrastructureRef.Name)
}
allServers, err := shared.GetOpenStackServers(e2eCtx, cluster, machineNames)
Expect(err).NotTo(HaveOccurred())
allServerNames := make([]string, 0, len(allServers))
for name := range allServers {
allServerNames = append(allServerNames, name)
}
rootVolumes := make(map[string]*volumes.Volume)
additionalVolumes := make(map[string]*volumes.Volume)
for _, machine := range allMachines {
// The output of a HaveKey() failure against
// allServers is too long and overflows
openstackMachineName := machine.Spec.InfrastructureRef.Name
Expect(allServerNames).To(
ContainElement(openstackMachineName),
fmt.Sprintf("Cluster %s: did not find a server for machine %s", cluster.Name, openstackMachineName))
server := allServers[openstackMachineName]
Expect(server.AvailabilityZone).To(
Equal(*machine.Spec.FailureDomain),
fmt.Sprintf("Server %s was not scheduled in the correct AZ", machine.Name))
// Check that all machines have the expected volumes:
// - 1 root volume
// - 1 additional volume
volumes := server.AttachedVolumes
Expect(volumes).To(HaveLen(2))
// nova.objects.BlockDeviceMappingList.bdms_by_instance_uuid does not guarantee order of the volumes
// so we need to find the boot volume by checking the "bootable" flag for now.
firstVolumeFound, err := shared.GetOpenStackVolume(e2eCtx, volumes[0].ID)
Expect(err).NotTo(HaveOccurred(), "failed to get OpenStack volume %s for machine %s", volumes[0].ID, machine.Name)
secondVolumeFound, err := shared.GetOpenStackVolume(e2eCtx, volumes[1].ID)
Expect(err).NotTo(HaveOccurred(), "failed to get OpenStack volume %s for machine %s", volumes[1].ID, machine.Name)
rootVolume := firstVolumeFound
additionalVolume := secondVolumeFound
// The boot volume is the one with the "bootable" flag set.
if firstVolumeFound.Bootable != "true" { // This is genuinely a string, not a bool
rootVolume = secondVolumeFound
additionalVolume = firstVolumeFound
}
rootVolumes[machine.Name] = rootVolume
Expect(*rootVolume).To(MatchFields(IgnoreExtras, Fields{
"Name": Equal(fmt.Sprintf("%s-root", server.Name)),
"Size": Equal(25),
"Bootable": Equal("true"), // This is genuinely a string, not a bool
}), "Boot volume %s for machine %s not as expected", rootVolume.ID, machine.Name)
additionalVolumes[machine.Name] = additionalVolume
Expect(*additionalVolume).To(MatchFields(IgnoreExtras, Fields{
"Name": Equal(fmt.Sprintf("%s-extravol", server.Name)),
"Size": Equal(1),
}), "Additional block device %s for machine %s not as expected", additionalVolume.ID, machine.Name)
}
// Expect all control plane machines to have volumes in the same AZ as the machine, and the default volume type
for _, machine := range controlPlaneMachines {
rootVolume := rootVolumes[machine.Name]
Expect(rootVolume.AvailabilityZone).To(Equal(*machine.Spec.FailureDomain))
Expect(rootVolume.VolumeType).NotTo(Equal(volumeTypeAlt))
additionalVolume := additionalVolumes[machine.Name]
Expect(additionalVolume.AvailabilityZone).To(Equal(*machine.Spec.FailureDomain))
Expect(additionalVolume.VolumeType).NotTo(Equal(volumeTypeAlt))
}
// Expect all worker machines to have volumes in the primary AZ, and the test volume type
for _, machine := range workerMachines {
rootVolume := rootVolumes[machine.Name]
Expect(rootVolume.AvailabilityZone).To(Equal(failureDomain))
Expect(rootVolume.VolumeType).To(Equal(volumeTypeAlt))
additionalVolume := additionalVolumes[machine.Name]
Expect(additionalVolume.AvailabilityZone).To(Equal(failureDomain))
Expect(additionalVolume.VolumeType).To(Equal(volumeTypeAlt))
}
})
})
AfterEach(func() {
shared.Logf("Attempting to collect logs for cluster %q in namespace %q", clusterResources.Cluster.Name, namespace.Name)
e2eCtx.Environment.BootstrapClusterProxy.CollectWorkloadClusterLogs(ctx, namespace.Name, clusterResources.Cluster.Name, filepath.Join(e2eCtx.Settings.ArtifactFolder, "clusters", e2eCtx.Environment.BootstrapClusterProxy.GetName(), namespace.Name))
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
shared.DumpSpecResourcesAndCleanup(ctx, specName, namespace, e2eCtx)
// Cleanup resources which can't be cleaned up until the cluster has been deleted
for _, cleanup := range postClusterCleanup {
cleanup()
}
})
})
func createCluster(ctx context.Context, configCluster clusterctl.ConfigClusterInput, result *clusterctl.ApplyClusterTemplateAndWaitResult) {
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
ClusterProxy: e2eCtx.Environment.BootstrapClusterProxy,
ConfigCluster: configCluster,
WaitForClusterIntervals: e2eCtx.E2EConfig.GetIntervals(specName, "wait-cluster"),
WaitForControlPlaneIntervals: e2eCtx.E2EConfig.GetIntervals(specName, "wait-control-plane"),
WaitForMachineDeployments: e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
}, result)
}
func defaultConfigCluster(clusterName, namespace string) clusterctl.ConfigClusterInput {
return clusterctl.ConfigClusterInput{
LogFolder: filepath.Join(e2eCtx.Settings.ArtifactFolder, "clusters", e2eCtx.Environment.BootstrapClusterProxy.GetName()),
ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath,
KubeconfigPath: e2eCtx.Environment.BootstrapClusterProxy.GetKubeconfigPath(),
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
Namespace: namespace,
ClusterName: clusterName,
KubernetesVersion: e2eCtx.E2EConfig.GetVariable(shared.KubernetesVersion),
}
}
func getEvents(namespace string) *corev1.EventList {
eventsList := &corev1.EventList{}
if err := e2eCtx.Environment.BootstrapClusterProxy.GetClient().List(context.TODO(), eventsList, crclient.InNamespace(namespace), crclient.MatchingLabels{}); err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "Got error while fetching events of namespace: %s, %s \n", namespace, err.Error())
}
return eventsList
}
func getInstanceIDForMachine(machine *clusterv1.Machine) string {
providerID := machine.Spec.ProviderID
Expect(providerID).NotTo(BeNil())
providerIDSplit := strings.SplitN(*providerID, ":///", 2)
Expect(providerIDSplit[0]).To(Equal("openstack"))
return providerIDSplit[1]
}
func isErrorEventExists(namespace, machineDeploymentName, eventReason, errorMsg string, eList *corev1.EventList) bool {
ctrlClient := e2eCtx.Environment.BootstrapClusterProxy.GetClient()
machineDeployment := &clusterv1.MachineDeployment{}
if err := ctrlClient.Get(context.TODO(), apimachinerytypes.NamespacedName{Namespace: namespace, Name: machineDeploymentName}, machineDeployment); err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "Got error while getting machinedeployment %s \n", machineDeploymentName)
return false
}
selector, err := metav1.LabelSelectorAsMap(&machineDeployment.Spec.Selector)
if err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "Got error while reading lables of machinedeployment: %s, %s \n", machineDeploymentName, err.Error())
return false
}
openStackMachineList := &infrav1.OpenStackMachineList{}
if err := ctrlClient.List(context.TODO(), openStackMachineList, crclient.InNamespace(namespace), crclient.MatchingLabels(selector)); err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "Got error while getting openstackmachines of machinedeployment: %s, %s \n", machineDeploymentName, err.Error())
return false
}
eventMachinesCnt := 0
for _, openStackMachine := range openStackMachineList.Items {
for _, event := range eList.Items {
if strings.Contains(event.Name, openStackMachine.Name) && event.Reason == eventReason && strings.Contains(event.Message, errorMsg) {
eventMachinesCnt++
break
}
}
}
return len(openStackMachineList.Items) == eventMachinesCnt
}
func makeOpenStackMachineTemplate(namespace, clusterName, name string) *infrav1.OpenStackMachineTemplate {
return &infrav1.OpenStackMachineTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: infrav1.OpenStackMachineTemplateSpec{
Template: infrav1.OpenStackMachineTemplateResource{
Spec: infrav1.OpenStackMachineSpec{
Flavor: e2eCtx.E2EConfig.GetVariable(shared.OpenStackNodeMachineFlavor),
Image: infrav1.ImageParam{
Filter: &infrav1.ImageFilter{
Name: ptr.To(e2eCtx.E2EConfig.GetVariable(shared.OpenStackImageName)),
},
},
SSHKeyName: shared.DefaultSSHKeyPairName,
IdentityRef: &infrav1.OpenStackIdentityReference{
Name: fmt.Sprintf("%s-cloud-config", clusterName),
CloudName: e2eCtx.E2EConfig.GetVariable(shared.OpenStackCloud),
},
},
},
},
}
}
func makeOpenStackMachineTemplateWithPortOptions(namespace, clusterName, name string, portOpts *[]infrav1.PortOpts, machineTags []string) *infrav1.OpenStackMachineTemplate {
return &infrav1.OpenStackMachineTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: infrav1.OpenStackMachineTemplateSpec{
Template: infrav1.OpenStackMachineTemplateResource{
Spec: infrav1.OpenStackMachineSpec{
Flavor: e2eCtx.E2EConfig.GetVariable(shared.OpenStackNodeMachineFlavor),
Image: infrav1.ImageParam{
Filter: &infrav1.ImageFilter{
Name: ptr.To(e2eCtx.E2EConfig.GetVariable(shared.OpenStackImageName)),
},
},
SSHKeyName: shared.DefaultSSHKeyPairName,
IdentityRef: &infrav1.OpenStackIdentityReference{
Name: fmt.Sprintf("%s-cloud-config", clusterName),
CloudName: e2eCtx.E2EConfig.GetVariable(shared.OpenStackCloud),
},
Ports: *portOpts,
Tags: machineTags,
},
},
},
}
}
// makeJoinBootstrapConfigTemplate returns a KubeadmConfigTemplate which can be used
// to test different error cases. As we're missing e.g. the cloud provider conf it cannot
// be used to successfully add nodes to a cluster.
func makeJoinBootstrapConfigTemplate(namespace, name string) *bootstrapv1.KubeadmConfigTemplate {
return &bootstrapv1.KubeadmConfigTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: bootstrapv1.KubeadmConfigTemplateSpec{
Template: bootstrapv1.KubeadmConfigTemplateResource{
Spec: bootstrapv1.KubeadmConfigSpec{
JoinConfiguration: &bootstrapv1.JoinConfiguration{
NodeRegistration: bootstrapv1.NodeRegistrationOptions{
Name: "{{ local_hostname }}",
KubeletExtraArgs: map[string]string{
"cloud-config": "/etc/kubernetes/cloud.conf",
"cloud-provider": "openstack",
},
},
},
},
},
},
}
}
func makeMachineDeployment(namespace, mdName, clusterName string, failureDomain string, replicas int32) *clusterv1.MachineDeployment {
if failureDomain == "" {
failureDomain = e2eCtx.E2EConfig.GetVariable(shared.OpenStackFailureDomain)
}
return &clusterv1.MachineDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: mdName,
Namespace: namespace,
Labels: map[string]string{
"cluster.x-k8s.io/cluster-name": clusterName,
"nodepool": mdName,
},
},
Spec: clusterv1.MachineDeploymentSpec{
Replicas: &replicas,
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"cluster.x-k8s.io/cluster-name": clusterName,
"nodepool": mdName,
},
},
ClusterName: clusterName,
Template: clusterv1.MachineTemplateSpec{
ObjectMeta: clusterv1.ObjectMeta{
Labels: map[string]string{
"cluster.x-k8s.io/cluster-name": clusterName,
"nodepool": mdName,
},
},
Spec: clusterv1.MachineSpec{
ClusterName: clusterName,
FailureDomain: &failureDomain,