-
Notifications
You must be signed in to change notification settings - Fork 431
/
azure_test.go
1255 lines (1139 loc) · 46.5 KB
/
azure_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 2020 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"
"fmt"
"os"
"time"
"github.com/Azure/azure-service-operator/v2/pkg/common/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
capi_e2e "sigs.k8s.io/cluster-api/test/e2e"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var _ = Describe("Workload cluster creation", func() {
var (
ctx = context.TODO()
specName = "create-workload-cluster"
namespace *corev1.Namespace
cancelWatches context.CancelFunc
result *clusterctl.ApplyClusterTemplateAndWaitResult
clusterName string
clusterNamePrefix string
additionalCleanup func()
specTimes = map[string]time.Time{}
skipResourceGroupCheck = false
)
BeforeEach(func() {
logCheckpoint(specTimes)
Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName)
Expect(e2eConfig).NotTo(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName)
Expect(clusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. clusterctlConfigPath must be an existing file when calling %s spec", specName)
Expect(bootstrapClusterProxy).NotTo(BeNil(), "Invalid argument. bootstrapClusterProxy can't be nil when calling %s spec", specName)
Expect(os.MkdirAll(artifactFolder, 0o755)).To(Succeed(), "Invalid argument. artifactFolder can't be created for %s spec", specName)
Expect(e2eConfig.Variables).To(HaveKey(capi_e2e.KubernetesVersion))
// CLUSTER_NAME and CLUSTER_NAMESPACE allows for testing existing clusters
// if CLUSTER_NAMESPACE is set don't generate a new prefix otherwise
// the correct namespace won't be found and a new cluster will be created
clusterNameSpace := os.Getenv("CLUSTER_NAMESPACE")
if clusterNameSpace == "" {
clusterNamePrefix = fmt.Sprintf("capz-e2e-%s", util.RandomString(6))
} else {
clusterNamePrefix = clusterNameSpace
}
// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
var err error
namespace, cancelWatches, err = setupSpecNamespace(ctx, clusterNamePrefix, bootstrapClusterProxy, artifactFolder)
Expect(err).NotTo(HaveOccurred())
result = new(clusterctl.ApplyClusterTemplateAndWaitResult)
asoSecretName := e2eConfig.GetVariable("ASO_CREDENTIAL_SECRET_NAME")
asoSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace.Name,
Name: asoSecretName,
},
StringData: map[string]string{
config.AzureSubscriptionID: e2eConfig.GetVariable(AzureSubscriptionID),
config.AzureTenantID: e2eConfig.GetVariable(AzureTenantID),
config.AzureClientID: e2eConfig.GetVariable(AzureClientIDUserAssignedIdentity),
config.AuthMode: e2eConfig.GetVariable("ASO_CREDENTIAL_SECRET_MODE"),
},
}
err = bootstrapClusterProxy.GetClient().Create(ctx, asoSecret)
Expect(client.IgnoreAlreadyExists(err)).NotTo(HaveOccurred())
identityName := e2eConfig.GetVariable(ClusterIdentityName)
Expect(os.Setenv(ClusterIdentityName, identityName)).To(Succeed())
Expect(os.Setenv(ClusterIdentityNamespace, defaultNamespace)).To(Succeed())
additionalCleanup = nil
})
AfterEach(func() {
if result.Cluster == nil {
// this means the cluster failed to come up. We make an attempt to find the cluster to be able to fetch logs for the failed bootstrapping.
_ = bootstrapClusterProxy.GetClient().Get(ctx, types.NamespacedName{Name: clusterName, Namespace: namespace.Name}, result.Cluster)
}
CheckTestBeforeCleanup()
cleanInput := cleanupInput{
SpecName: specName,
Cluster: result.Cluster,
ClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
CancelWatches: cancelWatches,
IntervalsGetter: e2eConfig.GetIntervals,
SkipCleanup: skipCleanup,
SkipLogCollection: skipLogCollection,
AdditionalCleanup: additionalCleanup,
ArtifactFolder: artifactFolder,
SkipResourceGroupCheck: skipResourceGroupCheck,
}
dumpSpecResourcesAndCleanup(ctx, cleanInput)
Expect(os.Unsetenv(AzureResourceGroup)).To(Succeed())
Expect(os.Unsetenv(AzureCustomVnetResourceGroup)).To(Succeed())
Expect(os.Unsetenv(AzureVNetName)).To(Succeed())
Expect(os.Unsetenv(ClusterIdentityName)).To(Succeed())
Expect(os.Unsetenv(ClusterIdentityNamespace)).To(Succeed())
Expect(os.Unsetenv("WINDOWS_WORKER_MACHINE_COUNT")).To(Succeed())
Expect(os.Unsetenv("K8S_FEATURE_GATES")).To(Succeed())
logCheckpoint(specTimes)
})
if os.Getenv("USE_LOCAL_KIND_REGISTRY") != "true" {
// This spec expects a user-assigned identity with Contributor role assignment named "cloud-provider-user-identity" in a "capz-ci"
// resource group. Override these defaults by setting the USER_IDENTITY and CI_RG environment variables.
Context("Creating a private cluster [OPTIONAL]", func() {
It("Creates a public management cluster in a custom vnet", func() {
clusterName = getClusterName(clusterNamePrefix, "public-custom-vnet")
By("Creating a custom virtual network", func() {
Expect(os.Setenv(AzureCustomVNetName, "custom-vnet")).To(Succeed())
Expect(os.Setenv(AzureCustomVnetResourceGroup, clusterName+"-vnetrg")).To(Succeed())
additionalCleanup = SetupExistingVNet(ctx,
"10.0.0.0/16",
map[string]string{fmt.Sprintf("%s-controlplane-subnet", os.Getenv(AzureCustomVNetName)): "10.0.0.0/24"},
map[string]string{fmt.Sprintf("%s-node-subnet", os.Getenv(AzureCustomVNetName)): "10.0.1.0/24"},
fmt.Sprintf("%s-azure-bastion-subnet", os.Getenv(AzureCustomVNetName)),
"10.0.2.0/24",
)
})
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("custom-vnet"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("Creating a private cluster from the management cluster", func() {
AzurePrivateClusterSpec(ctx, func() AzurePrivateClusterSpecInput {
return AzurePrivateClusterSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
ClusterctlConfigPath: clusterctlConfigPath,
E2EConfig: e2eConfig,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
CancelWatches: cancelWatches,
}
})
})
By("PASSED!")
})
})
} else {
fmt.Fprintf(GinkgoWriter, "INFO: skipping test requires pushing container images to external repository")
}
Context("Creating a highly available cluster [REQUIRED]", func() {
It("With 3 control-plane nodes and 2 Linux and 2 Windows worker nodes", func() {
clusterName = getClusterName(clusterNamePrefix, "ha")
// Opt into using windows with prow template
Expect(os.Setenv("WINDOWS_WORKER_MACHINE_COUNT", "2")).To(Succeed())
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withNamespace(namespace.Name),
withClusterName(clusterName),
withControlPlaneMachineCount(3),
withWorkerMachineCount(2),
withControlPlaneInterval(specName, "wait-control-plane-ha"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("Verifying expected VM extensions are present on the node", func() {
AzureVMExtensionsSpec(ctx, func() AzureVMExtensionsSpecInput {
return AzureVMExtensionsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
})
By("Verifying security rules are deleted on azure side", func() {
AzureSecurityGroupsSpec(ctx, func() AzureSecurityGroupsSpecInput {
return AzureSecurityGroupsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
Cluster: result.Cluster,
WaitForUpdate: e2eConfig.GetIntervals(specName, "wait-nsg-update"),
}
})
})
By("Validating failure domains", func() {
AzureFailureDomainsSpec(ctx, func() AzureFailureDomainsSpecInput {
return AzureFailureDomainsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Cluster: result.Cluster,
Namespace: namespace,
ClusterName: clusterName,
}
})
})
By("Creating an accessible load balancer", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
By("Validating network policies", func() {
AzureNetPolSpec(ctx, func() AzureNetPolSpecInput {
return AzureNetPolSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
By("Creating an accessible load balancer for windows", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
Windows: true,
}
})
})
By("PASSED!")
})
})
When("Creating a highly available cluster with Azure CNI v1 [REQUIRED]", Label("Azure CNI v1"), func() {
It("can create 3 control-plane nodes and 2 Linux worker nodes", func() {
clusterName = getClusterName(clusterNamePrefix, "azcni-v1")
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withAzureCNIv1Manifest(e2eConfig.GetVariable(AzureCNIv1Manifest)), // AzureCNIManifest is set
withFlavor("azure-cni-v1"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withControlPlaneMachineCount(3),
withWorkerMachineCount(2),
withControlPlaneInterval(specName, "wait-control-plane-ha"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("can expect VM extensions are present on the node", func() {
AzureVMExtensionsSpec(ctx, func() AzureVMExtensionsSpecInput {
return AzureVMExtensionsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
})
By("can validate failure domains", func() {
AzureFailureDomainsSpec(ctx, func() AzureFailureDomainsSpecInput {
return AzureFailureDomainsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Cluster: result.Cluster,
Namespace: namespace,
ClusterName: clusterName,
}
})
})
By("can create an accessible load balancer", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
})
})
Context("Creating a Flatcar cluster [OPTIONAL]", func() {
It("With Flatcar control-plane and worker nodes", func() {
clusterName = getClusterName(clusterNamePrefix, "flatcar")
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("flatcar"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withKubernetesVersion(e2eConfig.GetVariable(FlatcarKubernetesVersion)),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("can create and access a load balancer", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
})
})
Context("Creating a Flatcar sysext cluster [OPTIONAL]", func() {
It("With Flatcar control-plane and worker nodes", func() {
clusterName = getClusterName(clusterNamePrefix, "flatcar-sysext")
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("flatcar-sysext"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withKubernetesVersion(e2eConfig.GetVariable(capi_e2e.KubernetesVersion)),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("can create and access a load balancer", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
})
})
Context("Creating a cluster with spot vms [OPTIONAL]", func() {
It("With spot vm machine deployments", func() {
clusterName = getClusterName(clusterNamePrefix, "spot")
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("spot"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("can create and access a load balancer", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
})
})
Context("Creating a ipv6 control-plane cluster [REQUIRED]", func() {
It("With ipv6 worker node", func() {
clusterName = getClusterName(clusterNamePrefix, "ipv6")
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("ipv6"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withControlPlaneMachineCount(3),
withWorkerMachineCount(1),
withControlPlaneInterval(specName, "wait-control-plane-ha"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("Verifying expected VM extensions are present on the node", func() {
AzureVMExtensionsSpec(ctx, func() AzureVMExtensionsSpecInput {
return AzureVMExtensionsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
})
By("Creating an accessible ipv6 load balancer", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
// Setting IPFamily to ipv6 is not required for single-stack IPv6 clusters. The clusterIP
// will be automatically assigned IPv6 address. However, setting this config so that
// we can use the same test code for both single-stack and dual-stack IPv6 clusters.
IPFamilies: []corev1.IPFamily{corev1.IPv6Protocol},
}
})
})
By("PASSED!")
})
})
Context("Creating a VMSS cluster [REQUIRED]", func() {
It("with a single control plane node and an AzureMachinePool with 2 Linux and 2 Windows worker nodes", func() {
clusterName = getClusterName(clusterNamePrefix, "vmss")
// Opt into using windows with prow template
Expect(os.Setenv("WINDOWS_WORKER_MACHINE_COUNT", "2")).To(Succeed())
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("machine-pool"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withControlPlaneMachineCount(1),
withWorkerMachineCount(2),
withMachineDeploymentInterval(specName, ""),
withControlPlaneInterval(specName, "wait-control-plane"),
withMachinePoolInterval(specName, "wait-machine-pool-nodes"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("Verifying expected VM extensions are present on the node", func() {
AzureVMExtensionsSpec(ctx, func() AzureVMExtensionsSpecInput {
return AzureVMExtensionsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
})
By("Creating an accessible load balancer", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
By("Creating an accessible load balancer for windows", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
Windows: true,
}
})
})
By("PASSED!")
})
})
// ci-e2e.sh and Prow CI skip this test by default, since N-series GPUs are relatively expensive
// and may require specific quota limits on the subscription.
// To include this test, set `GINKGO_SKIP=""`.
// You can override the default SKU `Standard_NV12s_v3` and `Premium_LRS` storage by setting
// the `AZURE_GPU_NODE_MACHINE_TYPE` and `AZURE_GPU_NODE_STORAGE_TYPE` environment variables.
// See https://azure.microsoft.com/en-us/pricing/details/virtual-machines/linux/ for pricing.
Context("Creating a GPU-enabled cluster [OPTIONAL]", func() {
It("with a single control plane node and 1 node", func() {
Skip("Skipping since the e2e subscription has no quota for GPU SKUs")
clusterName = getClusterName(clusterNamePrefix, "gpu")
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("nvidia-gpu"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withMachineDeploymentInterval(specName, "wait-gpu-nodes"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
return DaemonsetsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
InstallGPUOperator(ctx, func() GPUOperatorSpecInput {
return GPUOperatorSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
}),
), result)
By("Verifying expected VM extensions are present on the node", func() {
AzureVMExtensionsSpec(ctx, func() AzureVMExtensionsSpecInput {
return AzureVMExtensionsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
})
By("Running a GPU-based calculation", func() {
AzureGPUSpec(ctx, func() AzureGPUSpecInput {
return AzureGPUSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
By("PASSED!")
})
})
// ci-e2e.sh and Prow CI skip this test by default. To include this test, set `GINKGO_SKIP=""`.
Context("Creating a cluster with VMSS flex machinepools [OPTIONAL]", func() {
It("with 1 control plane node and 1 machinepool", func() {
clusterName = getClusterName(clusterNamePrefix, "flex")
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("machine-pool-flex"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withMachineDeploymentInterval(specName, ""),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
}),
withMachinePoolInterval(specName, "wait-machine-pool-nodes"),
withControlPlaneInterval(specName, "wait-control-plane"),
), result)
By("Verifying machinepool can scale out and in", func() {
AzureMachinePoolsSpec(ctx, func() AzureMachinePoolsSpecInput {
return AzureMachinePoolsSpecInput{
Cluster: result.Cluster,
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
}
})
})
By("Verifying expected VM extensions are present on the node", func() {
AzureVMExtensionsSpec(ctx, func() AzureVMExtensionsSpecInput {
return AzureVMExtensionsSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
}
})
})
By("Creating an accessible load balancer", func() {
AzureLBSpec(ctx, func() AzureLBSpecInput {
return AzureLBSpecInput{
BootstrapClusterProxy: bootstrapClusterProxy,
Namespace: namespace,
ClusterName: clusterName,
SkipCleanup: skipCleanup,
}
})
})
By("PASSED!")
})
})
// You can override the default SKU `Standard_D2s_v3` by setting the
// `AZURE_AKS_NODE_MACHINE_TYPE` environment variable.
Context("Creating an AKS cluster for control plane tests [Managed Kubernetes]", func() {
It("with a single control plane node and 1 node", func() {
clusterName = getClusterName(clusterNamePrefix, aksClusterNameSuffix)
kubernetesVersionUpgradeFrom, err := GetAKSKubernetesVersion(ctx, e2eConfig, AKSKubernetesVersionUpgradeFrom)
Byf("Upgrading from k8s version %s", kubernetesVersionUpgradeFrom)
Expect(err).NotTo(HaveOccurred())
kubernetesVersion, err := GetAKSKubernetesVersion(ctx, e2eConfig, AKSKubernetesVersion)
Byf("Upgrading to k8s version %s", kubernetesVersion)
Expect(err).NotTo(HaveOccurred())
clusterTemplate := createApplyClusterTemplateInput(
specName,
withFlavor("aks"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withKubernetesVersion(kubernetesVersionUpgradeFrom),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withMachineDeploymentInterval(specName, ""),
withMachinePoolInterval(specName, "wait-worker-nodes"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: WaitForAKSControlPlaneInitialized,
WaitForControlPlaneMachinesReady: WaitForAKSControlPlaneReady,
}),
)
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterTemplate, result)
// This test should be first to make sure that the template re-applied here matches the current
// state of the cluster exactly.
By("orphaning and adopting the cluster", func() {
AKSAdoptSpec(ctx, func() AKSAdoptSpecInput {
return AKSAdoptSpecInput{
ApplyInput: clusterTemplate,
ApplyResult: result,
Cluster: result.Cluster,
MachinePools: result.MachinePools,
}
})
})
By("adding an AKS marketplace extension", func() {
AKSMarketplaceExtensionSpec(ctx, func() AKSMarketplaceExtensionSpecInput {
return AKSMarketplaceExtensionSpecInput{
Cluster: result.Cluster,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
By("attaching the cluster to azure fleet", func() {
AKSFleetsMemberSpec(ctx, func() AKSFleetsMemberInput {
return AKSFleetsMemberInput{
Cluster: result.Cluster,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
By("Upgrading the Kubernetes version of the cluster", func() {
AKSUpgradeSpec(ctx, func() AKSUpgradeSpecInput {
return AKSUpgradeSpecInput{
Cluster: result.Cluster,
MachinePools: result.MachinePools,
KubernetesVersionUpgradeTo: kubernetesVersion,
WaitForControlPlane: e2eConfig.GetIntervals(specName, "wait-machine-upgrade"),
WaitForMachinePools: e2eConfig.GetIntervals(specName, "wait-machine-pool-upgrade"),
}
})
})
By("modifying the azure cluster-autoscaler settings", func() {
AKSAzureClusterAutoscalerSettingsSpec(ctx, func() AKSAzureClusterAutoscalerSettingsSpecInput {
return AKSAzureClusterAutoscalerSettingsSpecInput{
Cluster: result.Cluster,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
}
})
})
})
})
Context("Creating an AKS cluster for node pool tests [Managed Kubernetes]", func() {
It("with a single control plane node and 1 node", func() {
clusterName = getClusterName(clusterNamePrefix, "pool")
kubernetesVersion, err := GetAKSKubernetesVersion(ctx, e2eConfig, AKSKubernetesVersion)
Expect(err).NotTo(HaveOccurred())
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("aks"),
withAzureCNIv1Manifest(e2eConfig.GetVariable(AzureCNIv1Manifest)),
withNamespace(namespace.Name),
withClusterName(clusterName),
withKubernetesVersion(kubernetesVersion),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withMachineDeploymentInterval(specName, ""),
withMachinePoolInterval(specName, "wait-worker-nodes"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: WaitForAKSControlPlaneInitialized,
WaitForControlPlaneMachinesReady: WaitForAKSControlPlaneReady,
}),
), result)
By("Exercising machine pools", func() {
AKSMachinePoolSpec(ctx, func() AKSMachinePoolSpecInput {
return AKSMachinePoolSpecInput{
Cluster: result.Cluster,
MachinePools: result.MachinePools,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
By("creating a machine pool with public IP addresses from a prefix", func() {
// This test is also currently serving as the canonical
// "create/delete node pool" test. Eventually, that should be
// made more distinct from this public IP prefix test.
AKSPublicIPPrefixSpec(ctx, func() AKSPublicIPPrefixSpecInput {
return AKSPublicIPPrefixSpecInput{
Cluster: result.Cluster,
KubernetesVersion: kubernetesVersion,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
}
})
})
By("creating a machine pool with spot max price and scale down mode", func() {
AKSSpotSpec(ctx, func() AKSSpotSpecInput {
return AKSSpotSpecInput{
Cluster: result.Cluster,
KubernetesVersion: kubernetesVersion,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
}
})
})
By("modifying nodepool autoscaling configuration", func() {
AKSAutoscaleSpec(ctx, func() AKSAutoscaleSpecInput {
return AKSAutoscaleSpecInput{
Cluster: result.Cluster,
MachinePool: result.MachinePools[0],
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
By("modifying additionalTags configuration", func() {
AKSAdditionalTagsSpec(ctx, func() AKSAdditionalTagsSpecInput {
return AKSAdditionalTagsSpecInput{
Cluster: result.Cluster,
MachinePools: result.MachinePools,
WaitForUpdate: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
By("modifying node labels configuration", func() {
AKSNodeLabelsSpec(ctx, func() AKSNodeLabelsSpecInput {
return AKSNodeLabelsSpecInput{
Cluster: result.Cluster,
MachinePools: result.MachinePools,
WaitForUpdate: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
By("modifying taints configuration", func() {
AKSNodeTaintsSpec(ctx, func() AKSNodeTaintsSpecInput {
return AKSNodeTaintsSpecInput{
Cluster: result.Cluster,
MachinePools: result.MachinePools,
WaitForUpdate: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
By("creating a byo nodepool", func() {
AKSBYONodeSpec(ctx, func() AKSBYONodeSpecInput {
return AKSBYONodeSpecInput{
Cluster: result.Cluster,
KubernetesVersion: kubernetesVersion,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
ExpectedWorkerNodes: result.ExpectedWorkerNodes(),
}
})
})
By("modifying custom patches", func() {
AKSPatchSpec(ctx, func() AKSPatchSpecInput {
return AKSPatchSpecInput{
Cluster: result.Cluster,
MachinePools: result.MachinePools,
WaitForUpdate: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
})
})
Context("Creating an AKS cluster using ClusterClass [Managed Kubernetes]", func() {
It("with a single control plane node and 1 node", func() {
// Use default as the clusterclass name so test infra can find the clusterclass template
os.Setenv("CLUSTER_CLASS_NAME", "default")
// Use "cc" as spec name because NAT gateway pip name exceeds limit.
clusterName = getClusterName(clusterNamePrefix, "cc")
kubernetesVersionUpgradeFrom, err := GetAKSKubernetesVersion(ctx, e2eConfig, AKSKubernetesVersionUpgradeFrom)
Byf("Upgrading from k8s version %s", kubernetesVersionUpgradeFrom)
Expect(err).NotTo(HaveOccurred())
kubernetesVersion, err := GetAKSKubernetesVersion(ctx, e2eConfig, AKSKubernetesVersion)
Byf("Upgrading to k8s version %s", kubernetesVersion)
Expect(err).NotTo(HaveOccurred())
// Create a cluster using the cluster class created above
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("aks-topology"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withKubernetesVersion(kubernetesVersionUpgradeFrom),
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withMachineDeploymentInterval(specName, ""),
withMachinePoolInterval(specName, "wait-machine-pool-nodes"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: WaitForAKSControlPlaneInitialized,
WaitForControlPlaneMachinesReady: WaitForAKSControlPlaneReady,
}),
), result)
By("Performing ClusterClass operations on the cluster", func() {
AKSClusterClassSpec(ctx, func() AKSClusterClassInput {
return AKSClusterClassInput{
Cluster: result.Cluster,
MachinePool: result.MachinePools[0],
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
WaitUpgradeIntervals: e2eConfig.GetIntervals(specName, "wait-machine-pool-upgrade"),
KubernetesVersionUpgradeTo: kubernetesVersion,
}
})
})
})
})
Context("Creating an AKS cluster with the ASO API [Managed Kubernetes]", func() {
It("with a single control plane node and 1 node", func() {
clusterName = getClusterName(clusterNamePrefix, "asoapi")
kubernetesVersion, err := GetAKSKubernetesVersion(ctx, e2eConfig, AKSKubernetesVersion)
Expect(err).NotTo(HaveOccurred())
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
specName,
withFlavor("aks-aso"),
withNamespace(namespace.Name),
withClusterName(clusterName),
withKubernetesVersion(kubernetesVersion),
withWorkerMachineCount(1),
withMachinePoolInterval(specName, "wait-worker-nodes"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: WaitForAKSControlPlaneInitialized,
WaitForControlPlaneMachinesReady: WaitForAKSControlPlaneReady,
}),
), result)
By("Exercising machine pools", func() {
AKSMachinePoolSpec(ctx, func() AKSMachinePoolSpecInput {
return AKSMachinePoolSpecInput{
Cluster: result.Cluster,
MachinePools: result.MachinePools,
WaitIntervals: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
}
})
})
})
})
// ci-e2e.sh and Prow CI skip this test by default. To include this test, set `GINKGO_SKIP=""`.
// This spec expects a user-assigned identity named "cloud-provider-user-identity" in a "capz-ci"
// resource group. Override these defaults by setting the USER_IDENTITY and CI_RG environment variables.
Context("Creating a dual-stack cluster [OPTIONAL]", func() {
It("With dual-stack worker node", func() {
By("using user-assigned identity")
clusterName = getClusterName(clusterNamePrefix, "dual-stack")
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(