forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.go
1373 lines (1225 loc) · 51.6 KB
/
validate.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 vlabs
import (
"encoding/base64"
"fmt"
"net"
"net/url"
"reflect"
"regexp"
"strings"
"time"
"github.com/Azure/acs-engine/pkg/api/common"
"github.com/Azure/acs-engine/pkg/helpers"
"github.com/blang/semver"
"github.com/pkg/errors"
"github.com/satori/go.uuid"
log "github.com/sirupsen/logrus"
"gopkg.in/go-playground/validator.v9"
)
var (
validate *validator.Validate
keyvaultIDRegex *regexp.Regexp
labelValueRegex *regexp.Regexp
labelKeyRegex *regexp.Regexp
// Any version has to be mirrored in https://acs-mirror.azureedge.net/github-coreos/etcd-v[Version]-linux-amd64.tar.gz
etcdValidVersions = [...]string{"2.2.5", "2.3.0", "2.3.1", "2.3.2", "2.3.3", "2.3.4", "2.3.5", "2.3.6", "2.3.7", "2.3.8",
"3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.0.4", "3.0.5", "3.0.6", "3.0.7", "3.0.8", "3.0.9", "3.0.10", "3.0.11", "3.0.12", "3.0.13", "3.0.14", "3.0.15", "3.0.16", "3.0.17",
"3.1.0", "3.1.1", "3.1.2", "3.1.2", "3.1.3", "3.1.4", "3.1.5", "3.1.6", "3.1.7", "3.1.8", "3.1.9", "3.1.10",
"3.2.0", "3.2.1", "3.2.2", "3.2.3", "3.2.4", "3.2.5", "3.2.6", "3.2.7", "3.2.8", "3.2.9", "3.2.11", "3.2.12",
"3.2.13", "3.2.14", "3.2.15", "3.2.16", "3.2.23", "3.2.24", "3.3.0", "3.3.1", "3.3.8", "3.3.9"}
networkPluginPlusPolicyAllowed = []k8sNetworkConfig{
{
networkPlugin: "",
networkPolicy: "",
},
{
networkPlugin: "azure",
networkPolicy: "",
},
{
networkPlugin: "azure",
networkPolicy: "azure",
},
{
networkPlugin: "kubenet",
networkPolicy: "",
},
{
networkPlugin: "flannel",
networkPolicy: "",
},
{
networkPlugin: "cilium",
networkPolicy: "",
},
{
networkPlugin: "cilium",
networkPolicy: "cilium",
},
{
networkPlugin: "kubenet",
networkPolicy: "calico",
},
{
networkPlugin: "azure",
networkPolicy: "calico",
},
{
networkPlugin: "",
networkPolicy: "calico",
},
{
networkPlugin: "",
networkPolicy: "cilium",
},
{
networkPlugin: "",
networkPolicy: "azure", // for backwards-compatibility w/ prior networkPolicy usage
},
{
networkPlugin: "",
networkPolicy: "none", // for backwards-compatibility w/ prior networkPolicy usage
},
}
)
const (
labelKeyPrefixMaxLength = 253
labelValueFormat = "^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$"
labelKeyFormat = "^(([a-zA-Z0-9-]+[.])*[a-zA-Z0-9-]+[/])?([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$"
)
type k8sNetworkConfig struct {
networkPlugin string
networkPolicy string
}
func init() {
validate = validator.New()
keyvaultIDRegex = regexp.MustCompile(`^/subscriptions/\S+/resourceGroups/\S+/providers/Microsoft.KeyVault/vaults/[^/\s]+$`)
labelValueRegex = regexp.MustCompile(labelValueFormat)
labelKeyRegex = regexp.MustCompile(labelKeyFormat)
}
// Validate implements APIObject
func (a *Properties) Validate(isUpdate bool) error {
if e := validate.Struct(a); e != nil {
return handleValidationErrors(e.(validator.ValidationErrors))
}
if e := a.validateOrchestratorProfile(isUpdate); e != nil {
return e
}
if e := a.validateMasterProfile(); e != nil {
return e
}
if e := a.validateAgentPoolProfiles(isUpdate); e != nil {
return e
}
if e := a.validateZones(); e != nil {
return e
}
if e := a.validateLinuxProfile(); e != nil {
return e
}
if e := a.validateAddons(); e != nil {
return e
}
if e := a.validateExtensions(); e != nil {
return e
}
if e := a.validateVNET(); e != nil {
return e
}
if e := a.validateServicePrincipalProfile(); e != nil {
return e
}
if e := a.validateManagedIdentity(); e != nil {
return e
}
if e := a.validateAADProfile(); e != nil {
return e
}
if e := a.validateAzProfile(); e != nil {
return e
}
return nil
}
func handleValidationErrors(e validator.ValidationErrors) error {
// Override any version specific validation error message
// common.HandleValidationErrors if the validation error message is general
return common.HandleValidationErrors(e)
}
func (a *Properties) validateOrchestratorProfile(isUpdate bool) error {
o := a.OrchestratorProfile
// On updates we only need to make sure there is a supported patch version for the minor version
if !isUpdate {
switch o.OrchestratorType {
case DCOS:
version := common.RationalizeReleaseAndVersion(
o.OrchestratorType,
o.OrchestratorRelease,
o.OrchestratorVersion,
isUpdate,
false)
if version == "" {
return errors.Errorf("the following OrchestratorProfile configuration is not supported: OrchestratorType: %s, OrchestratorRelease: %s, OrchestratorVersion: %s. Please check supported Release or Version for this build of acs-engine", o.OrchestratorType, o.OrchestratorRelease, o.OrchestratorVersion)
}
if o.DcosConfig != nil && o.DcosConfig.BootstrapProfile != nil {
if len(o.DcosConfig.BootstrapProfile.StaticIP) > 0 {
if net.ParseIP(o.DcosConfig.BootstrapProfile.StaticIP) == nil {
return errors.Errorf("DcosConfig.BootstrapProfile.StaticIP '%s' is an invalid IP address",
o.DcosConfig.BootstrapProfile.StaticIP)
}
}
}
case Swarm:
case SwarmMode:
case Kubernetes:
version := common.RationalizeReleaseAndVersion(
o.OrchestratorType,
o.OrchestratorRelease,
o.OrchestratorVersion,
isUpdate,
a.HasWindows())
if version == "" && a.HasWindows() {
return errors.Errorf("the following OrchestratorProfile configuration is not supported with OsType \"Windows\": OrchestratorType: \"%s\", OrchestratorRelease: \"%s\", OrchestratorVersion: \"%s\". Please use one of the following versions: %v", o.OrchestratorType, o.OrchestratorRelease, o.OrchestratorVersion, common.GetAllSupportedKubernetesVersions(false, true))
} else if version == "" {
return errors.Errorf("the following OrchestratorProfile configuration is not supported: OrchestratorType: \"%s\", OrchestratorRelease: \"%s\", OrchestratorVersion: \"%s\". Please use one of the following versions: %v", o.OrchestratorType, o.OrchestratorRelease, o.OrchestratorVersion, common.GetAllSupportedKubernetesVersions(false, false))
}
sv, err := semver.Make(version)
if err != nil {
return errors.Errorf("could not validate version %s", version)
}
if a.HasAvailabilityZones() {
minVersion, err := semver.Make("1.12.0")
if err != nil {
return errors.New("could not validate version")
}
if sv.LT(minVersion) {
return errors.New("availabilityZone is only available in Kubernetes version 1.12 or greater")
}
}
if o.KubernetesConfig != nil {
err := o.KubernetesConfig.Validate(version, a.HasWindows())
if err != nil {
return err
}
minVersion, err := semver.Make("1.7.0")
if err != nil {
return errors.New("could not validate version")
}
if o.KubernetesConfig.EnableAggregatedAPIs {
if sv.LT(minVersion) {
return errors.Errorf("enableAggregatedAPIs is only available in Kubernetes version %s or greater; unable to validate for Kubernetes version %s",
minVersion.String(), version)
}
if o.KubernetesConfig.EnableRbac != nil {
if !*o.KubernetesConfig.EnableRbac {
return errors.New("enableAggregatedAPIs requires the enableRbac feature as a prerequisite")
}
}
}
if helpers.IsTrueBoolPointer(o.KubernetesConfig.EnableDataEncryptionAtRest) {
if sv.LT(minVersion) {
return errors.Errorf("enableDataEncryptionAtRest is only available in Kubernetes version %s or greater; unable to validate for Kubernetes version %s",
minVersion.String(), o.OrchestratorVersion)
}
if o.KubernetesConfig.EtcdEncryptionKey != "" {
_, err = base64.StdEncoding.DecodeString(o.KubernetesConfig.EtcdEncryptionKey)
if err != nil {
return errors.New("etcdEncryptionKey must be base64 encoded. Please provide a valid base64 encoded value or leave the etcdEncryptionKey empty to auto-generate the value")
}
}
}
if helpers.IsTrueBoolPointer(o.KubernetesConfig.EnableEncryptionWithExternalKms) {
minVersion, err := semver.Make("1.10.0")
if err != nil {
return errors.Errorf("could not validate version")
}
if sv.LT(minVersion) {
return errors.Errorf("enableEncryptionWithExternalKms is only available in Kubernetes version %s or greater; unable to validate for Kubernetes version %s",
minVersion.String(), o.OrchestratorVersion)
}
}
if helpers.IsTrueBoolPointer(o.KubernetesConfig.EnablePodSecurityPolicy) {
if !helpers.IsTrueBoolPointer(o.KubernetesConfig.EnableRbac) {
return errors.Errorf("enablePodSecurityPolicy requires the enableRbac feature as a prerequisite")
}
minVersion, err := semver.Make("1.8.0")
if err != nil {
return errors.Errorf("could not validate version")
}
if sv.LT(minVersion) {
return errors.Errorf("enablePodSecurityPolicy is only supported in acs-engine for Kubernetes version %s or greater; unable to validate for Kubernetes version %s",
minVersion.String(), version)
}
}
if o.KubernetesConfig.LoadBalancerSku == "Standard" {
minVersion, err := semver.Make("1.11.0")
if err != nil {
return errors.Errorf("could not validate version")
}
if sv.LT(minVersion) {
return errors.Errorf("loadBalancerSku is only available in Kubernetes version %s or greater; unable to validate for Kubernetes version %s",
minVersion.String(), o.OrchestratorVersion)
}
if helpers.IsFalseBoolPointer(a.OrchestratorProfile.KubernetesConfig.ExcludeMasterFromStandardLB) {
return errors.Errorf("standard loadBalancerSku should exclude master nodes. Please set KubernetesConfig \"ExcludeMasterFromStandardLB\" to \"true\"")
}
}
if o.KubernetesConfig.DockerEngineVersion != "" {
log.Warnf("docker-engine is deprecated in favor of moby, but you passed in a dockerEngineVersion configuration. This will be ignored.")
}
}
case OpenShift:
// TODO: add appropriate additional validation logic
if o.OrchestratorVersion != common.OpenShiftVersionUnstable {
version := common.RationalizeReleaseAndVersion(
o.OrchestratorType,
o.OrchestratorRelease,
o.OrchestratorVersion,
isUpdate,
false)
if version == "" {
return errors.Errorf("OrchestratorProfile is not able to be rationalized, check supported Release or Version")
}
}
if o.OpenShiftConfig == nil {
return errors.Errorf("OpenShiftConfig must be specified for OpenShift orchestrator")
}
return o.OpenShiftConfig.Validate()
default:
return errors.Errorf("OrchestratorProfile has unknown orchestrator: %s", o.OrchestratorType)
}
} else {
switch o.OrchestratorType {
case DCOS, Kubernetes:
version := common.RationalizeReleaseAndVersion(
o.OrchestratorType,
o.OrchestratorRelease,
o.OrchestratorVersion,
false,
a.HasWindows())
if version == "" {
patchVersion := common.GetValidPatchVersion(o.OrchestratorType, o.OrchestratorVersion, isUpdate, a.HasWindows())
// if there isn't a supported patch version for this version fail
if patchVersion == "" {
if a.HasWindows() {
return errors.Errorf("the following OrchestratorProfile configuration is not supported with Windows agentpools: OrchestratorType: \"%s\", OrchestratorRelease: \"%s\", OrchestratorVersion: \"%s\". Please check supported Release or Version for this build of acs-engine", o.OrchestratorType, o.OrchestratorRelease, o.OrchestratorVersion)
}
return errors.Errorf("the following OrchestratorProfile configuration is not supported: OrchestratorType: \"%s\", OrchestratorRelease: \"%s\", OrchestratorVersion: \"%s\". Please check supported Release or Version for this build of acs-engine", o.OrchestratorType, o.OrchestratorRelease, o.OrchestratorVersion)
}
}
}
}
if (o.OrchestratorType != Kubernetes && o.OrchestratorType != OpenShift) && o.KubernetesConfig != nil {
return errors.Errorf("KubernetesConfig can be specified only when OrchestratorType is Kubernetes or OpenShift")
}
if o.OrchestratorType != OpenShift && o.OpenShiftConfig != nil {
return errors.Errorf("OpenShiftConfig can be specified only when OrchestratorType is OpenShift")
}
if o.OrchestratorType != DCOS && o.DcosConfig != nil && (*o.DcosConfig != DcosConfig{}) {
return errors.Errorf("DcosConfig can be specified only when OrchestratorType is DCOS")
}
if e := a.validateContainerRuntime(); e != nil {
return e
}
return nil
}
func (a *Properties) validateMasterProfile() error {
m := a.MasterProfile
if a.OrchestratorProfile.OrchestratorType == OpenShift {
if m.Count != 1 {
return errors.New("openshift can only deployed with one master")
}
if m.VnetSubnetID != "" && m.FirstConsecutiveStaticIP == "" {
return errors.New("when specifying a vnetsubnetid the firstconsecutivestaticip is required")
}
if m.StorageProfile != ManagedDisks {
return errors.New("OpenShift orchestrator supports only ManagedDisks")
}
}
if a.OrchestratorProfile.OrchestratorType == Kubernetes {
if m.IsVirtualMachineScaleSets() && m.VnetSubnetID != "" && m.FirstConsecutiveStaticIP != "" {
return errors.New("when masterProfile's availabilityProfile is VirtualMachineScaleSets and a vnetSubnetID is specified, the firstConsecutiveStaticIP should be empty and will be determined by an offset from the first IP in the vnetCidr")
}
}
if m.ImageRef != nil {
if err := m.ImageRef.validateImageNameAndGroup(); err != nil {
return err
}
}
if m.IsVirtualMachineScaleSets() && a.OrchestratorProfile.OrchestratorType == Kubernetes {
log.Warnf("Clusters with VMSS masters are not yet upgradable! You will not be able to upgrade your cluster until a future version of acs-engine!")
e := validateVMSS(a.OrchestratorProfile, false, m.StorageProfile)
if e != nil {
return e
}
if !a.IsClusterAllVirtualMachineScaleSets() {
return errors.New("VirtualMachineScaleSets for master profile must be used together with virtualMachineScaleSets for agent profiles. Set \"availabilityProfile\" to \"VirtualMachineScaleSets\" for agent profiles")
}
if a.OrchestratorProfile.KubernetesConfig != nil && a.OrchestratorProfile.KubernetesConfig.UseManagedIdentity && a.OrchestratorProfile.KubernetesConfig.UserAssignedID == "" {
return errors.New("virtualMachineScaleSets for master profile can be used only with user assigned MSI ! Please specify \"userAssignedID\" in \"kubernetesConfig\"")
}
}
if m.SinglePlacementGroup != nil && m.AvailabilityProfile == AvailabilitySet {
return errors.New("singlePlacementGroup is only supported with VirtualMachineScaleSets")
}
return common.ValidateDNSPrefix(m.DNSPrefix)
}
func (a *Properties) validateAgentPoolProfiles(isUpdate bool) error {
profileNames := make(map[string]bool)
for i, agentPoolProfile := range a.AgentPoolProfiles {
if e := validatePoolName(agentPoolProfile.Name); e != nil {
return e
}
// validate that each AgentPoolProfile Name is unique
if _, ok := profileNames[agentPoolProfile.Name]; ok {
return errors.Errorf("profile name '%s' already exists, profile names must be unique across pools", agentPoolProfile.Name)
}
profileNames[agentPoolProfile.Name] = true
if e := validatePoolOSType(agentPoolProfile.OSType); e != nil {
return e
}
if helpers.IsTrueBoolPointer(agentPoolProfile.AcceleratedNetworkingEnabled) || helpers.IsTrueBoolPointer(agentPoolProfile.AcceleratedNetworkingEnabledWindows) {
if e := validatePoolAcceleratedNetworking(agentPoolProfile.VMSize); e != nil {
return e
}
}
if e := agentPoolProfile.validateOrchestratorSpecificProperties(a.OrchestratorProfile.OrchestratorType); e != nil {
return e
}
if agentPoolProfile.ImageRef != nil {
return agentPoolProfile.ImageRef.validateImageNameAndGroup()
}
if e := agentPoolProfile.validateAvailabilityProfile(a.OrchestratorProfile.OrchestratorType); e != nil {
return e
}
if e := agentPoolProfile.validateRoles(a.OrchestratorProfile.OrchestratorType); e != nil {
return e
}
if e := agentPoolProfile.validateStorageProfile(a.OrchestratorProfile.OrchestratorType); e != nil {
return e
}
if e := agentPoolProfile.validateCustomNodeLabels(a.OrchestratorProfile.OrchestratorType); e != nil {
return e
}
if agentPoolProfile.AvailabilityProfile == VirtualMachineScaleSets {
e := validateVMSS(a.OrchestratorProfile, isUpdate, agentPoolProfile.StorageProfile)
if e != nil {
return e
}
}
if a.OrchestratorProfile.OrchestratorType == Kubernetes {
if a.AgentPoolProfiles[i].AvailabilityProfile != a.AgentPoolProfiles[0].AvailabilityProfile {
return errors.New("mixed mode availability profiles are not allowed. Please set either VirtualMachineScaleSets or AvailabilitySet in availabilityProfile for all agent pools")
}
if a.AgentPoolProfiles[i].SinglePlacementGroup != nil && a.AgentPoolProfiles[i].AvailabilityProfile == AvailabilitySet {
return errors.New("singlePlacementGroup is only supported with VirtualMachineScaleSets")
}
}
if a.OrchestratorProfile.OrchestratorType == OpenShift {
if (agentPoolProfile.Name == "infra") != (agentPoolProfile.Role == "infra") {
return errors.New("OpenShift requires that the 'infra' agent pool profile, and no other, should have role 'infra'")
}
}
if e := agentPoolProfile.validateWindows(a.OrchestratorProfile, a.WindowsProfile, isUpdate); agentPoolProfile.OSType == Windows && e != nil {
return e
}
}
if a.OrchestratorProfile.OrchestratorType == OpenShift {
if !reflect.DeepEqual(profileNames, map[string]bool{"compute": true, "infra": true}) {
return errors.New("OpenShift requires exactly two agent pool profiles: compute and infra")
}
}
return nil
}
func (a *Properties) validateZones() error {
if a.OrchestratorProfile.OrchestratorType == Kubernetes {
// all zones or no zones should be defined for the cluster
if a.HasAvailabilityZones() {
if a.MastersAndAgentsUseAvailabilityZones() {
// master profile
if a.MasterProfile.Count < len(a.MasterProfile.AvailabilityZones)*2 {
return errors.New("the node count and the number of availability zones provided can result in zone imbalance. To achieve zone balance, each zone should have at least 2 nodes or more")
}
// agent pool profiles
for _, agentPoolProfile := range a.AgentPoolProfiles {
if agentPoolProfile.AvailabilityProfile == AvailabilitySet {
return errors.New("Availability Zones are not supported with an AvailabilitySet. Please either remove availabilityProfile or set availabilityProfile to VirtualMachineScaleSets")
}
if agentPoolProfile.Count < len(agentPoolProfile.AvailabilityZones)*2 {
return errors.New("the node count and the number of availability zones provided can result in zone imbalance. To achieve zone balance, each zone should have at least 2 nodes or more")
}
}
if a.OrchestratorProfile.KubernetesConfig != nil && a.OrchestratorProfile.KubernetesConfig.LoadBalancerSku != "" && a.OrchestratorProfile.KubernetesConfig.LoadBalancerSku != "Standard" {
return errors.New("Availability Zones requires Standard LoadBalancer. Please set KubernetesConfig \"LoadBalancerSku\" to \"Standard\"")
}
} else {
return errors.New("Availability Zones need to be defined for master profile and all agent pool profiles. Please set \"availabilityZones\" for all profiles")
}
}
}
return nil
}
func (a *Properties) validateLinuxProfile() error {
if e := validate.Var(a.LinuxProfile.SSH.PublicKeys[0].KeyData, "required"); e != nil {
return errors.New("KeyData in LinuxProfile.SSH.PublicKeys cannot be empty string")
}
return validateKeyVaultSecrets(a.LinuxProfile.Secrets, false)
}
func (a *Properties) validateAddons() error {
if a.OrchestratorProfile.KubernetesConfig != nil && a.OrchestratorProfile.KubernetesConfig.Addons != nil {
var isAvailabilitySets bool
var IsNSeriesSKU bool
for _, agentPool := range a.AgentPoolProfiles {
if agentPool.IsAvailabilitySets() {
isAvailabilitySets = true
}
if agentPool.IsNSeriesSKU() {
IsNSeriesSKU = true
}
}
for _, addon := range a.OrchestratorProfile.KubernetesConfig.Addons {
if addon.Data != "" {
if len(addon.Config) > 0 || len(addon.Containers) > 0 {
return errors.New("Config and containers should be empty when addon.Data is specified")
}
if _, err := base64.StdEncoding.DecodeString(addon.Data); err != nil {
return errors.Errorf("Addon %s's data should be base64 encoded", addon.Name)
}
}
switch addon.Name {
case "cluster-autoscaler":
if helpers.IsTrueBoolPointer(addon.Enabled) && isAvailabilitySets {
return errors.Errorf("Cluster Autoscaler add-on can only be used with VirtualMachineScaleSets. Please specify \"availabilityProfile\": \"%s\"", VirtualMachineScaleSets)
}
case "nvidia-device-plugin":
if helpers.IsTrueBoolPointer(addon.Enabled) {
version := common.RationalizeReleaseAndVersion(
a.OrchestratorProfile.OrchestratorType,
a.OrchestratorProfile.OrchestratorRelease,
a.OrchestratorProfile.OrchestratorVersion,
false,
false)
if version == "" {
return errors.Errorf("the following user supplied OrchestratorProfile configuration is not supported: OrchestratorType: %s, OrchestratorRelease: %s, OrchestratorVersion: %s. Please check supported Release or Version for this build of acs-engine", a.OrchestratorProfile.OrchestratorType, a.OrchestratorProfile.OrchestratorRelease, a.OrchestratorProfile.OrchestratorVersion)
}
sv, err := semver.Make(version)
if err != nil {
return errors.Errorf("could not validate version %s", version)
}
minVersion, err := semver.Make("1.10.0")
if err != nil {
return errors.New("could not validate version")
}
if IsNSeriesSKU && sv.LT(minVersion) {
return errors.New("NVIDIA Device Plugin add-on can only be used Kubernetes 1.10 or above. Please specify \"orchestratorRelease\": \"1.10\"")
}
}
}
}
}
return nil
}
func (a *Properties) validateExtensions() error {
for _, agentPool := range a.AgentPoolProfiles {
if len(agentPool.Extensions) != 0 && (len(agentPool.AvailabilityProfile) == 0 || agentPool.IsVirtualMachineScaleSets()) {
return errors.Errorf("Extensions are currently not supported with VirtualMachineScaleSets. Please specify \"availabilityProfile\": \"%s\"", AvailabilitySet)
}
}
for _, extension := range a.ExtensionProfiles {
if extension.ExtensionParametersKeyVaultRef != nil {
if e := validate.Var(extension.ExtensionParametersKeyVaultRef.VaultID, "required"); e != nil {
return errors.Errorf("the Keyvault ID must be specified for Extension %s", extension.Name)
}
if e := validate.Var(extension.ExtensionParametersKeyVaultRef.SecretName, "required"); e != nil {
return errors.Errorf("the Keyvault Secret must be specified for Extension %s", extension.Name)
}
if !keyvaultIDRegex.MatchString(extension.ExtensionParametersKeyVaultRef.VaultID) {
return errors.Errorf("Extension %s's keyvault secret reference is of incorrect format", extension.Name)
}
}
}
return nil
}
func (a *Properties) validateVNET() error {
isCustomVNET := a.MasterProfile.IsCustomVNET()
for _, agentPool := range a.AgentPoolProfiles {
if agentPool.IsCustomVNET() != isCustomVNET {
return errors.New("Multiple VNET Subnet configurations specified. The master profile and each agent pool profile must all specify a custom VNET Subnet, or none at all")
}
}
if isCustomVNET {
if a.MasterProfile.IsVirtualMachineScaleSets() && a.MasterProfile.AgentVnetSubnetID == "" {
return errors.New("when master profile is using VirtualMachineScaleSets and is custom vnet, set \"vnetsubnetid\" and \"agentVnetSubnetID\" for master profile")
}
subscription, resourcegroup, vnetname, _, e := common.GetVNETSubnetIDComponents(a.MasterProfile.VnetSubnetID)
if e != nil {
return e
}
for _, agentPool := range a.AgentPoolProfiles {
agentSubID, agentRG, agentVNET, _, err := common.GetVNETSubnetIDComponents(agentPool.VnetSubnetID)
if err != nil {
return err
}
if agentSubID != subscription ||
agentRG != resourcegroup ||
agentVNET != vnetname {
return errors.New("Multiple VNETS specified. The master profile and each agent pool must reference the same VNET (but it is ok to reference different subnets on that VNET)")
}
}
masterFirstIP := net.ParseIP(a.MasterProfile.FirstConsecutiveStaticIP)
if masterFirstIP == nil && !a.MasterProfile.IsVirtualMachineScaleSets() {
return errors.Errorf("MasterProfile.FirstConsecutiveStaticIP (with VNET Subnet specification) '%s' is an invalid IP address", a.MasterProfile.FirstConsecutiveStaticIP)
}
if a.MasterProfile.VnetCidr != "" {
_, _, err := net.ParseCIDR(a.MasterProfile.VnetCidr)
if err != nil {
return errors.Errorf("MasterProfile.VnetCidr '%s' contains invalid cidr notation", a.MasterProfile.VnetCidr)
}
}
}
return nil
}
func (a *Properties) validateServicePrincipalProfile() error {
if a.OrchestratorProfile.OrchestratorType == Kubernetes {
useManagedIdentity := a.OrchestratorProfile.KubernetesConfig != nil &&
a.OrchestratorProfile.KubernetesConfig.UseManagedIdentity
if !useManagedIdentity {
if a.ServicePrincipalProfile == nil {
return errors.Errorf("ServicePrincipalProfile must be specified with Orchestrator %s", a.OrchestratorProfile.OrchestratorType)
}
if e := validate.Var(a.ServicePrincipalProfile.ClientID, "required"); e != nil {
return errors.Errorf("the service principal client ID must be specified with Orchestrator %s", a.OrchestratorProfile.OrchestratorType)
}
if (len(a.ServicePrincipalProfile.Secret) == 0 && a.ServicePrincipalProfile.KeyvaultSecretRef == nil) ||
(len(a.ServicePrincipalProfile.Secret) != 0 && a.ServicePrincipalProfile.KeyvaultSecretRef != nil) {
return errors.Errorf("either the service principal client secret or keyvault secret reference must be specified with Orchestrator %s", a.OrchestratorProfile.OrchestratorType)
}
if a.OrchestratorProfile.KubernetesConfig != nil && helpers.IsTrueBoolPointer(a.OrchestratorProfile.KubernetesConfig.EnableEncryptionWithExternalKms) && len(a.ServicePrincipalProfile.ObjectID) == 0 {
return errors.Errorf("the service principal object ID must be specified with Orchestrator %s when enableEncryptionWithExternalKms is true", a.OrchestratorProfile.OrchestratorType)
}
if a.ServicePrincipalProfile.KeyvaultSecretRef != nil {
if e := validate.Var(a.ServicePrincipalProfile.KeyvaultSecretRef.VaultID, "required"); e != nil {
return errors.Errorf("the Keyvault ID must be specified for the Service Principle with Orchestrator %s", a.OrchestratorProfile.OrchestratorType)
}
if e := validate.Var(a.ServicePrincipalProfile.KeyvaultSecretRef.SecretName, "required"); e != nil {
return errors.Errorf("the Keyvault Secret must be specified for the Service Principle with Orchestrator %s", a.OrchestratorProfile.OrchestratorType)
}
if !keyvaultIDRegex.MatchString(a.ServicePrincipalProfile.KeyvaultSecretRef.VaultID) {
return errors.Errorf("service principal client keyvault secret reference is of incorrect format")
}
}
}
}
return nil
}
func (a *Properties) validateManagedIdentity() error {
if a.OrchestratorProfile.OrchestratorType == Kubernetes {
useManagedIdentity := a.OrchestratorProfile.KubernetesConfig != nil &&
a.OrchestratorProfile.KubernetesConfig.UseManagedIdentity
if useManagedIdentity {
version := common.RationalizeReleaseAndVersion(
a.OrchestratorProfile.OrchestratorType,
a.OrchestratorProfile.OrchestratorRelease,
a.OrchestratorProfile.OrchestratorVersion,
false,
false)
if version == "" {
return errors.Errorf("the following user supplied OrchestratorProfile configuration is not supported: OrchestratorType: %s, OrchestratorRelease: %s, OrchestratorVersion: %s. Please check supported Release or Version for this build of acs-engine", a.OrchestratorProfile.OrchestratorType, a.OrchestratorProfile.OrchestratorRelease, a.OrchestratorProfile.OrchestratorVersion)
}
sv, err := semver.Make(version)
if err != nil {
return errors.Errorf("could not validate version %s", version)
}
minVersion, err := semver.Make("1.12.0")
if err != nil {
return errors.New("could not validate version")
}
if a.MasterProfile.IsVirtualMachineScaleSets() {
if sv.LT(minVersion) {
return errors.New("managed identity and VMSS masters can only be used with Kubernetes 1.12.0 or above. Please specify \"orchestratorRelease\": \"1.12\"")
}
} else if a.OrchestratorProfile.KubernetesConfig.UserAssignedID != "" && sv.LT(minVersion) {
return errors.New("user assigned identity can only be used with Kubernetes 1.12.0 or above. Please specify \"orchestratorRelease\": \"1.12\"")
}
}
}
return nil
}
func (a *Properties) validateAADProfile() error {
if profile := a.AADProfile; profile != nil {
if a.OrchestratorProfile.OrchestratorType != Kubernetes {
return errors.Errorf("'aadProfile' is only supported by orchestrator '%v'", Kubernetes)
}
if _, err := uuid.FromString(profile.ClientAppID); err != nil {
return errors.Errorf("clientAppID '%v' is invalid", profile.ClientAppID)
}
if _, err := uuid.FromString(profile.ServerAppID); err != nil {
return errors.Errorf("serverAppID '%v' is invalid", profile.ServerAppID)
}
if len(profile.TenantID) > 0 {
if _, err := uuid.FromString(profile.TenantID); err != nil {
return errors.Errorf("tenantID '%v' is invalid", profile.TenantID)
}
}
if len(profile.AdminGroupID) > 0 {
if _, err := uuid.FromString(profile.AdminGroupID); err != nil {
return errors.Errorf("adminGroupID '%v' is invalid", profile.AdminGroupID)
}
}
}
return nil
}
func (a *Properties) validateAzProfile() error {
switch a.OrchestratorProfile.OrchestratorType {
case OpenShift:
if a.AzProfile == nil || a.AzProfile.Location == "" ||
a.AzProfile.ResourceGroup == "" || a.AzProfile.SubscriptionID == "" ||
a.AzProfile.TenantID == "" {
return errors.Errorf("'azProfile' must be supplied in full for orchestrator '%v'", OpenShift)
}
default:
if a.AzProfile != nil {
return errors.Errorf("'azProfile' is only supported by orchestrator '%v'", OpenShift)
}
}
return nil
}
// Validate OpenShiftConfig ensures that the OpenShiftConfig is valid.
func (o *OpenShiftConfig) Validate() error {
if o.ClusterUsername == "" || o.ClusterPassword == "" {
return errors.Errorf("ClusterUsername and ClusterPassword must both be specified")
}
return nil
}
func (a *AgentPoolProfile) validateAvailabilityProfile(orchestratorType string) error {
switch a.AvailabilityProfile {
case AvailabilitySet:
case VirtualMachineScaleSets:
case "":
default:
{
return errors.Errorf("unknown availability profile type '%s' for agent pool '%s'. Specify either %s, or %s", a.AvailabilityProfile, a.Name, AvailabilitySet, VirtualMachineScaleSets)
}
}
if orchestratorType == OpenShift && a.AvailabilityProfile != AvailabilitySet {
return errors.Errorf("Only AvailabilityProfile: AvailabilitySet is supported for Orchestrator 'OpenShift'")
}
return nil
}
func (a *AgentPoolProfile) validateRoles(orchestratorType string) error {
validRoles := []AgentPoolProfileRole{AgentPoolProfileRoleEmpty}
if orchestratorType == OpenShift {
validRoles = append(validRoles, AgentPoolProfileRoleInfra)
}
var found bool
for _, validRole := range validRoles {
if a.Role == validRole {
found = true
break
}
}
if !found {
return errors.Errorf("Role %q is not supported for Orchestrator %s", a.Role, orchestratorType)
}
return nil
}
func (a *AgentPoolProfile) validateStorageProfile(orchestratorType string) error {
/* this switch statement is left to protect newly added orchestrators until they support Managed Disks*/
if a.StorageProfile == ManagedDisks {
switch orchestratorType {
case DCOS:
case Swarm:
case Kubernetes:
case OpenShift:
case SwarmMode:
default:
return errors.Errorf("HA volumes are currently unsupported for Orchestrator %s", orchestratorType)
}
}
if orchestratorType == OpenShift && a.StorageProfile != ManagedDisks {
return errors.New("OpenShift orchestrator supports only ManagedDisks")
}
return nil
}
func (a *AgentPoolProfile) validateCustomNodeLabels(orchestratorType string) error {
if len(a.CustomNodeLabels) > 0 {
switch orchestratorType {
case DCOS:
case Kubernetes:
for k, v := range a.CustomNodeLabels {
if e := validateKubernetesLabelKey(k); e != nil {
return e
}
if e := validateKubernetesLabelValue(v); e != nil {
return e
}
}
default:
return errors.New("Agent CustomNodeLabels are only supported for DCOS and Kubernetes")
}
}
return nil
}
func (a *AgentPoolProfile) validateKubernetesDistro() error {
switch a.Distro {
case AKS:
if a.IsNSeriesSKU() {
return errors.Errorf("The %s VM SKU must use the %s Distro as they require the docker-engine container runtime", a.VMSize, AKSDockerEngine)
}
}
return nil
}
func validateVMSS(o *OrchestratorProfile, isUpdate bool, storageProfile string) error {
if o.OrchestratorType == Kubernetes {
version := common.RationalizeReleaseAndVersion(
o.OrchestratorType,
o.OrchestratorRelease,
o.OrchestratorVersion,
isUpdate,
false)
if version == "" {
return errors.Errorf("the following OrchestratorProfile configuration is not supported: OrchestratorType: %s, OrchestratorRelease: %s, OrchestratorVersion: %s. Please check supported Release or Version for this build of acs-engine", o.OrchestratorType, o.OrchestratorRelease, o.OrchestratorVersion)
}
sv, err := semver.Make(version)
if err != nil {
return errors.Errorf("could not validate version %s", version)
}
minVersion, err := semver.Make("1.10.0")
if err != nil {
return errors.New("could not validate version")
}
if sv.LT(minVersion) {
return errors.Errorf("VirtualMachineScaleSets are only available in Kubernetes version %s or greater. Please set \"orchestratorVersion\" to %s or above", minVersion.String(), minVersion.String())
}
// validation for instanceMetadata using VMSS with Kubernetes
minVersion, err = semver.Make("1.10.2")
if err != nil {
return errors.New("could not validate version")
}
if o.KubernetesConfig != nil && o.KubernetesConfig.UseInstanceMetadata != nil {
if *o.KubernetesConfig.UseInstanceMetadata && sv.LT(minVersion) {
return errors.Errorf("VirtualMachineScaleSets with instance metadata is supported for Kubernetes version %s or greater. Please set \"useInstanceMetadata\": false in \"kubernetesConfig\" or set \"orchestratorVersion\" to %s or above", minVersion.String(), minVersion.String())
}
}
if storageProfile == StorageAccount {
return errors.Errorf("VirtualMachineScaleSets does not support %s disks. Please specify \"storageProfile\": \"%s\" (recommended) or \"availabilityProfile\": \"%s\"", StorageAccount, ManagedDisks, AvailabilitySet)
}
}
return nil
}
func (a *AgentPoolProfile) validateWindows(o *OrchestratorProfile, w *WindowsProfile, isUpdate bool) error {
switch o.OrchestratorType {
case DCOS:
case Swarm:
case SwarmMode:
case Kubernetes:
version := common.RationalizeReleaseAndVersion(
o.OrchestratorType,
o.OrchestratorRelease,
o.OrchestratorVersion,
isUpdate,
true)
if version == "" {
return errors.Errorf("Orchestrator %s version %s does not support Windows", o.OrchestratorType, o.OrchestratorVersion)
}
default:
return errors.Errorf("Orchestrator %s does not support Windows", o.OrchestratorType)
}
if w != nil {
if e := w.Validate(o.OrchestratorType); e != nil {
return e
}
} else {
return errors.New("WindowsProfile is required when the cluster definition contains Windows agent pool(s)")
}
return nil
}
func (a *AgentPoolProfile) validateOrchestratorSpecificProperties(orchestratorType string) error {
// for Kubernetes, we don't support AgentPoolProfile.DNSPrefix
if orchestratorType == Kubernetes {
if e := validate.Var(a.DNSPrefix, "len=0"); e != nil {
return errors.New("AgentPoolProfile.DNSPrefix must be empty for Kubernetes")
}
if e := validate.Var(a.Ports, "len=0"); e != nil {
return errors.New("AgentPoolProfile.Ports must be empty for Kubernetes")
}
if validate.Var(a.ScaleSetPriority, "eq=Regular") == nil && validate.Var(a.ScaleSetEvictionPolicy, "len=0") != nil {
return errors.New("property 'AgentPoolProfile.ScaleSetEvictionPolicy' must be empty for AgentPoolProfile.Priority of Regular")
}
}
if a.DNSPrefix != "" {
if e := common.ValidateDNSPrefix(a.DNSPrefix); e != nil {
return e
}
if len(a.Ports) > 0 {
if e := validateUniquePorts(a.Ports, a.Name); e != nil {
return e
}
} else {
a.Ports = []int{80, 443, 8080}
}
} else {
if e := validate.Var(a.Ports, "len=0"); e != nil {
return errors.Errorf("AgentPoolProfile.Ports must be empty when AgentPoolProfile.DNSPrefix is empty for Orchestrator: %s", string(orchestratorType))
}
}
if len(a.DiskSizesGB) > 0 {
if e := validate.Var(a.StorageProfile, "eq=StorageAccount|eq=ManagedDisks"); e != nil {
return errors.Errorf("property 'StorageProfile' must be set to either '%s' or '%s' when attaching disks", StorageAccount, ManagedDisks)
}
if e := validate.Var(a.AvailabilityProfile, "eq=VirtualMachineScaleSets|eq=AvailabilitySet"); e != nil {
return errors.Errorf("property 'AvailabilityProfile' must be set to either '%s' or '%s' when attaching disks", VirtualMachineScaleSets, AvailabilitySet)
}
if a.StorageProfile == StorageAccount && (a.AvailabilityProfile == VirtualMachineScaleSets) {
return errors.Errorf("VirtualMachineScaleSets does not support storage account attached disks. Instead specify 'StorageAccount': '%s' or specify AvailabilityProfile '%s'", ManagedDisks, AvailabilitySet)
}
}
return nil
}
func validateKeyVaultSecrets(secrets []KeyVaultSecrets, requireCertificateStore bool) error {
for _, s := range secrets {
if len(s.VaultCertificates) == 0 {
return errors.New("Valid KeyVaultSecrets must have no empty VaultCertificates")
}
if s.SourceVault == nil {
return errors.New("missing SourceVault in KeyVaultSecrets")
}
if s.SourceVault.ID == "" {
return errors.New("KeyVaultSecrets must have a SourceVault.ID")
}
for _, c := range s.VaultCertificates {
if _, e := url.Parse(c.CertificateURL); e != nil {
return errors.Errorf("Certificate url was invalid. received error %s", e)
}
if e := validateName(c.CertificateStore, "KeyVaultCertificate.CertificateStore"); requireCertificateStore && e != nil {
return errors.Errorf("%s for certificates in a WindowsProfile", e)
}
}
}
return nil
}
// Validate ensures that the WindowsProfile is valid
func (w *WindowsProfile) Validate(orchestratorType string) error {