forked from kubermatic/machine-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_e2e_test.go
895 lines (746 loc) · 33.3 KB
/
all_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
// +build e2e
/*
Copyright 2019 The Machine Controller 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 provisioning
import (
"context"
"flag"
"fmt"
"os"
"strings"
"testing"
"time"
clusterv1alpha1 "github.com/kubermatic/machine-controller/pkg/apis/cluster/v1alpha1"
providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
"github.com/kubermatic/machine-controller/pkg/userdata/flatcar"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)
func init() {
klog.InitFlags(nil)
if err := clusterv1alpha1.SchemeBuilder.AddToScheme(scheme.Scheme); err != nil {
klog.Fatalf("failed to add clusterv1alpha1 to scheme: %v", err)
}
}
const (
DOManifest = "./testdata/machinedeployment-digitalocean.yaml"
AWSManifest = "./testdata/machinedeployment-aws.yaml"
AWSManifestARM = "./testdata/machinedeployment-aws-arm-machines.yaml"
AWSEBSEncryptedManifest = "./testdata/machinedeployment-aws-ebs-encryption-enabled.yaml"
AzureManifest = "./testdata/machinedeployment-azure.yaml"
AzureRedhatSatelliteManifest = "./testdata/machinedeployment-azure.yaml"
AzureCustomImageReferenceManifest = "./testdata/machinedeployment-azure-custom-image-reference.yaml"
GCEManifest = "./testdata/machinedeployment-gce.yaml"
HZManifest = "./testdata/machinedeployment-hetzner.yaml"
PacketManifest = "./testdata/machinedeployment-packet.yaml"
LinodeManifest = "./testdata/machinedeployment-linode.yaml"
VSPhereManifest = "./testdata/machinedeployment-vsphere.yaml"
VSPhereDSCManifest = "./testdata/machinedeployment-vsphere-datastore-cluster.yaml"
VSPhereResourcePoolManifest = "./testdata/machinedeployment-vsphere-resource-pool.yaml"
ScalewayManifest = "./testdata/machinedeployment-scaleway.yaml"
OSMachineManifest = "./testdata/machine-openstack.yaml"
OSManifest = "./testdata/machinedeployment-openstack.yaml"
OSUpgradeManifest = "./testdata/machinedeployment-openstack-upgrade.yml"
invalidMachineManifest = "./testdata/machine-invalid.yaml"
kubevirtManifest = "./testdata/machinedeployment-kubevirt.yaml"
kubevirtManifestDNSConfig = "./testdata/machinedeployment-kubevirt-dns-config.yaml"
alibabaManifest = "./testdata/machinedeployment-alibaba.yaml"
anexiaManifest = "./testdata/machinedeployment-anexia.yaml"
)
var testRunIdentifier = flag.String("identifier", "local", "The unique identifier for this test run")
func TestInvalidObjectsGetRejected(t *testing.T) {
t.Parallel()
tests := []scenario{
{osName: "invalid", executor: verifyCreateMachineFails},
{osName: "flatcar", executor: verifyCreateMachineFails},
}
for i, test := range tests {
testScenario(t,
test,
fmt.Sprintf("invalid-machine-%v", i),
nil,
invalidMachineManifest,
false)
}
}
// TestCustomCAsAreApplied ensures that the configured CA bundle is actually
// being used by performing a negative test: It purposefully replaces the
// valid CA bundle with a bundle that contains one random self-signed cert
// and then expects openstack provisioning to _fail_.
func TestCustomCAsAreApplied(t *testing.T) {
t.Parallel()
osAuthURL := os.Getenv("OS_AUTH_URL")
osDomain := os.Getenv("OS_DOMAIN")
osPassword := os.Getenv("OS_PASSWORD")
osRegion := os.Getenv("OS_REGION")
osUsername := os.Getenv("OS_USERNAME")
osTenant := os.Getenv("OS_TENANT_NAME")
osNetwork := os.Getenv("OS_NETWORK_NAME")
if osAuthURL == "" || osUsername == "" || osPassword == "" || osDomain == "" || osRegion == "" || osTenant == "" {
t.Fatal("unable to run test suite, all of OS_AUTH_URL, OS_USERNAME, OS_PASSOWRD, OS_REGION, and OS_TENANT OS_DOMAIN must be set!")
}
params := []string{
fmt.Sprintf("<< IDENTITY_ENDPOINT >>=%s", osAuthURL),
fmt.Sprintf("<< USERNAME >>=%s", osUsername),
fmt.Sprintf("<< PASSWORD >>=%s", osPassword),
fmt.Sprintf("<< DOMAIN_NAME >>=%s", osDomain),
fmt.Sprintf("<< REGION >>=%s", osRegion),
fmt.Sprintf("<< TENANT_NAME >>=%s", osTenant),
fmt.Sprintf("<< NETWORK_NAME >>=%s", osNetwork),
}
testScenario(
t,
scenario{
name: "ca-test",
containerRuntime: "docker",
kubernetesVersion: versions[0].String(),
osName: string(providerconfigtypes.OperatingSystemUbuntu),
executor: func(kubeConfig, manifestPath string, parameters []string, d time.Duration) error {
if err := updateMachineControllerForCustomCA(kubeConfig); err != nil {
return fmt.Errorf("failed to add CA: %v", err)
}
return verifyCreateMachineFails(kubeConfig, manifestPath, parameters, d)
},
},
"dummy-machine",
params,
OSMachineManifest,
false,
)
}
func updateMachineControllerForCustomCA(kubeconfig string) error {
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return fmt.Errorf("Error building kubeconfig: %v", err)
}
client, err := ctrlruntimeclient.New(cfg, ctrlruntimeclient.Options{})
if err != nil {
return fmt.Errorf("failed to create Client: %v", err)
}
ctx := context.Background()
ns := metav1.NamespaceSystem
// create intentionally valid but useless CA bundle
caBundle := &corev1.ConfigMap{
ObjectMeta: v1.ObjectMeta{
Namespace: ns,
Name: "ca-bundle",
},
Data: map[string]string{
// this certificate was created using `make examples/ca-cert.pem`
"ca-bundle.pem": strings.TrimSpace(`
-----BEGIN CERTIFICATE-----
MIIFezCCA2OgAwIBAgIUV9en2WQLDZ1VzPYgzblnuhrg1sQwDQYJKoZIhvcNAQEL
BQAwTTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMQ0wCwYDVQQKDARBY21lMSIw
IAYDVQQDDBlrOHMtbWFjaGluZS1jb250cm9sbGVyLWNhMB4XDTIwMDgxOTEzNDEw
MloXDTQ4MDEwNTEzNDEwMlowTTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMQ0w
CwYDVQQKDARBY21lMSIwIAYDVQQDDBlrOHMtbWFjaGluZS1jb250cm9sbGVyLWNh
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtHUcIL+zTd7jmYazQCL0
auCJxbICdthFzW3Hs8FwQ3zhXiqP7bsgMgLsG5lxmRA1iyRRUQklV/Cu6XTWQkPA
Z8WqA06zhoNl7/f5tfhilJS6RP3ftlDJ9UMVb2DaG560VF+31QHZKL8Hr0KgPdz9
WgUFTpD1LpOk0wHJdjc/WzKaTFrZm3UAZRcZIkR0+5LrUudmUPYfbHWtYSYLX2vB
Y0+9oKqcpTtoFE2jGa993dtSPSE7grG3kfKb+IhwHUDXOW0xiT/uue7JAJYc6fDd
RoRdf3vSIESl9+R7lxymcW5R9YrQ26YJ6HlVr14BpT0hNVgvrpJINstYBpj5PbQV
kpIcHmrDOoZEgb+QTAtzga0mZctWWa7U1AJ8KoWejrJgNCAE4nrecFaPQ7aDjSe4
ca0/Gx1TtLPhswMFqQhihK4bxuV1iTTsk++h8rK5ii6jO6ioS+AF9Nqye+1tYuE8
JePXMMkO1pnwKeyiRGs8poJdQEXzu0xYbc/f2FZqP4b9X4TfsVC5WQIO/xhfhaOI
l0cIKTaBn5mWW5gn/ag+AnaTHZ7aX3A4zAuE/riyTFC2GWNLO5PqlTgo6c/+5ynC
x5Q6CUBIMFw4LP8DMC2bWhyJjRaCre9+3bXSXQ8XCWxAyfTjDTcIgBEv0+peGko0
wb697GGWGgiqlRpW8GBZPeUCAwEAAaNTMFEwHQYDVR0OBBYEFO2EDvPI7jRqR6rK
vKkqj8BxCCZvMB8GA1UdIwQYMBaAFO2EDvPI7jRqR6rKvKkqj8BxCCZvMA8GA1Ud
EwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBAJMXHPxnorj4h+HePA1TaqBs
LPfrARxPGi+/mFWGtT8JpLf8cP1YT3j74sdD9oiDCxDSL+Cg5JY3IKa5U+jnS6Go
a26D4U9MOUl2hPOa/f4BEEN9+6jNvB/jg1Jd1YC1Q7hdWjBZKx1n+qMhq+bwNJZo
du0t/zmgk6sJVa7E50ILv/WmEQDCo0NFpOBSku0M35iA+maMgxq5/7EBybl2Qo2F
j6IPTxGBRbOE13I8virmYz9MdloiKX1GDUDCP3yRSSnPVveKlaGYa/lCNbSEhynb
KZHbzcro71RRAgne1cNaFIqr5oCZMSSx+hlsc/mkenr7Dg1/o6FexFc1IYO85Fs4
VC8Yb5V2oD8IDZlRVo7G74cZqEly8OYHO17zO0ib3S70aPGTUtFXEyMiirWCbVCb
L3I2dvQcO19WTQ8CfujWGtbL2lhBZvJTfa9fzrz3uYQRIeBHIWZvi8sEIQ1pmeOi
9PQkGHHJO+jfJkbOdR9cAmHUyuHH26WzZctg5CR2+f6xA8kO/8tUMEAJ9hUJa1iJ
Br0c+gPd5UmjrHLikc40/CgjmfLkaSJcnmiYP0xxYM3Rqm8ptKJM7asHDDbeBK8m
rh3NiRD903zsNpRiUXKkQs7N382SkRaBTB/rJTONM00pXEQYAivs5nIEfCQzen/Z
C8QmzsMaZhk+mVFr1sGy
-----END CERTIFICATE-----
`),
},
}
if err := client.Create(ctx, caBundle); err != nil {
return fmt.Errorf("failed to create ca-bundle ConfigMap: %v", err)
}
// add CA to deployments
deployments := []string{"machine-controller", "machine-controller-webhook"}
for _, deployment := range deployments {
if err := addCAToDeployment(ctx, client, deployment, ns); err != nil {
return fmt.Errorf("failed to add CA to %s Deployment: %v", deployment, err)
}
}
// wait for deployments to roll out
for _, deployment := range deployments {
if err := wait.Poll(3*time.Second, 30*time.Second, func() (done bool, err error) {
d := &appsv1.Deployment{}
key := types.NamespacedName{Namespace: ns, Name: deployment}
if err := client.Get(ctx, key, d); err != nil {
return false, fmt.Errorf("failed to get Deployment: %v", err)
}
return d.Status.AvailableReplicas > 0, nil
}); err != nil {
return fmt.Errorf("%s Deployment never became ready: %v", deployment, err)
}
}
return nil
}
func addCAToDeployment(ctx context.Context, client ctrlruntimeclient.Client, name string, namespace string) error {
deployment := &appsv1.Deployment{}
key := types.NamespacedName{Namespace: namespace, Name: name}
if err := client.Get(ctx, key, deployment); err != nil {
return fmt.Errorf("failed to get Deployment: %v", err)
}
caVolume := corev1.Volume{
Name: "ca-bundle",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "ca-bundle",
},
},
},
}
caVolumeMount := corev1.VolumeMount{
Name: "ca-bundle",
ReadOnly: true,
MountPath: "/etc/machine-controller",
}
oldDeployment := deployment.DeepCopy()
deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, caVolume)
container := deployment.Spec.Template.Spec.Containers[0]
container.VolumeMounts = append(container.VolumeMounts, caVolumeMount)
container.Command = append(container.Command, "-ca-bundle=/etc/machine-controller/ca-bundle.pem")
deployment.Spec.Template.Spec.Containers[0] = container
return client.Patch(ctx, deployment, ctrlruntimeclient.MergeFrom(oldDeployment))
}
func TestKubevirtProvisioningE2E(t *testing.T) {
t.Parallel()
kubevirtKubeconfig := os.Getenv("KUBEVIRT_E2E_TESTS_KUBECONFIG")
if kubevirtKubeconfig == "" {
t.Fatalf("Unable to run kubevirt tests, KUBEVIRT_E2E_TESTS_KUBECONFIG must be set")
}
selector := OsSelector("ubuntu", "centos")
params := []string{
fmt.Sprintf("<< KUBECONFIG >>=%s", kubevirtKubeconfig),
}
runScenarios(t, selector, params, kubevirtManifest, fmt.Sprintf("kubevirt-%s", *testRunIdentifier))
}
func TestKubevirtDNSConfigProvisioningE2E(t *testing.T) {
t.Parallel()
kubevirtKubeconfig := os.Getenv("KUBEVIRT_E2E_TESTS_KUBECONFIG")
if kubevirtKubeconfig == "" {
t.Fatalf("Unable to run kubevirt tests, KUBEVIRT_E2E_TESTS_KUBECONFIG must be set")
}
params := []string{
fmt.Sprintf("<< KUBECONFIG >>=%s", kubevirtKubeconfig),
}
scenario := scenario{
name: "Kubevirt with dns config",
osName: "ubuntu",
containerRuntime: "docker",
kubernetesVersion: "v1.17.0",
executor: verifyCreateAndDelete,
}
testScenario(t, scenario, *testRunIdentifier, params, kubevirtManifestDNSConfig, false)
}
func TestOpenstackProvisioningE2E(t *testing.T) {
t.Parallel()
osAuthURL := os.Getenv("OS_AUTH_URL")
osDomain := os.Getenv("OS_DOMAIN")
osPassword := os.Getenv("OS_PASSWORD")
osRegion := os.Getenv("OS_REGION")
osUsername := os.Getenv("OS_USERNAME")
osTenant := os.Getenv("OS_TENANT_NAME")
osNetwork := os.Getenv("OS_NETWORK_NAME")
if osAuthURL == "" || osUsername == "" || osPassword == "" || osDomain == "" || osRegion == "" || osTenant == "" {
t.Fatal("unable to run test suite, all of OS_AUTH_URL, OS_USERNAME, OS_PASSOWRD, OS_REGION, and OS_TENANT OS_DOMAIN must be set!")
}
params := []string{
fmt.Sprintf("<< IDENTITY_ENDPOINT >>=%s", osAuthURL),
fmt.Sprintf("<< USERNAME >>=%s", osUsername),
fmt.Sprintf("<< PASSWORD >>=%s", osPassword),
fmt.Sprintf("<< DOMAIN_NAME >>=%s", osDomain),
fmt.Sprintf("<< REGION >>=%s", osRegion),
fmt.Sprintf("<< TENANT_NAME >>=%s", osTenant),
fmt.Sprintf("<< NETWORK_NAME >>=%s", osNetwork),
}
selector := Not(OsSelector("sles", "rhel", "amzn2"))
runScenarios(t, selector, params, OSManifest, fmt.Sprintf("os-%s", *testRunIdentifier))
}
// TestDigitalOceanProvisioning - a test suite that exercises digital ocean provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
//
// note that tests require a valid API Token that is read from the DO_E2E_TEST_TOKEN environmental variable.
func TestDigitalOceanProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
doToken := os.Getenv("DO_E2E_TESTS_TOKEN")
if len(doToken) == 0 {
t.Fatal("unable to run the test suite, DO_E2E_TESTS_TOKEN environment variable cannot be empty")
}
selector := OsSelector("ubuntu", "centos")
// act
params := []string{fmt.Sprintf("<< DIGITALOCEAN_TOKEN >>=%s", doToken)}
runScenarios(t, selector, params, DOManifest, fmt.Sprintf("do-%s", *testRunIdentifier))
}
// TestAWSProvisioning - a test suite that exercises AWS provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
func TestAWSProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
awsKeyID := os.Getenv("AWS_E2E_TESTS_KEY_ID")
awsSecret := os.Getenv("AWS_E2E_TESTS_SECRET")
if len(awsKeyID) == 0 || len(awsSecret) == 0 {
t.Fatal("unable to run the test suite, AWS_E2E_TESTS_KEY_ID or AWS_E2E_TESTS_SECRET environment variables cannot be empty")
}
selector := Not(OsSelector("sles"))
// act
params := []string{fmt.Sprintf("<< AWS_ACCESS_KEY_ID >>=%s", awsKeyID),
fmt.Sprintf("<< AWS_SECRET_ACCESS_KEY >>=%s", awsSecret),
fmt.Sprintf("<< PROVISIONING_UTILITY >>=%s", flatcar.Ignition),
}
runScenarios(t, selector, params, AWSManifest, fmt.Sprintf("aws-%s", *testRunIdentifier))
}
// TestAWSARMProvisioningE2E - a test suite that exercises AWS provider for arm machines
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
func TestAWSARMProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
awsKeyID := os.Getenv("AWS_E2E_TESTS_KEY_ID")
awsSecret := os.Getenv("AWS_E2E_TESTS_SECRET")
if len(awsKeyID) == 0 || len(awsSecret) == 0 {
t.Fatal("unable to run the test suite, AWS_E2E_TESTS_KEY_ID or AWS_E2E_TESTS_SECRET environment variables cannot be empty")
}
selector := OsSelector("ubuntu")
// act
params := []string{fmt.Sprintf("<< AWS_ACCESS_KEY_ID >>=%s", awsKeyID),
fmt.Sprintf("<< AWS_SECRET_ACCESS_KEY >>=%s", awsSecret),
fmt.Sprintf("<< PROVISIONING_UTILITY >>=%s", flatcar.Ignition),
}
runScenarios(t, selector, params, AWSManifestARM, fmt.Sprintf("aws-%s", *testRunIdentifier))
}
// TestAWSSLESProvisioningE2E - a test suite that exercises AWS provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
func TestAWSSLESProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
awsKeyID := os.Getenv("AWS_E2E_TESTS_KEY_ID")
awsSecret := os.Getenv("AWS_E2E_TESTS_SECRET")
if len(awsKeyID) == 0 || len(awsSecret) == 0 {
t.Fatal("unable to run the test suite, AWS_E2E_TESTS_KEY_ID or AWS_E2E_TESTS_SECRET environment variables cannot be empty")
}
// act
params := []string{fmt.Sprintf("<< AWS_ACCESS_KEY_ID >>=%s", awsKeyID),
fmt.Sprintf("<< AWS_SECRET_ACCESS_KEY >>=%s", awsSecret),
}
// We would like to test SLES image only in this test as the other images are tested in TestAWSProvisioningE2E
selector := OsSelector("sles")
runScenarios(t, selector, params, AWSManifest, fmt.Sprintf("aws-%s", *testRunIdentifier))
}
func TestAWSFlatcarCoreOSCloudInit8ProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
awsKeyID := os.Getenv("AWS_E2E_TESTS_KEY_ID")
awsSecret := os.Getenv("AWS_E2E_TESTS_SECRET")
if len(awsKeyID) == 0 || len(awsSecret) == 0 {
t.Fatal("unable to run the test suite, AWS_E2E_TESTS_KEY_ID or AWS_E2E_TESTS_SECRET environment variables cannot be empty")
}
params := []string{
fmt.Sprintf("<< AWS_ACCESS_KEY_ID >>=%s", awsKeyID),
fmt.Sprintf("<< AWS_SECRET_ACCESS_KEY >>=%s", awsSecret),
fmt.Sprintf("<< PROVISIONING_UTILITY >>=%s", flatcar.CloudInit),
}
// We would like to test flatcar with CoreOS-cloud-init
selector := OsSelector("flatcar")
runScenarios(t, selector, params, AWSManifest, fmt.Sprintf("aws-%s", *testRunIdentifier))
}
func TestAWSFlatcarContainerdProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
awsKeyID := os.Getenv("AWS_E2E_TESTS_KEY_ID")
awsSecret := os.Getenv("AWS_E2E_TESTS_SECRET")
if len(awsKeyID) == 0 || len(awsSecret) == 0 {
t.Fatal("unable to run the test suite, AWS_E2E_TESTS_KEY_ID or AWS_E2E_TESTS_SECRET environment variables cannot be empty")
}
params := []string{
fmt.Sprintf("<< AWS_ACCESS_KEY_ID >>=%s", awsKeyID),
fmt.Sprintf("<< AWS_SECRET_ACCESS_KEY >>=%s", awsSecret),
fmt.Sprintf("<< PROVISIONING_UTILITY >>=%s", flatcar.Ignition),
}
scenario := scenario{
name: "flatcar with containerd in AWS",
osName: "flatcar",
containerRuntime: "containerd",
kubernetesVersion: "1.19.9",
executor: verifyCreateAndDelete,
}
testScenario(t, scenario, *testRunIdentifier, params, AWSManifest, false)
}
func TestAWSCentOS8ProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
awsKeyID := os.Getenv("AWS_E2E_TESTS_KEY_ID")
awsSecret := os.Getenv("AWS_E2E_TESTS_SECRET")
if len(awsKeyID) == 0 || len(awsSecret) == 0 {
t.Fatal("unable to run the test suite, AWS_E2E_TESTS_KEY_ID or AWS_E2E_TESTS_SECRET environment variables cannot be empty")
}
amiID := "ami-032025b3afcbb6b34" // official "CentOS 8.2.2004 x86_64"
params := []string{
fmt.Sprintf("<< AWS_ACCESS_KEY_ID >>=%s", awsKeyID),
fmt.Sprintf("<< AWS_SECRET_ACCESS_KEY >>=%s", awsSecret),
fmt.Sprintf("<< AMI >>=%s", amiID),
}
// We would like to test CentOS8 image only in this test as the other images are tested in TestAWSProvisioningE2E
selector := OsSelector("centos")
runScenarios(t, selector, params, AWSManifest, fmt.Sprintf("aws-%s", *testRunIdentifier))
}
// TestAWSProvisioningE2EWithEbsEncryptionEnabled - a test suite that exercises AWS provider with ebs encryption enabled
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
func TestAWSProvisioningE2EWithEbsEncryptionEnabled(t *testing.T) {
t.Parallel()
// test data
awsKeyID := os.Getenv("AWS_E2E_TESTS_KEY_ID")
awsSecret := os.Getenv("AWS_E2E_TESTS_SECRET")
if len(awsKeyID) == 0 || len(awsSecret) == 0 {
t.Fatal("unable to run the test suite, AWS_E2E_TESTS_KEY_ID or AWS_E2E_TESTS_SECRET environment variables cannot be empty")
}
// act
params := []string{fmt.Sprintf("<< AWS_ACCESS_KEY_ID >>=%s", awsKeyID),
fmt.Sprintf("<< AWS_SECRET_ACCESS_KEY >>=%s", awsSecret),
}
scenario := scenario{
name: "AWS with ebs encryption enabled",
osName: "ubuntu",
containerRuntime: "docker",
kubernetesVersion: "v1.15.6",
executor: verifyCreateAndDelete,
}
testScenario(t, scenario, fmt.Sprintf("aws-%s", *testRunIdentifier), params, AWSEBSEncryptedManifest, false)
}
// TestAzureProvisioningE2E - a test suite that exercises Azure provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
func TestAzureProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
azureTenantID := os.Getenv("AZURE_E2E_TESTS_TENANT_ID")
azureSubscriptionID := os.Getenv("AZURE_E2E_TESTS_SUBSCRIPTION_ID")
azureClientID := os.Getenv("AZURE_E2E_TESTS_CLIENT_ID")
azureClientSecret := os.Getenv("AZURE_E2E_TESTS_CLIENT_SECRET")
if len(azureTenantID) == 0 || len(azureSubscriptionID) == 0 || len(azureClientID) == 0 || len(azureClientSecret) == 0 {
t.Fatal("unable to run the test suite, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET environment variables cannot be empty")
}
selector := Not(OsSelector("sles", "amzn2"))
// act
params := []string{
fmt.Sprintf("<< AZURE_TENANT_ID >>=%s", azureTenantID),
fmt.Sprintf("<< AZURE_SUBSCRIPTION_ID >>=%s", azureSubscriptionID),
fmt.Sprintf("<< AZURE_CLIENT_ID >>=%s", azureClientID),
fmt.Sprintf("<< AZURE_CLIENT_SECRET >>=%s", azureClientSecret),
}
runScenarios(t, selector, params, AzureManifest, fmt.Sprintf("azure-%s", *testRunIdentifier))
}
// TestAzureCustomImageReferenceProvisioningE2E - a test suite that exercises Azure provider
// by requesting nodes with different combination of container runtime type, container runtime version and custom Image reference.
func TestAzureCustomImageReferenceProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
azureTenantID := os.Getenv("AZURE_E2E_TESTS_TENANT_ID")
azureSubscriptionID := os.Getenv("AZURE_E2E_TESTS_SUBSCRIPTION_ID")
azureClientID := os.Getenv("AZURE_E2E_TESTS_CLIENT_ID")
azureClientSecret := os.Getenv("AZURE_E2E_TESTS_CLIENT_SECRET")
if len(azureTenantID) == 0 || len(azureSubscriptionID) == 0 || len(azureClientID) == 0 || len(azureClientSecret) == 0 {
t.Fatal("unable to run the test suite, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET environment variables cannot be empty")
}
selector := OsSelector("ubuntu")
// act
params := []string{
fmt.Sprintf("<< AZURE_TENANT_ID >>=%s", azureTenantID),
fmt.Sprintf("<< AZURE_SUBSCRIPTION_ID >>=%s", azureSubscriptionID),
fmt.Sprintf("<< AZURE_CLIENT_ID >>=%s", azureClientID),
fmt.Sprintf("<< AZURE_CLIENT_SECRET >>=%s", azureClientSecret),
}
runScenarios(t, selector, params, AzureCustomImageReferenceManifest, fmt.Sprintf("azure-%s", *testRunIdentifier))
}
// TestAzureRedhatSatelliteProvisioningE2E - a test suite that exercises Azure provider
// by requesting rhel node and subscribe to redhat satellite server.
func TestAzureRedhatSatelliteProvisioningE2E(t *testing.T) {
t.Parallel()
t.Skip()
// test data
azureTenantID := os.Getenv("AZURE_E2E_TESTS_TENANT_ID")
azureSubscriptionID := os.Getenv("AZURE_E2E_TESTS_SUBSCRIPTION_ID")
azureClientID := os.Getenv("AZURE_E2E_TESTS_CLIENT_ID")
azureClientSecret := os.Getenv("AZURE_E2E_TESTS_CLIENT_SECRET")
if len(azureTenantID) == 0 || len(azureSubscriptionID) == 0 || len(azureClientID) == 0 || len(azureClientSecret) == 0 {
t.Fatal("unable to run the test suite, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET environment variables cannot be empty")
}
// act
params := []string{
fmt.Sprintf("<< AZURE_TENANT_ID >>=%s", azureTenantID),
fmt.Sprintf("<< AZURE_SUBSCRIPTION_ID >>=%s", azureSubscriptionID),
fmt.Sprintf("<< AZURE_CLIENT_ID >>=%s", azureClientID),
fmt.Sprintf("<< AZURE_CLIENT_SECRET >>=%s", azureClientSecret),
}
scenario := scenario{
name: "Azure redhat satellite server subscription",
osName: "rhel",
containerRuntime: "docker",
kubernetesVersion: "v1.17.0",
executor: verifyCreateAndDelete,
}
testScenario(t, scenario, *testRunIdentifier, params, AzureRedhatSatelliteManifest, false)
}
// TestGCEProvisioningE2E - a test suite that exercises Google Cloud provider
// by requesting nodes with different combination of container runtime type,
// container runtime version and the OS flavour.
func TestGCEProvisioningE2E(t *testing.T) {
t.Parallel()
// Test data.
googleServiceAccount := os.Getenv("GOOGLE_SERVICE_ACCOUNT")
if len(googleServiceAccount) == 0 {
t.Fatal("unable to run the test suite, GOOGLE_SERVICE_ACCOUNT environment variable cannot be empty")
}
// Act. GCE does not support CentOS.
selector := OsSelector("ubuntu")
params := []string{
fmt.Sprintf("<< GOOGLE_SERVICE_ACCOUNT >>=%s", googleServiceAccount),
}
runScenarios(t, selector, params, GCEManifest, fmt.Sprintf("gce-%s", *testRunIdentifier))
}
// TestHetznerProvisioning - a test suite that exercises Hetzner provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
func TestHetznerProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
hzToken := os.Getenv("HZ_E2E_TOKEN")
if len(hzToken) == 0 {
t.Fatal("unable to run the test suite, HZ_E2E_TOKEN environment variable cannot be empty")
}
selector := OsSelector("ubuntu", "centos")
// act
params := []string{fmt.Sprintf("<< HETZNER_TOKEN >>=%s", hzToken)}
runScenarios(t, selector, params, HZManifest, fmt.Sprintf("hz-%s", *testRunIdentifier))
}
// TestPacketProvisioning - a test suite that exercises Packet provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
func TestPacketProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
apiKey := os.Getenv("PACKET_API_KEY")
if len(apiKey) == 0 {
t.Fatal("unable to run the test suite, PACKET_API_KEY environment variable cannot be empty")
}
projectID := os.Getenv("PACKET_PROJECT_ID")
if len(projectID) == 0 {
t.Fatal("unable to run the test suite, PACKET_PROJECT_ID environment variable cannot be empty")
}
selector := Not(OsSelector("sles", "rhel"))
// act
params := []string{
fmt.Sprintf("<< PACKET_API_KEY >>=%s", apiKey),
fmt.Sprintf("<< PACKET_PROJECT_ID >>=%s", projectID),
}
runScenarios(t, selector, params, PacketManifest, fmt.Sprintf("packet-%s", *testRunIdentifier))
}
func TestAlibabaProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
accessKeyID := os.Getenv("ALIBABA_ACCESS_KEY_ID")
if len(accessKeyID) == 0 {
t.Fatal("unable to run the test suite, ALIBABA_ACCESS_KEY_ID environment variable cannot be empty")
}
accessKeySecret := os.Getenv("ALIBABA_ACCESS_KEY_SECRET")
if len(accessKeySecret) == 0 {
t.Fatal("unable to run the test suite, ALIBABA_ACCESS_KEY_SECRET environment variable cannot be empty")
}
selector := Not(OsSelector("sles", "rhel", "flatcar"))
// act
params := []string{
fmt.Sprintf("<< ALIBABA_ACCESS_KEY_ID >>=%s", accessKeyID),
fmt.Sprintf("<< ALIBABA_ACCESS_KEY_SECRET >>=%s", accessKeySecret),
}
runScenarios(t, selector, params, alibabaManifest, fmt.Sprintf("alibaba-%s", *testRunIdentifier))
}
// TestLinodeProvisioning - a test suite that exercises Linode provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
//
// note that tests require a valid API Token that is read from the LINODE_E2E_TEST_TOKEN environmental variable.
func TestLinodeProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
linodeToken := os.Getenv("LINODE_E2E_TESTS_TOKEN")
if len(linodeToken) == 0 {
t.Fatal("unable to run the test suite, LINODE_E2E_TESTS_TOKEN environment variable cannot be empty")
}
// we're shimming userdata through Linode stackscripts and the stackscript hasn't been verified for use with centos
selector := OsSelector("ubuntu")
// act
params := []string{fmt.Sprintf("<< LINODE_TOKEN >>=%s", linodeToken)}
runScenarios(t, selector, params, LinodeManifest, fmt.Sprintf("linode-%s", *testRunIdentifier))
}
func getVSphereTestParams(t *testing.T) []string {
// test data
vsPassword := os.Getenv("VSPHERE_E2E_PASSWORD")
vsUsername := os.Getenv("VSPHERE_E2E_USERNAME")
vsCluster := os.Getenv("VSPHERE_E2E_CLUSTER")
vsAddress := os.Getenv("VSPHERE_E2E_ADDRESS")
if vsPassword == "" || vsUsername == "" || vsAddress == "" || vsCluster == "" {
t.Fatal("unable to run the test suite, VSPHERE_E2E_PASSWORD, VSPHERE_E2E_USERNAME, VSPHERE_E2E_CLUSTER " +
"or VSPHERE_E2E_ADDRESS environment variables cannot be empty")
}
// act
params := []string{fmt.Sprintf("<< VSPHERE_PASSWORD >>=%s", vsPassword),
fmt.Sprintf("<< VSPHERE_USERNAME >>=%s", vsUsername),
fmt.Sprintf("<< VSPHERE_ADDRESS >>=%s", vsAddress),
fmt.Sprintf("<< VSPHERE_CLUSTER >>=%s", vsCluster),
}
return params
}
// TestVsphereProvisioning - a test suite that exercises vsphere provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
func TestVsphereProvisioningE2E(t *testing.T) {
t.Parallel()
selector := Not(OsSelector("sles", "rhel", "amzn2"))
params := getVSphereTestParams(t)
runScenarios(t, selector, params, VSPhereManifest, fmt.Sprintf("vs-%s", *testRunIdentifier))
}
// TestVsphereDatastoreClusterProvisioning - is the same as the TestVsphereProvisioning suite but specifies a DatastoreCluster
// instead of the Datastore in the provider specs.
func TestVsphereDatastoreClusterProvisioningE2E(t *testing.T) {
t.Parallel()
selector := OsSelector("ubuntu", "centos")
params := getVSphereTestParams(t)
runScenarios(t, selector, params, VSPhereDSCManifest, fmt.Sprintf("vs-dsc-%s", *testRunIdentifier))
}
// TestVsphereResourcePoolProvisioning - creates a machine deployment using a
// resource pool.
func TestVsphereResourcePoolProvisioningE2E(t *testing.T) {
t.Parallel()
params := getVSphereTestParams(t)
// We do not need to test all combinations.
scenario := scenario{
name: "vSphere resource pool provisioning",
osName: "flatcar",
containerRuntime: "docker",
kubernetesVersion: "1.17.0",
executor: verifyCreateAndDelete,
}
testScenario(t, scenario, *testRunIdentifier, params, VSPhereResourcePoolManifest, false)
}
// TestScalewayProvisioning - a test suite that exercises scaleway provider
// by requesting nodes with different combination of container runtime type, container runtime version and the OS flavour.
//
// note that tests require the following environment variable:
// - SCW_ACCESS_KEY -> the Scaleway Access Key
// - SCW_SECRET_KEY -> the Scaleway Secret Key
// - SCW_DEFAULT_PROJECT_ID -> the Scaleway Project ID
func TestScalewayProvisioningE2E(t *testing.T) {
t.Parallel()
// test data
scwAccessKey := os.Getenv("SCW_ACCESS_KEY")
if len(scwAccessKey) == 0 {
t.Fatal("unable to run the test suite, SCW_E2E_TEST_ACCESS_KEY environment variable cannot be empty")
}
scwSecretKey := os.Getenv("SCW_SECRET_KEY")
if len(scwSecretKey) == 0 {
t.Fatal("unable to run the test suite, SCW_E2E_TEST_SECRET_KEY environment variable cannot be empty")
}
scwProjectID := os.Getenv("SCW_DEFAULT_PROJECT_ID")
if len(scwProjectID) == 0 {
t.Fatal("unable to run the test suite, SCW_E2E_TEST_PROJECT_ID environment variable cannot be empty")
}
selector := Not(OsSelector("sles", "rhel", "flatcar"))
// act
params := []string{
fmt.Sprintf("<< SCW_ACCESS_KEY >>=%s", scwAccessKey),
fmt.Sprintf("<< SCW_SECRET_KEY >>=%s", scwSecretKey),
fmt.Sprintf("<< SCW_DEFAULT_PROJECT_ID >>=%s", scwProjectID),
}
runScenarios(t, selector, params, ScalewayManifest, fmt.Sprintf("scw-%s", *testRunIdentifier))
}
// TestUbuntuProvisioningWithUpgradeE2E will create an instance from an old Ubuntu 1604
// image and upgrade it prior to joining the cluster
func TestUbuntuProvisioningWithUpgradeE2E(t *testing.T) {
t.Parallel()
osAuthURL := os.Getenv("OS_AUTH_URL")
osDomain := os.Getenv("OS_DOMAIN")
osPassword := os.Getenv("OS_PASSWORD")
osRegion := os.Getenv("OS_REGION")
osUsername := os.Getenv("OS_USERNAME")
osTenant := os.Getenv("OS_TENANT_NAME")
osNetwork := os.Getenv("OS_NETWORK_NAME")
if osAuthURL == "" || osUsername == "" || osPassword == "" || osDomain == "" || osRegion == "" || osTenant == "" {
t.Fatal("unable to run test suite, all of OS_AUTH_URL, OS_USERNAME, OS_PASSOWRD, OS_REGION, and OS_TENANT OS_DOMAIN must be set!")
}
params := []string{
fmt.Sprintf("<< IDENTITY_ENDPOINT >>=%s", osAuthURL),
fmt.Sprintf("<< USERNAME >>=%s", osUsername),
fmt.Sprintf("<< PASSWORD >>=%s", osPassword),
fmt.Sprintf("<< DOMAIN_NAME >>=%s", osDomain),
fmt.Sprintf("<< REGION >>=%s", osRegion),
fmt.Sprintf("<< TENANT_NAME >>=%s", osTenant),
fmt.Sprintf("<< NETWORK_NAME >>=%s", osNetwork),
}
scenario := scenario{
name: "Ubuntu upgrade",
osName: "ubuntu",
containerRuntime: "docker",
kubernetesVersion: "1.16.2",
executor: verifyCreateAndDelete,
}
testScenario(t, scenario, *testRunIdentifier, params, OSUpgradeManifest, false)
}
// TestDeploymentControllerUpgradesMachineE2E verifies the machineDeployment controller correctly
// rolls over machines on changes in the machineDeployment
func TestDeploymentControllerUpgradesMachineE2E(t *testing.T) {
t.Parallel()
// test data
hzToken := os.Getenv("HZ_E2E_TOKEN")
if len(hzToken) == 0 {
t.Fatal("unable to run the test suite, HZ_E2E_TOKEN environment variable cannot be empty")
}
// act
params := []string{fmt.Sprintf("<< HETZNER_TOKEN >>=%s", hzToken)}
scenario := scenario{
name: "MachineDeployment upgrade",
osName: "ubuntu",
containerRuntime: "docker",
kubernetesVersion: "1.16.2",
executor: verifyCreateUpdateAndDelete,
}
testScenario(t, scenario, *testRunIdentifier, params, HZManifest, false)
}
func TestAnexiaProvisioningE2E(t *testing.T) {
t.Parallel()
token := os.Getenv("ANEXIA_TOKEN")
if token == "" {
t.Fatal("unable to run the test suite, ANEXIA_TOKEN environment variable cannot be empty")
}
selector := OsSelector("flatcar")
params := []string{
fmt.Sprintf("<< ANEXIA_TOKEN >>=%s", token),
}
runScenarios(t, selector, params, anexiaManifest, fmt.Sprintf("anexia-%s", *testRunIdentifier))
}