forked from Azure/aks-engine
/
defaults_test.go
1399 lines (1277 loc) · 65.3 KB
/
defaults_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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package api
import (
"encoding/base64"
"encoding/binary"
"net"
"reflect"
"testing"
"github.com/Azure/go-autorest/autorest/to"
)
func TestCertsAlreadyPresent(t *testing.T) {
var cert *CertificateProfile
result := certsAlreadyPresent(nil, 1)
expected := map[string]bool{
"ca": false,
"apiserver": false,
"client": false,
"kubeconfig": false,
"etcd": false,
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("certsAlreadyPresent() did not return false for all certs for a non-existent CertificateProfile")
}
cert = &CertificateProfile{}
result = certsAlreadyPresent(cert, 1)
expected = map[string]bool{
"ca": false,
"apiserver": false,
"client": false,
"kubeconfig": false,
"etcd": false,
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("certsAlreadyPresent() did not return false for all certs for empty CertificateProfile")
}
cert = &CertificateProfile{
APIServerCertificate: "a",
}
result = certsAlreadyPresent(cert, 1)
expected = map[string]bool{
"ca": false,
"apiserver": false,
"client": false,
"kubeconfig": false,
"etcd": false,
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("certsAlreadyPresent() did not return false for all certs for 1 cert in CertificateProfile")
}
cert = &CertificateProfile{
APIServerCertificate: "a",
CaCertificate: "c",
CaPrivateKey: "d",
ClientCertificate: "e",
ClientPrivateKey: "f",
KubeConfigCertificate: "g",
KubeConfigPrivateKey: "h",
EtcdClientCertificate: "i",
EtcdClientPrivateKey: "j",
EtcdServerCertificate: "k",
EtcdServerPrivateKey: "l",
}
result = certsAlreadyPresent(cert, 3)
expected = map[string]bool{
"ca": true,
"apiserver": false,
"client": true,
"kubeconfig": true,
"etcd": false,
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("certsAlreadyPresent() did not return expected result for some certs in CertificateProfile")
}
cert = &CertificateProfile{
APIServerCertificate: "a",
APIServerPrivateKey: "b",
CaCertificate: "c",
CaPrivateKey: "d",
ClientCertificate: "e",
ClientPrivateKey: "f",
KubeConfigCertificate: "g",
KubeConfigPrivateKey: "h",
EtcdClientCertificate: "i",
EtcdClientPrivateKey: "j",
EtcdServerCertificate: "k",
EtcdServerPrivateKey: "l",
EtcdPeerCertificates: []string{"0", "1", "2"},
EtcdPeerPrivateKeys: []string{"0", "1", "2"},
}
result = certsAlreadyPresent(cert, 3)
expected = map[string]bool{
"ca": true,
"apiserver": true,
"client": true,
"kubeconfig": true,
"etcd": true,
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("certsAlreadyPresent() did not return expected result for all certs in CertificateProfile")
}
}
func TestSetMissingKubeletValues(t *testing.T) {
config := &KubernetesConfig{}
defaultKubeletConfig := map[string]string{
"--network-plugin": "1",
"--pod-infra-container-image": "2",
"--max-pods": "3",
"--eviction-hard": "4",
"--node-status-update-frequency": "5",
"--image-gc-high-threshold": "6",
"--image-gc-low-threshold": "7",
"--non-masquerade-cidr": "8",
"--cloud-provider": "9",
"--pod-max-pids": "10",
}
setMissingKubeletValues(config, defaultKubeletConfig)
for key, val := range defaultKubeletConfig {
if config.KubeletConfig[key] != val {
t.Fatalf("setMissingKubeletValue() did not return the expected value %s for key %s, instead returned: %s", val, key, config.KubeletConfig[key])
}
}
config = &KubernetesConfig{
KubeletConfig: map[string]string{
"--network-plugin": "a",
"--pod-infra-container-image": "b",
"--cloud-provider": "c",
},
}
expectedResult := map[string]string{
"--network-plugin": "a",
"--pod-infra-container-image": "b",
"--max-pods": "3",
"--eviction-hard": "4",
"--node-status-update-frequency": "5",
"--image-gc-high-threshold": "6",
"--image-gc-low-threshold": "7",
"--non-masquerade-cidr": "8",
"--cloud-provider": "c",
"--pod-max-pids": "10",
}
setMissingKubeletValues(config, defaultKubeletConfig)
for key, val := range expectedResult {
if config.KubeletConfig[key] != val {
t.Fatalf("setMissingKubeletValue() did not return the expected value %s for key %s, instead returned: %s", val, key, config.KubeletConfig[key])
}
}
config = &KubernetesConfig{
KubeletConfig: map[string]string{},
}
setMissingKubeletValues(config, defaultKubeletConfig)
for key, val := range defaultKubeletConfig {
if config.KubeletConfig[key] != val {
t.Fatalf("setMissingKubeletValue() did not return the expected value %s for key %s, instead returned: %s", val, key, config.KubeletConfig[key])
}
}
}
func TestAddonsIndexByName(t *testing.T) {
addonName := "testaddon"
addons := []KubernetesAddon{
getMockAddon(addonName),
}
i := getAddonsIndexByName(addons, addonName)
if i != 0 {
t.Fatalf("addonsIndexByName() did not return the expected index value 0, instead returned: %d", i)
}
i = getAddonsIndexByName(addons, "nonExistentAddonName")
if i != -1 {
t.Fatalf("addonsIndexByName() did not return -1 for a non-existent addon, instead returned: %d", i)
}
}
func TestAssignDefaultAddonImages(t *testing.T) {
addonContainerMap := map[string]string{
DefaultTillerAddonName: "gcr.io/kubernetes-helm/tiller:v2.11.0",
DefaultACIConnectorAddonName: "microsoft/virtual-kubelet:latest",
DefaultClusterAutoscalerAddonName: "k8s.gcr.io/cluster-autoscaler:v1.2.2",
DefaultBlobfuseFlexVolumeAddonName: "mcr.microsoft.com/k8s/flexvolume/blobfuse-flexvolume:1.0.7",
DefaultSMBFlexVolumeAddonName: "mcr.microsoft.com/k8s/flexvolume/smb-flexvolume:1.0.2",
DefaultKeyVaultFlexVolumeAddonName: "mcr.microsoft.com/k8s/flexvolume/keyvault-flexvolume:v0.0.5",
DefaultDashboardAddonName: "k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1",
DefaultReschedulerAddonName: "k8s.gcr.io/rescheduler:v0.3.1",
DefaultMetricsServerAddonName: "k8s.gcr.io/metrics-server-amd64:v0.2.1",
NVIDIADevicePluginAddonName: "nvidia/k8s-device-plugin:1.10",
ContainerMonitoringAddonName: "microsoft/oms:ciprod01092019",
IPMASQAgentAddonName: "k8s.gcr.io/ip-masq-agent-amd64:v2.0.0",
AzureCNINetworkMonitoringAddonName: "containernetworking/networkmonitor:v0.0.4",
DefaultDNSAutoscalerAddonName: "k8s.gcr.io/cluster-proportional-autoscaler-amd64:1.1.1",
DefaultHeapsterAddonName: "k8s.gcr.io/heapster-amd64:v1.5.4",
}
var addons []KubernetesAddon
for addonName := range addonContainerMap {
containerName := addonName
if addonName == ContainerMonitoringAddonName {
containerName = "omsagent"
}
customAddon := KubernetesAddon{
Name: addonName,
Enabled: to.BoolPtr(true),
Containers: []KubernetesContainerSpec{
{
Name: containerName,
CPURequests: "50m",
MemoryRequests: "150Mi",
CPULimits: "50m",
MemoryLimits: "150Mi",
},
},
}
addons = append(addons, customAddon)
}
mockCS := getMockBaseContainerService("1.10.8")
mockCS.Properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
mockCS.Properties.OrchestratorProfile.KubernetesConfig.Addons = addons
mockCS.SetPropertiesDefaults(false, false)
modifiedAddons := mockCS.Properties.OrchestratorProfile.KubernetesConfig.Addons
for _, addon := range modifiedAddons {
expected := addonContainerMap[addon.Name]
actual := addon.Containers[0].Image
if actual != expected {
t.Errorf("expected setDefaults to set Image %s in addon %s, but got %s", expected, addon.Name, actual)
}
}
}
func TestAssignDefaultAddonVals(t *testing.T) {
addonName := "testaddon"
customImage := "myimage"
customCPURequests := "60m"
customMemoryRequests := "160Mi"
customCPULimits := "40m"
customMemoryLimits := "140Mi"
// Verify that an addon with all custom values provided remains unmodified during default value assignment
customAddon := KubernetesAddon{
Name: addonName,
Enabled: to.BoolPtr(true),
Containers: []KubernetesContainerSpec{
{
Name: addonName,
Image: customImage,
CPURequests: customCPURequests,
MemoryRequests: customMemoryRequests,
CPULimits: customCPULimits,
MemoryLimits: customMemoryLimits,
},
},
}
addonWithDefaults := getMockAddon(addonName)
isUpdate := false
modifiedAddon := assignDefaultAddonVals(customAddon, addonWithDefaults, isUpdate)
if modifiedAddon.Containers[0].Name != customAddon.Containers[0].Name {
t.Fatalf("assignDefaultAddonVals() should not have modified Containers 'Name' value %s to %s,", customAddon.Containers[0].Name, modifiedAddon.Containers[0].Name)
}
if modifiedAddon.Containers[0].Image != customAddon.Containers[0].Image {
t.Fatalf("assignDefaultAddonVals() should not have modified Containers 'Image' value %s to %s,", customAddon.Containers[0].Image, modifiedAddon.Containers[0].Image)
}
if modifiedAddon.Containers[0].CPURequests != customAddon.Containers[0].CPURequests {
t.Fatalf("assignDefaultAddonVals() should not have modified Containers 'CPURequests' value %s to %s,", customAddon.Containers[0].CPURequests, modifiedAddon.Containers[0].CPURequests)
}
if modifiedAddon.Containers[0].MemoryRequests != customAddon.Containers[0].MemoryRequests {
t.Fatalf("assignDefaultAddonVals() should not have modified Containers 'MemoryRequests' value %s to %s,", customAddon.Containers[0].MemoryRequests, modifiedAddon.Containers[0].MemoryRequests)
}
if modifiedAddon.Containers[0].CPULimits != customAddon.Containers[0].CPULimits {
t.Fatalf("assignDefaultAddonVals() should not have modified Containers 'CPULimits' value %s to %s,", customAddon.Containers[0].CPULimits, modifiedAddon.Containers[0].CPULimits)
}
if modifiedAddon.Containers[0].MemoryLimits != customAddon.Containers[0].MemoryLimits {
t.Fatalf("assignDefaultAddonVals() should not have modified Containers 'MemoryLimits' value %s to %s,", customAddon.Containers[0].MemoryLimits, modifiedAddon.Containers[0].MemoryLimits)
}
// Verify that an addon with no custom values provided gets all the appropriate defaults
customAddon = KubernetesAddon{
Name: addonName,
Enabled: to.BoolPtr(true),
Containers: []KubernetesContainerSpec{
{
Name: addonName,
},
},
}
isUpdate = false
modifiedAddon = assignDefaultAddonVals(customAddon, addonWithDefaults, isUpdate)
if modifiedAddon.Containers[0].Image != addonWithDefaults.Containers[0].Image {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'Image' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].Image, modifiedAddon.Containers[0].Image)
}
if modifiedAddon.Containers[0].CPURequests != addonWithDefaults.Containers[0].CPURequests {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'CPURequests' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].CPURequests, modifiedAddon.Containers[0].CPURequests)
}
if modifiedAddon.Containers[0].MemoryRequests != addonWithDefaults.Containers[0].MemoryRequests {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'MemoryRequests' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].MemoryRequests, modifiedAddon.Containers[0].MemoryRequests)
}
if modifiedAddon.Containers[0].CPULimits != addonWithDefaults.Containers[0].CPULimits {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'CPULimits' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].CPULimits, modifiedAddon.Containers[0].CPULimits)
}
if modifiedAddon.Containers[0].MemoryLimits != addonWithDefaults.Containers[0].MemoryLimits {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'MemoryLimits' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].MemoryLimits, modifiedAddon.Containers[0].MemoryLimits)
}
// More checking to verify default interpolation
customAddon = KubernetesAddon{
Name: addonName,
Enabled: to.BoolPtr(true),
Containers: []KubernetesContainerSpec{
{
Name: addonName,
CPURequests: customCPURequests,
MemoryLimits: customMemoryLimits,
},
},
}
isUpdate = false
modifiedAddon = assignDefaultAddonVals(customAddon, addonWithDefaults, isUpdate)
if modifiedAddon.Containers[0].Image != addonWithDefaults.Containers[0].Image {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'Image' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].Image, modifiedAddon.Containers[0].Image)
}
if modifiedAddon.Containers[0].Name != customAddon.Containers[0].Name {
t.Fatalf("assignDefaultAddonVals() should not have modified Containers 'Name' value %s to %s,", customAddon.Containers[0].Name, modifiedAddon.Containers[0].Name)
}
if modifiedAddon.Containers[0].MemoryRequests != addonWithDefaults.Containers[0].MemoryRequests {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'MemoryRequests' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].MemoryRequests, modifiedAddon.Containers[0].MemoryRequests)
}
if modifiedAddon.Containers[0].CPULimits != addonWithDefaults.Containers[0].CPULimits {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'CPULimits' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].CPULimits, modifiedAddon.Containers[0].CPULimits)
}
if modifiedAddon.Containers[0].MemoryLimits != customAddon.Containers[0].MemoryLimits {
t.Fatalf("assignDefaultAddonVals() should not have modified Containers 'MemoryLimits' value %s to %s,", customAddon.Containers[0].MemoryLimits, modifiedAddon.Containers[0].MemoryLimits)
}
// Verify that an addon with a custom image value will be overridden during upgrade/scale
customAddon = KubernetesAddon{
Name: addonName,
Enabled: to.BoolPtr(true),
Containers: []KubernetesContainerSpec{
{
Name: addonName,
Image: customImage,
},
},
}
isUpdate = true
modifiedAddon = assignDefaultAddonVals(customAddon, addonWithDefaults, isUpdate)
if modifiedAddon.Containers[0].Image != addonWithDefaults.Containers[0].Image {
t.Fatalf("assignDefaultAddonVals() should have assigned a default 'Image' value of %s, instead assigned %s,", addonWithDefaults.Containers[0].Image, modifiedAddon.Containers[0].Image)
}
addonWithDefaults.Config = map[string]string{
"os": "Linux",
"taint": "node.kubernetes.io/memory-pressure",
}
isUpdate = false
modifiedAddon = assignDefaultAddonVals(customAddon, addonWithDefaults, isUpdate)
if modifiedAddon.Config["os"] != "Linux" {
t.Error("assignDefaultAddonVals() should have added the default config property")
}
if modifiedAddon.Config["taint"] != "node.kubernetes.io/memory-pressure" {
t.Error("assignDefaultAddonVals() should have added the default config property")
}
}
func TestAcceleratedNetworking(t *testing.T) {
mockCS := getMockBaseContainerService("1.10.8")
mockCS.Properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled = nil
mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows = nil
isUpgrade := true
mockCS.SetPropertiesDefaults(isUpgrade, false)
// In upgrade scenario, nil AcceleratedNetworkingEnabled should always render as false (i.e., we never turn on this feature on an existing vm that didn't have it before)
if to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled) {
t.Errorf("expected nil acceleratedNetworkingEnabled to be false after upgrade, instead got %t", to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled))
}
// In upgrade scenario, nil AcceleratedNetworkingEnabledWindows should always render as false (i.e., we never turn on this feature on an existing vm that didn't have it before)
if to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows) {
t.Errorf("expected nil acceleratedNetworkingEnabledWindows to be false after upgrade, instead got %t", to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows))
}
mockCS = getMockBaseContainerService("1.10.8")
mockCS.Properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled = nil
mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows = nil
isScale := true
mockCS.SetPropertiesDefaults(false, isScale)
// In scale scenario, nil AcceleratedNetworkingEnabled should always render as false (i.e., we never turn on this feature on an existing agent pool / vmss that didn't have it before)
if to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled) {
t.Errorf("expected nil acceleratedNetworkingEnabled to be false after upgrade, instead got %t", to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled))
}
// In scale scenario, nil AcceleratedNetworkingEnabledWindows should always render as false (i.e., we never turn on this feature on an existing vm that didn't have it before)
if to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows) {
t.Errorf("expected nil acceleratedNetworkingEnabledWindows to be false after upgrade, instead got %t", to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows))
}
mockCS = getMockBaseContainerService("1.10.8")
mockCS.Properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled = nil
mockCS.Properties.AgentPoolProfiles[0].VMSize = "Standard_D2_v2"
mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows = nil
mockCS.Properties.AgentPoolProfiles[0].VMSize = "Standard_D2_v2"
mockCS.SetPropertiesDefaults(false, false)
// In create scenario, nil AcceleratedNetworkingEnabled should be the defaults
acceleratedNetworkingEnabled := DefaultAcceleratedNetworking
if to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled) != acceleratedNetworkingEnabled {
t.Errorf("expected default acceleratedNetworkingEnabled to be %t, instead got %t", acceleratedNetworkingEnabled, to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled))
}
// In create scenario, nil AcceleratedNetworkingEnabledWindows should be the defaults
acceleratedNetworkingEnabled = DefaultAcceleratedNetworkingWindowsEnabled
if to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows) != acceleratedNetworkingEnabled {
t.Errorf("expected default acceleratedNetworkingEnabledWindows to be %t, instead got %t", acceleratedNetworkingEnabled, to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows))
}
mockCS = getMockBaseContainerService("1.10.8")
mockCS.Properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled = nil
mockCS.Properties.AgentPoolProfiles[0].VMSize = "Standard_D666_v2"
mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows = nil
mockCS.Properties.AgentPoolProfiles[0].VMSize = "Standard_D666_v2"
mockCS.SetPropertiesDefaults(false, false)
// In non-supported VM SKU scenario, acceleratedNetworkingEnabled should always be false
if to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled) {
t.Errorf("expected acceleratedNetworkingEnabled to be %t for an unsupported VM SKU, instead got %t", false, to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabled))
}
// In non-supported VM SKU scenario, acceleratedNetworkingEnabledWindows should always be false
if to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows) {
t.Errorf("expected acceleratedNetworkingEnabledWindows to be %t for an unsupported VM SKU, instead got %t", false, to.Bool(mockCS.Properties.AgentPoolProfiles[0].AcceleratedNetworkingEnabledWindows))
}
}
func TestKubeletFeatureGatesEnsureFeatureGatesOnAgentsFor1_6_0(t *testing.T) {
mockCS := getMockBaseContainerService("1.6.0")
properties := mockCS.Properties
// No KubernetesConfig.KubeletConfig set for MasterProfile or AgentProfile
// so they will inherit the top-level config
properties.OrchestratorProfile.KubernetesConfig = getKubernetesConfigWithFeatureGates("TopLevel=true")
mockCS.setKubeletConfig()
agentFeatureGates := properties.AgentPoolProfiles[0].KubernetesConfig.KubeletConfig["--feature-gates"]
if agentFeatureGates != "TopLevel=true" {
t.Fatalf("setKubeletConfig did not add 'TopLevel=true' for agent profile: expected 'TopLevel=true' got '%s'", agentFeatureGates)
}
// Verify that the TopLevel feature gate override has only been applied to the agents
masterFeatureFates := properties.MasterProfile.KubernetesConfig.KubeletConfig["--feature-gates"]
if masterFeatureFates != "TopLevel=true" {
t.Fatalf("setKubeletConfig modified feature gates for master profile: expected 'TopLevel=true' got '%s'", agentFeatureGates)
}
}
func TestKubeletFeatureGatesEnsureMasterAndAgentConfigUsedFor1_6_0(t *testing.T) {
mockCS := getMockBaseContainerService("1.6.0")
properties := mockCS.Properties
// Set MasterProfile and AgentProfiles KubernetesConfig.KubeletConfig values
// Verify that they are used instead of the top-level config
properties.OrchestratorProfile.KubernetesConfig = getKubernetesConfigWithFeatureGates("TopLevel=true")
properties.MasterProfile = &MasterProfile{KubernetesConfig: getKubernetesConfigWithFeatureGates("MasterLevel=true")}
properties.AgentPoolProfiles[0].KubernetesConfig = getKubernetesConfigWithFeatureGates("AgentLevel=true")
mockCS.setKubeletConfig()
agentFeatureGates := properties.AgentPoolProfiles[0].KubernetesConfig.KubeletConfig["--feature-gates"]
if agentFeatureGates != "AgentLevel=true" {
t.Fatalf("setKubeletConfig agent profile: expected 'AgentLevel=true' got '%s'", agentFeatureGates)
}
// Verify that the TopLevel feature gate override has only been applied to the agents
masterFeatureFates := properties.MasterProfile.KubernetesConfig.KubeletConfig["--feature-gates"]
if masterFeatureFates != "MasterLevel=true" {
t.Fatalf("setKubeletConfig master profile: expected 'MasterLevel=true' got '%s'", agentFeatureGates)
}
}
func TestEtcdDiskSize(t *testing.T) {
mockCS := getMockBaseContainerService("1.8.10")
properties := mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 1
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB != DefaultEtcdDiskSize {
t.Fatalf("EtcdDiskSizeGB did not have the expected size, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB, DefaultEtcdDiskSize)
}
mockCS = getMockBaseContainerService("1.8.10")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 5
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB != DefaultEtcdDiskSizeGT3Nodes {
t.Fatalf("EtcdDiskSizeGB did not have the expected size, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB, DefaultEtcdDiskSizeGT3Nodes)
}
mockCS = getMockBaseContainerService("1.8.10")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 5
properties.AgentPoolProfiles[0].Count = 6
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB != DefaultEtcdDiskSizeGT10Nodes {
t.Fatalf("EtcdDiskSizeGB did not have the expected size, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB, DefaultEtcdDiskSizeGT10Nodes)
}
mockCS = getMockBaseContainerService("1.8.10")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 5
properties.AgentPoolProfiles[0].Count = 16
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB != DefaultEtcdDiskSizeGT20Nodes {
t.Fatalf("EtcdDiskSizeGB did not have the expected size, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB, DefaultEtcdDiskSizeGT20Nodes)
}
mockCS = getMockBaseContainerService("1.8.10")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 5
properties.AgentPoolProfiles[0].Count = 50
customEtcdDiskSize := "512"
properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB = customEtcdDiskSize
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB != customEtcdDiskSize {
t.Fatalf("EtcdDiskSizeGB did not have the expected size, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB, customEtcdDiskSize)
}
}
func TestGenerateEtcdEncryptionKey(t *testing.T) {
key1 := generateEtcdEncryptionKey()
key2 := generateEtcdEncryptionKey()
if key1 == key2 {
t.Fatalf("generateEtcdEncryptionKey should return a unique key each time, instead returned identical %s and %s", key1, key2)
}
for _, val := range []string{key1, key2} {
_, err := base64.StdEncoding.DecodeString(val)
if err != nil {
t.Fatalf("generateEtcdEncryptionKey should return a base64 encoded key, instead returned %s", val)
}
}
}
func TestNetworkPolicyDefaults(t *testing.T) {
mockCS := getMockBaseContainerService("1.8.10")
properties := mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy = "calico"
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin != "kubenet" {
t.Fatalf("NetworkPlugin did not have the expected value, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin, "kubenet")
}
mockCS = getMockBaseContainerService("1.8.10")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy = "cilium"
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin != "cilium" {
t.Fatalf("NetworkPlugin did not have the expected value, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin, "cilium")
}
mockCS = getMockBaseContainerService("1.8.10")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy = "azure"
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin != "azure" {
t.Fatalf("NetworkPlugin did not have the expected value, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin, "azure")
}
if properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy != "" {
t.Fatalf("NetworkPolicy did not have the expected value, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy, "")
}
mockCS = getMockBaseContainerService("1.8.10")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy = "none"
mockCS.setOrchestratorDefaults(true)
if properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin != "kubenet" {
t.Fatalf("NetworkPlugin did not have the expected value, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin, "kubenet")
}
if properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy != "" {
t.Fatalf("NetworkPolicy did not have the expected value, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy, "")
}
}
func TestStorageProfile(t *testing.T) {
// Test ManagedDisks default configuration
mockCS := getMockBaseContainerService("1.8.10")
properties := mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 1
properties.OrchestratorProfile.KubernetesConfig.PrivateCluster = &PrivateCluster{
Enabled: to.BoolPtr(true),
JumpboxProfile: &PrivateJumpboxProfile{},
}
mockCS.SetPropertiesDefaults(false, false)
if properties.MasterProfile.StorageProfile != ManagedDisks {
t.Fatalf("MasterProfile.StorageProfile did not have the expected configuration, got %s, expected %s",
properties.MasterProfile.StorageProfile, ManagedDisks)
}
if !properties.MasterProfile.IsManagedDisks() {
t.Fatalf("MasterProfile.StorageProfile did not have the expected configuration, got %t, expected %t",
false, true)
}
if properties.AgentPoolProfiles[0].StorageProfile != ManagedDisks {
t.Fatalf("AgentPoolProfile.StorageProfile did not have the expected configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].StorageProfile, ManagedDisks)
}
if !properties.AgentPoolProfiles[0].IsManagedDisks() {
t.Fatalf("AgentPoolProfile.IsManagedDisks() did not have the expected configuration, got %t, expected %t",
false, true)
}
if properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.StorageProfile != ManagedDisks {
t.Fatalf("MasterProfile.StorageProfile did not have the expected configuration, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.StorageProfile, ManagedDisks)
}
if !properties.AgentPoolProfiles[0].IsAvailabilitySets() {
t.Fatalf("AgentPoolProfile[0].AvailabilityProfile did not have the expected configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].AvailabilityProfile, AvailabilitySet)
}
mockCS = getMockBaseContainerService("1.10.2")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
mockCS.SetPropertiesDefaults(false, false)
if !properties.AgentPoolProfiles[0].IsVirtualMachineScaleSets() {
t.Fatalf("AgentPoolProfile[0].AvailabilityProfile did not have the expected configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].AvailabilityProfile, VirtualMachineScaleSets)
}
}
// TestMasterProfileDefaults covers tests for setMasterProfileDefaults
func TestMasterProfileDefaults(t *testing.T) {
// this validates default masterProfile configuration
mockCS := getMockBaseContainerService("1.10.3")
properties := mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet = ""
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = "azure"
properties.MasterProfile.AvailabilityProfile = ""
properties.MasterProfile.Count = 3
mockCS.Properties = properties
mockCS.SetPropertiesDefaults(false, false)
if properties.MasterProfile.IsVirtualMachineScaleSets() {
t.Fatalf("Master VMAS, AzureCNI: MasterProfile AvailabilityProfile did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.AvailabilityProfile, AvailabilitySet)
}
if properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet != DefaultKubernetesSubnet {
t.Fatalf("Master VMAS, AzureCNI: MasterProfile ClusterSubnet did not have the expected default configuration, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet, DefaultKubernetesSubnet)
}
if properties.MasterProfile.Subnet != properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet {
t.Fatalf("Master VMAS, AzureCNI: MasterProfile Subnet did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.Subnet, properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet)
}
if properties.AgentPoolProfiles[0].Subnet != properties.MasterProfile.Subnet {
t.Fatalf("Master VMAS, AzureCNI: AgentPoolProfiles Subnet did not have the expected default configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].Subnet, properties.MasterProfile.Subnet)
}
if properties.MasterProfile.FirstConsecutiveStaticIP != "10.255.255.5" {
t.Fatalf("Master VMAS, AzureCNI: MasterProfile FirstConsecutiveStaticIP did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.FirstConsecutiveStaticIP, "10.255.255.5")
}
// this validates default vmss masterProfile configuration
mockCS = getMockBaseContainerService("1.10.3")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = "azure"
properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet = ""
properties.MasterProfile.AvailabilityProfile = VirtualMachineScaleSets
mockCS.SetPropertiesDefaults(false, true)
if !properties.MasterProfile.IsVirtualMachineScaleSets() {
t.Fatalf("Master VMSS, AzureCNI: MasterProfile AvailabilityProfile did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.AvailabilityProfile, VirtualMachineScaleSets)
}
if properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet != DefaultKubernetesSubnet {
t.Fatalf("Master VMSS, AzureCNI: MasterProfile ClusterSubnet did not have the expected default configuration, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet, DefaultKubernetesSubnet)
}
if properties.MasterProfile.FirstConsecutiveStaticIP != DefaultFirstConsecutiveKubernetesStaticIPVMSS {
t.Fatalf("Master VMSS, AzureCNI: MasterProfile FirstConsecutiveStaticIP did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.FirstConsecutiveStaticIP, DefaultFirstConsecutiveKubernetesStaticIPVMSS)
}
if properties.MasterProfile.Subnet != DefaultKubernetesMasterSubnet {
t.Fatalf("Master VMSS, AzureCNI: MasterProfile Subnet did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.Subnet, DefaultKubernetesMasterSubnet)
}
if properties.MasterProfile.AgentSubnet != DefaultKubernetesAgentSubnetVMSS {
t.Fatalf("Master VMSS, AzureCNI: MasterProfile AgentSubnet did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.AgentSubnet, DefaultKubernetesAgentSubnetVMSS)
}
// this validates default masterProfile configuration and kubenet
mockCS = getMockBaseContainerService("1.10.3")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet = ""
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = "kubenet"
properties.MasterProfile.AvailabilityProfile = VirtualMachineScaleSets
mockCS.SetPropertiesDefaults(false, true)
if properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet != DefaultKubernetesClusterSubnet {
t.Fatalf("Master VMSS, kubenet: MasterProfile ClusterSubnet did not have the expected default configuration, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet, DefaultKubernetesClusterSubnet)
}
if properties.MasterProfile.Subnet != DefaultKubernetesMasterSubnet {
t.Fatalf("Master VMSS, kubenet: MasterProfile Subnet did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.Subnet, DefaultKubernetesMasterSubnet)
}
if properties.MasterProfile.FirstConsecutiveStaticIP != DefaultFirstConsecutiveKubernetesStaticIPVMSS {
t.Fatalf("Master VMSS, kubenet: MasterProfile FirstConsecutiveStaticIP did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.FirstConsecutiveStaticIP, DefaultFirstConsecutiveKubernetesStaticIPVMSS)
}
if properties.MasterProfile.AgentSubnet != DefaultKubernetesAgentSubnetVMSS {
t.Fatalf("Master VMSS, kubenet: MasterProfile AgentSubnet did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.AgentSubnet, DefaultKubernetesAgentSubnetVMSS)
}
properties.MasterProfile.AvailabilityProfile = AvailabilitySet
mockCS.SetPropertiesDefaults(false, true)
if properties.MasterProfile.FirstConsecutiveStaticIP != DefaultFirstConsecutiveKubernetesStaticIP {
t.Fatalf("Master VMAS, kubenet: MasterProfile FirstConsecutiveStaticIP did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.FirstConsecutiveStaticIP, DefaultFirstConsecutiveKubernetesStaticIP)
}
// this validates default vmas masterProfile configuration, AzureCNI, and custom vnet
mockCS = getMockBaseContainerService("1.10.3")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.VnetSubnetID = "/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Network/virtualNetworks/ExampleCustomVNET/subnets/ExampleMasterSubnet"
properties.MasterProfile.VnetCidr = "10.239.0.0/16"
properties.MasterProfile.FirstConsecutiveStaticIP = "10.239.255.239"
properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet = ""
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = "azure"
properties.MasterProfile.AvailabilityProfile = AvailabilitySet
mockCS.SetPropertiesDefaults(false, true)
if properties.MasterProfile.FirstConsecutiveStaticIP != "10.239.255.239" {
t.Fatalf("Master VMAS, AzureCNI, customvnet: MasterProfile FirstConsecutiveStaticIP did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.FirstConsecutiveStaticIP, "10.239.255.239")
}
// this validates default vmss masterProfile configuration, AzureCNI, and custom vnet
mockCS = getMockBaseContainerService("1.10.3")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.VnetSubnetID = "/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Network/virtualNetworks/ExampleCustomVNET/subnets/ExampleMasterSubnet"
properties.MasterProfile.VnetCidr = "10.239.0.0/16"
properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet = ""
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = "azure"
properties.MasterProfile.AvailabilityProfile = VirtualMachineScaleSets
mockCS.SetPropertiesDefaults(false, true)
if properties.MasterProfile.FirstConsecutiveStaticIP != "10.239.0.4" {
t.Fatalf("Master VMSS, AzureCNI, customvnet: MasterProfile FirstConsecutiveStaticIP did not have the expected default configuration, got %s, expected %s",
properties.MasterProfile.FirstConsecutiveStaticIP, "10.239.0.4")
}
// this validates default configurations for LoadBalancerSku and ExcludeMasterFromStandardLB
mockCS = getMockBaseContainerService("1.11.6")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku = "Standard"
mockCS.SetPropertiesDefaults(false, false)
excludeMaster := DefaultExcludeMasterFromStandardLB
if *properties.OrchestratorProfile.KubernetesConfig.ExcludeMasterFromStandardLB != excludeMaster {
t.Fatalf("OrchestratorProfile.KubernetesConfig.ExcludeMasterFromStandardLB did not have the expected configuration, got %t, expected %t",
*properties.OrchestratorProfile.KubernetesConfig.ExcludeMasterFromStandardLB, excludeMaster)
}
// this validates default configurations for MaximumLoadBalancerRuleCount.
mockCS = getMockBaseContainerService("1.11.6")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
mockCS.SetPropertiesDefaults(false, false)
if properties.OrchestratorProfile.KubernetesConfig.MaximumLoadBalancerRuleCount != DefaultMaximumLoadBalancerRuleCount {
t.Fatalf("OrchestratorProfile.KubernetesConfig.MaximumLoadBalancerRuleCount did not have the expected configuration, got %d, expected %d",
properties.OrchestratorProfile.KubernetesConfig.MaximumLoadBalancerRuleCount, DefaultMaximumLoadBalancerRuleCount)
}
}
func TestAgentPoolProfile(t *testing.T) {
mockCS := getMockBaseContainerService("1.10")
properties := mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 1
mockCS.SetPropertiesDefaults(false, false)
if properties.AgentPoolProfiles[0].ScaleSetPriority != "" {
t.Fatalf("AgentPoolProfiles[0].ScaleSetPriority did not have the expected configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].ScaleSetPriority, "")
}
if properties.AgentPoolProfiles[0].ScaleSetEvictionPolicy != "" {
t.Fatalf("AgentPoolProfiles[0].ScaleSetEvictionPolicy did not have the expected configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].ScaleSetEvictionPolicy, "")
}
properties.AgentPoolProfiles[0].ScaleSetPriority = ScaleSetPriorityLow
mockCS.SetPropertiesDefaults(false, false)
if properties.AgentPoolProfiles[0].ScaleSetEvictionPolicy != ScaleSetEvictionPolicyDelete {
t.Fatalf("AgentPoolProfile[0].ScaleSetEvictionPolicy did not have the expected configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].ScaleSetEvictionPolicy, ScaleSetEvictionPolicyDelete)
}
}
// TestSetComponentsNetworkDefaults covers tests for setMasterProfileDefaults and setAgentProfileDefaults
// TODO: Currently this test covers only Distro setting. Extend test cases to cover network configuration too.
func TestSetComponentsNetworkDefaults(t *testing.T) {
var tests = []struct {
name string // test case name
orchestratorProfile OrchestratorProfile // orchestrator to be tested
expectedDistro Distro // expected result default disto to be used
}{
{
"default_kubernetes",
OrchestratorProfile{
OrchestratorType: Kubernetes,
},
AKS,
},
{
"default_swarm",
OrchestratorProfile{
OrchestratorType: Swarm,
},
Ubuntu,
},
{
"default_swarmmode",
OrchestratorProfile{
OrchestratorType: SwarmMode,
},
Ubuntu,
},
{
"default_dcos",
OrchestratorProfile{
OrchestratorType: DCOS,
},
Ubuntu,
},
}
for _, test := range tests {
mockAPI := getMockAPIProperties("1.0.0")
mockAPI.OrchestratorProfile = &test.orchestratorProfile
mockAPI.setMasterProfileDefaults(false)
mockAPI.setAgentProfileDefaults(false, false)
if mockAPI.MasterProfile.Distro != test.expectedDistro {
t.Fatalf("setMasterProfileDefaults() test case %v did not return right Distro configurations %v != %v", test.name, mockAPI.MasterProfile.Distro, test.expectedDistro)
}
for _, agent := range mockAPI.AgentPoolProfiles {
if agent.Distro != test.expectedDistro {
t.Fatalf("setAgentProfileDefaults() test case %v did not return right Distro configurations %v != %v", test.name, agent.Distro, test.expectedDistro)
}
}
}
}
func TestIsAzureCNINetworkmonitorAddon(t *testing.T) {
mockCS := getMockBaseContainerService("1.10.3")
properties := mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 1
properties.OrchestratorProfile.KubernetesConfig.Addons = []KubernetesAddon{
{
Name: AzureCNINetworkMonitoringAddonName,
Containers: []KubernetesContainerSpec{
{
Name: AzureCNINetworkMonitoringAddonName,
CPURequests: "50m",
MemoryRequests: "150Mi",
CPULimits: "50m",
MemoryLimits: "150Mi",
},
},
Enabled: to.BoolPtr(true),
},
}
mockCS.setOrchestratorDefaults(true)
i := getAddonsIndexByName(properties.OrchestratorProfile.KubernetesConfig.Addons, AzureCNINetworkMonitoringAddonName)
if !to.Bool(properties.OrchestratorProfile.KubernetesConfig.Addons[i].Enabled) {
t.Fatalf("Azure CNI networkmonitor addon should be present")
}
mockCS = getMockBaseContainerService("1.10.3")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 1
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = "azure"
mockCS.setOrchestratorDefaults(true)
i = getAddonsIndexByName(properties.OrchestratorProfile.KubernetesConfig.Addons, AzureCNINetworkMonitoringAddonName)
if !to.Bool(properties.OrchestratorProfile.KubernetesConfig.Addons[i].Enabled) {
t.Fatalf("Azure CNI networkmonitor addon should be present by default if Azure CNI is set")
}
}
// TestSetVMSSDefaultsAndZones covers tests for setVMSSDefaultsForAgents and masters
func TestSetVMSSDefaultsAndZones(t *testing.T) {
// masters with vmss and no zones
mockCS := getMockBaseContainerService("1.12.0")
properties := mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.AvailabilityProfile = VirtualMachineScaleSets
mockCS.SetPropertiesDefaults(false, false)
if properties.MasterProfile.HasAvailabilityZones() {
t.Fatalf("MasterProfile.HasAvailabilityZones did not have the expected return, got %t, expected %t",
properties.MasterProfile.HasAvailabilityZones(), false)
}
if properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku != DefaultLoadBalancerSku {
t.Fatalf("OrchestratorProfile.KubernetesConfig.LoadBalancerSku did not have the expected configuration, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku, DefaultLoadBalancerSku)
}
// masters with vmss and zones
mockCS = getMockBaseContainerService("1.12.0")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.AvailabilityProfile = VirtualMachineScaleSets
properties.MasterProfile.AvailabilityZones = []string{"1", "2"}
mockCS.SetPropertiesDefaults(false, false)
singlePlacementGroup := DefaultSinglePlacementGroup
if *properties.MasterProfile.SinglePlacementGroup != singlePlacementGroup {
t.Fatalf("MasterProfile.SinglePlacementGroup default did not have the expected configuration, got %t, expected %t",
*properties.MasterProfile.SinglePlacementGroup, singlePlacementGroup)
}
if !properties.MasterProfile.HasAvailabilityZones() {
t.Fatalf("MasterProfile.HasAvailabilityZones did not have the expected return, got %t, expected %t",
properties.MasterProfile.HasAvailabilityZones(), true)
}
if properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku != "Standard" {
t.Fatalf("OrchestratorProfile.KubernetesConfig.LoadBalancerSku did not have the expected configuration, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku, "Standard")
}
excludeMaster := DefaultExcludeMasterFromStandardLB
if *properties.OrchestratorProfile.KubernetesConfig.ExcludeMasterFromStandardLB != excludeMaster {
t.Fatalf("OrchestratorProfile.KubernetesConfig.ExcludeMasterFromStandardLB did not have the expected configuration, got %t, expected %t",
*properties.OrchestratorProfile.KubernetesConfig.ExcludeMasterFromStandardLB, excludeMaster)
}
// agents with vmss and no zones
mockCS = getMockBaseContainerService("1.12.0")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.AgentPoolProfiles[0].Count = 4
mockCS.SetPropertiesDefaults(false, false)
if properties.AgentPoolProfiles[0].HasAvailabilityZones() {
t.Fatalf("AgentPoolProfiles[0].HasAvailabilityZones did not have the expected return, got %t, expected %t",
properties.AgentPoolProfiles[0].HasAvailabilityZones(), false)
}
if properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku != DefaultLoadBalancerSku {
t.Fatalf("OrchestratorProfile.KubernetesConfig.LoadBalancerSku did not have the expected configuration, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku, DefaultLoadBalancerSku)
}
// agents with vmss and zones
mockCS = getMockBaseContainerService("1.12.0")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.AgentPoolProfiles[0].Count = 4
properties.AgentPoolProfiles[0].AvailabilityZones = []string{"1", "2"}
mockCS.SetPropertiesDefaults(false, false)
if !properties.AgentPoolProfiles[0].IsVirtualMachineScaleSets() {
t.Fatalf("AgentPoolProfile[0].AvailabilityProfile did not have the expected configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].AvailabilityProfile, VirtualMachineScaleSets)
}
if !properties.AgentPoolProfiles[0].HasAvailabilityZones() {
t.Fatalf("AgentPoolProfiles[0].HasAvailabilityZones did not have the expected return, got %t, expected %t",
properties.AgentPoolProfiles[0].HasAvailabilityZones(), true)
}
singlePlacementGroup = DefaultSinglePlacementGroup
if *properties.AgentPoolProfiles[0].SinglePlacementGroup != singlePlacementGroup {
t.Fatalf("AgentPoolProfile[0].SinglePlacementGroup default did not have the expected configuration, got %t, expected %t",
*properties.AgentPoolProfiles[0].SinglePlacementGroup, singlePlacementGroup)