This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 527
/
validate.go
1967 lines (1760 loc) · 77.9 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"
"regexp"
"strconv"
"strings"
"time"
"github.com/Azure/aks-engine/pkg/api/common"
"github.com/Azure/aks-engine/pkg/helpers"
"github.com/Azure/aks-engine/pkg/versions"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
"github.com/Azure/go-autorest/autorest/to"
"github.com/blang/semver"
"github.com/google/uuid"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
validator "gopkg.in/go-playground/validator.v9"
)
var (
validate *validator.Validate
keyvaultIDRegex *regexp.Regexp
labelValueRegex *regexp.Regexp
labelKeyRegex *regexp.Regexp
diskEncryptionSetIDRegex *regexp.Regexp
proximityPlacementGroupIDRegex *regexp.Regexp
// Any version has to be available in a container image from mcr.microsoft.com/oss/etcd-io/etcd:v[Version]
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.2.25", "3.2.26", "3.3.0", "3.3.1", "3.3.8", "3.3.9", "3.3.10", "3.3.13", "3.3.15", "3.3.18", "3.3.19", "3.3.22", "3.3.25"}
containerdValidVersions = [...]string{"1.3.2", "1.3.3", "1.3.4", "1.3.5", "1.3.6", "1.3.7", "1.3.8", "1.3.9", "1.4.4", "1.4.6"}
kubernetesImageBaseTypeValidVersions = [...]string{"", common.KubernetesImageBaseTypeGCR, common.KubernetesImageBaseTypeMCR}
cachingTypesValidValues = [...]string{"", string(compute.CachingTypesNone), string(compute.CachingTypesReadWrite), string(compute.CachingTypesReadOnly)}
linuxEth0MTUAllowedValues = [...]int{1500, 3900}
networkPluginPlusPolicyAllowed = []k8sNetworkConfig{
{
networkPlugin: "",
networkPolicy: "",
},
{
networkPlugin: "azure",
networkPolicy: "",
},
{
networkPlugin: "azure",
networkPolicy: "azure",
},
{
networkPlugin: "kubenet",
networkPolicy: "",
},
{
networkPlugin: "flannel",
networkPolicy: "",
},
{
networkPlugin: NetworkPluginCilium,
networkPolicy: NetworkPolicyCilium,
},
{
networkPlugin: "kubenet",
networkPolicy: "calico",
},
{
networkPlugin: "azure",
networkPolicy: "calico",
},
{
networkPlugin: "",
networkPolicy: "calico",
},
{
networkPlugin: "",
networkPolicy: NetworkPolicyCilium,
},
{
networkPlugin: NetworkPluginAntrea,
networkPolicy: NetworkPolicyAntrea,
},
{
networkPlugin: "azure",
networkPolicy: NetworkPolicyAntrea,
},
{
networkPlugin: "",
networkPolicy: NetworkPolicyAntrea,
},
{
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)
diskEncryptionSetIDRegex = regexp.MustCompile(`^/subscriptions/\S+/resourceGroups/\S+/providers/Microsoft.Compute/diskEncryptionSets/[^/\s]+$`)
proximityPlacementGroupIDRegex = regexp.MustCompile(`^/subscriptions/\S+/resourceGroups/\S+/providers/Microsoft.Compute/proximityPlacementGroups/[^/\s]+$`)
}
// 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(isUpdate); 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(isUpdate); 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.validateAADProfile(); e != nil {
return e
}
if e := a.validateCustomKubeComponent(); e != nil {
return e
}
if e := a.validateAzureStackSupport(); e != nil {
return e
}
if e := a.validateWindowsProfile(isUpdate); 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)
}
//ValidateOrchestratorProfile validates the orchestrator profile and the addons dependent on the version of the orchestrator
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 {
version := common.RationalizeReleaseAndVersion(
o.OrchestratorType,
o.OrchestratorRelease,
o.OrchestratorVersion,
isUpdate,
a.HasWindows(),
a.IsAzureStackCloud())
if a.IsAzureStackCloud() {
if version == "" && a.HasWindows() {
return errors.Errorf("the following OrchestratorProfile configuration is not supported on Azure Stack 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, true))
} else if version == "" {
return errors.Errorf("the following OrchestratorProfile configuration is not supported on Azure Stack: OrchestratorType: \"%s\", OrchestratorRelease: \"%s\", OrchestratorVersion: \"%s\". Please use one of the following versions: %v", o.OrchestratorType, o.OrchestratorRelease, o.OrchestratorVersion, common.GetAllSupportedKubernetesVersions(false, false, true))
}
} else {
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, false))
} 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, 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(), a.FeatureFlags.IsIPv6DualStackEnabled(), a.FeatureFlags.IsIPv6OnlyEnabled(), isUpdate)
if err != nil {
return err
}
if o.KubernetesConfig.EnableAggregatedAPIs {
if !o.KubernetesConfig.IsRBACEnabled() {
return errors.New("enableAggregatedAPIs requires the enableRbac feature as a prerequisite")
}
}
if to.Bool(o.KubernetesConfig.EnableDataEncryptionAtRest) {
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 to.Bool(o.KubernetesConfig.EnableEncryptionWithExternalKms) {
if to.Bool(a.OrchestratorProfile.KubernetesConfig.UseManagedIdentity) && a.OrchestratorProfile.KubernetesConfig.UserAssignedID == "" {
log.Warnf("Clusters with enableEncryptionWithExternalKms=true and system-assigned identity are not upgradable! You will not be able to upgrade your cluster using `aks-engine upgrade`")
}
}
if to.Bool(o.KubernetesConfig.EnablePodSecurityPolicy) {
log.Warnf("EnablePodSecurityPolicy is deprecated in favor of the addon pod-security-policy.")
if !o.KubernetesConfig.IsRBACEnabled() {
return errors.Errorf("enablePodSecurityPolicy requires the enableRbac feature as a prerequisite")
}
if len(o.KubernetesConfig.PodSecurityPolicyConfig) > 0 {
log.Warnf("Raw manifest for PodSecurityPolicy using PodSecurityPolicyConfig is deprecated in favor of the addon pod-security-policy. This will be ignored.")
}
}
if o.KubernetesConfig.LoadBalancerSku != "" {
if !strings.EqualFold(o.KubernetesConfig.LoadBalancerSku, StandardLoadBalancerSku) && !strings.EqualFold(o.KubernetesConfig.LoadBalancerSku, BasicLoadBalancerSku) {
return errors.Errorf("Invalid value for loadBalancerSku, only %s and %s are supported", StandardLoadBalancerSku, BasicLoadBalancerSku)
}
}
if o.KubernetesConfig.LoadBalancerSku == StandardLoadBalancerSku {
if !to.Bool(a.OrchestratorProfile.KubernetesConfig.ExcludeMasterFromStandardLB) {
return errors.Errorf("standard loadBalancerSku should exclude master nodes. Please set KubernetesConfig \"ExcludeMasterFromStandardLB\" to \"true\"")
}
}
if o.KubernetesConfig.LoadBalancerSku == BasicLoadBalancerSku {
if o.KubernetesConfig.LoadBalancerOutboundIPs != nil {
return errors.Errorf("kubernetesConfig.loadBalancerOutboundIPs configuration only supported for Standard loadBalancerSku=Standard")
}
}
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.")
}
if o.KubernetesConfig.MaximumLoadBalancerRuleCount < 0 {
return errors.New("maximumLoadBalancerRuleCount shouldn't be less than 0")
}
if o.KubernetesConfig.LoadBalancerOutboundIPs != nil {
if to.Int(o.KubernetesConfig.LoadBalancerOutboundIPs) > common.MaxLoadBalancerOutboundIPs {
return errors.Errorf("kubernetesConfig.loadBalancerOutboundIPs was set to %d, the maximum allowed is %d", to.Int(o.KubernetesConfig.LoadBalancerOutboundIPs), common.MaxLoadBalancerOutboundIPs)
}
}
// https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-outbound-rules-overview
if o.KubernetesConfig.LoadBalancerSku == StandardLoadBalancerSku && o.KubernetesConfig.OutboundRuleIdleTimeoutInMinutes != 0 && (o.KubernetesConfig.OutboundRuleIdleTimeoutInMinutes < 4 || o.KubernetesConfig.OutboundRuleIdleTimeoutInMinutes > 120) {
return errors.New("outboundRuleIdleTimeoutInMinutes shouldn't be less than 4 or greater than 120")
}
if a.IsAzureStackCloud() {
if to.Bool(o.KubernetesConfig.UseInstanceMetadata) {
return errors.New("useInstanceMetadata shouldn't be set to true as feature not yet supported on Azure Stack")
}
if o.KubernetesConfig.EtcdDiskSizeGB != "" {
etcdDiskSizeGB, err := strconv.Atoi(o.KubernetesConfig.EtcdDiskSizeGB)
if err != nil {
return errors.Errorf("could not convert EtcdDiskSizeGB to int")
}
if etcdDiskSizeGB > MaxAzureStackManagedDiskSize {
return errors.Errorf("EtcdDiskSizeGB max size supported on Azure Stack is %d", MaxAzureStackManagedDiskSize)
}
}
}
if o.KubernetesConfig.EtcdStorageLimitGB != 0 {
if o.KubernetesConfig.EtcdStorageLimitGB > 8 {
log.Warnf("EtcdStorageLimitGB of %d is larger than the recommended maximum of 8", o.KubernetesConfig.EtcdStorageLimitGB)
}
if o.KubernetesConfig.EtcdStorageLimitGB < 2 {
return errors.Errorf("EtcdStorageLimitGB value of %d is too small, the minimum allowed is 2", o.KubernetesConfig.EtcdStorageLimitGB)
}
}
}
} else {
version := common.RationalizeReleaseAndVersion(
o.OrchestratorType,
o.OrchestratorRelease,
o.OrchestratorVersion,
false,
a.HasWindows(),
a.IsAzureStackCloud())
if version == "" {
patchVersion := common.GetValidPatchVersion(o.OrchestratorType, o.OrchestratorVersion, isUpdate, a.HasWindows(), a.IsAzureStackCloud())
// 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 aks-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 aks-engine", o.OrchestratorType, o.OrchestratorRelease, o.OrchestratorVersion)
}
}
}
if a.HasFlatcar() && o.KubernetesConfig.NetworkPlugin == "azure" && o.KubernetesConfig.NetworkMode == NetworkModeBridge {
return errors.Errorf("Flatcar node pools require 'transparent' networkMode with Azure CNI")
}
return a.validateContainerRuntime(isUpdate)
}
func (a *Properties) validateMasterProfile(isUpdate bool) error {
m := a.MasterProfile
if m.Count == 1 && !isUpdate {
log.Warnf("Running only 1 control plane VM not recommended for production clusters, use 3 or 5 for control plane redundancy")
}
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() {
if !isUpdate {
log.Warnf("Clusters with a VMSS control plane are not upgradable! You will not be able to upgrade your cluster using `aks-engine upgrade`")
}
e := validateVMSS(a.OrchestratorProfile, false, m.StorageProfile, a.HasWindows(), a.IsAzureStackCloud())
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 && to.Bool(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")
}
if e := validateProximityPlacementGroupID(m.ProximityPlacementGroupID); e != nil {
return e
}
distroValues := DistroValues
if isUpdate {
distroValues = append(distroValues, AKSDockerEngine, AKS1604Deprecated, AKS1804Deprecated)
}
if !validateDistro(m.Distro, distroValues) {
switch m.Distro {
case AKSDockerEngine, AKS1604Deprecated:
return errors.Errorf("The %s distro is deprecated, please use %s instead", m.Distro, AKSUbuntu1604)
case AKS1804Deprecated:
return errors.Errorf("The %s distro is deprecated, please use %s instead", m.Distro, AKSUbuntu1804)
default:
return errors.Errorf("The %s distro is not supported", m.Distro)
}
}
if to.Bool(m.AuditDEnabled) {
if m.Distro != "" && !m.IsUbuntu() {
return errors.Errorf("You have enabled auditd for master vms, but you did not specify an Ubuntu-based distro.")
}
}
var validOSDiskCachingType bool
for _, valid := range cachingTypesValidValues {
if valid == m.OSDiskCachingType {
validOSDiskCachingType = true
}
}
if !validOSDiskCachingType {
return errors.Errorf("Invalid masterProfile osDiskCachingType value \"%s\", please use one of the following versions: %s", m.OSDiskCachingType, cachingTypesValidValues)
}
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 os type is linux if dual stack feature is enabled
if a.FeatureFlags.IsIPv6DualStackEnabled() || a.FeatureFlags.IsIPv6OnlyEnabled() {
if agentPoolProfile.OSType == Windows {
if a.FeatureFlags.IsIPv6DualStackEnabled() && !common.IsKubernetesVersionGe(a.OrchestratorProfile.OrchestratorVersion, "1.19.0") {
return errors.Errorf("Dual stack IPv6 feature is supported on Windows only from Kubernetes version 1.19, but OrchestratorProfile.OrchestratorVersion is '%s'", a.OrchestratorProfile.OrchestratorVersion)
}
if a.FeatureFlags.IsIPv6OnlyEnabled() {
return errors.Errorf("Single stack IPv6 feature is supported only with Linux, but agent pool '%s' is of os type %s", agentPoolProfile.Name, agentPoolProfile.OSType)
}
}
if agentPoolProfile.Distro == Flatcar {
return errors.Errorf("Dual stack and single stack IPv6 feature is currently supported only with Ubuntu, but agent pool '%s' is of distro type %s", agentPoolProfile.Name, agentPoolProfile.Distro)
}
}
// 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 to.Bool(agentPoolProfile.AcceleratedNetworkingEnabled) || to.Bool(agentPoolProfile.AcceleratedNetworkingEnabledWindows) {
if a.IsAzureStackCloud() {
return errors.Errorf("AcceleratedNetworkingEnabled or AcceleratedNetworkingEnabledWindows shouldn't be set to true as feature is not yet supported on Azure Stack")
} else if to.Bool(agentPoolProfile.AcceleratedNetworkingEnabledWindows) {
return errors.Errorf("Accelerated Networking is currently unstable for Windows + Kubernetes, please set acceleratedNetworkingEnabledWindows to false")
} else if e := validatePoolAcceleratedNetworking(agentPoolProfile.VMSize); e != nil {
return e
}
}
if to.Bool(agentPoolProfile.VMSSOverProvisioningEnabled) {
if agentPoolProfile.AvailabilityProfile == AvailabilitySet {
return errors.Errorf("You have specified VMSS Overprovisioning in agent pool %s, but you did not specify VMSS", agentPoolProfile.Name)
}
}
if to.Bool(agentPoolProfile.AuditDEnabled) {
if agentPoolProfile.Distro != "" && !agentPoolProfile.IsUbuntu() {
return errors.Errorf("You have enabled auditd in agent pool %s, but you did not specify an Ubuntu-based distro", agentPoolProfile.Name)
}
}
if to.Bool(agentPoolProfile.EnableVMSSNodePublicIP) {
if agentPoolProfile.AvailabilityProfile == AvailabilitySet {
return errors.Errorf("You have enabled VMSS node public IP in agent pool %s, but you did not specify VMSS", agentPoolProfile.Name)
}
if !strings.EqualFold(a.OrchestratorProfile.KubernetesConfig.LoadBalancerSku, BasicLoadBalancerSku) {
return errors.Errorf("You have enabled VMSS node public IP in agent pool %s, but you did not specify Basic Load Balancer SKU", agentPoolProfile.Name)
}
}
if e := agentPoolProfile.validateOrchestratorSpecificProperties(); e != nil {
return e
}
if agentPoolProfile.ImageRef != nil {
return agentPoolProfile.ImageRef.validateImageNameAndGroup()
}
if e := agentPoolProfile.validateAvailabilityProfile(); e != nil {
return e
}
if e := agentPoolProfile.validateRoles(); e != nil {
return e
}
if e := agentPoolProfile.validateCustomNodeLabels(); e != nil {
return e
}
if agentPoolProfile.AvailabilityProfile != AvailabilitySet {
e := validateVMSS(a.OrchestratorProfile, isUpdate, agentPoolProfile.StorageProfile, a.HasWindows(), a.IsAzureStackCloud())
if e != nil {
return e
}
}
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")
}
distroValues := DistroValues
if isUpdate {
distroValues = append(distroValues, AKSDockerEngine, AKS1604Deprecated, AKS1804Deprecated)
}
if !validateDistro(agentPoolProfile.Distro, distroValues) {
switch agentPoolProfile.Distro {
case AKSDockerEngine, AKS1604Deprecated:
return errors.Errorf("The %s distro is deprecated, please use %s instead", agentPoolProfile.Distro, AKSUbuntu1604)
case AKS1804Deprecated:
return errors.Errorf("The %s distro is deprecated, please use %s instead", agentPoolProfile.Distro, AKSUbuntu1804)
default:
return errors.Errorf("The %s distro is not supported", agentPoolProfile.Distro)
}
}
if e := agentPoolProfile.validateLoadBalancerBackendAddressPoolIDs(); e != nil {
return e
}
if agentPoolProfile.IsEphemeral() {
log.Warnf("Ephemeral disks are enabled for Agent Pool %s. This feature in AKS-Engine is experimental, and data could be lost in some cases.", agentPoolProfile.Name)
}
if e := validateProximityPlacementGroupID(agentPoolProfile.ProximityPlacementGroupID); e != nil {
return e
}
var validOSDiskCachingType, validDataDiskCachingType bool
for _, valid := range cachingTypesValidValues {
if valid == agentPoolProfile.OSDiskCachingType {
validOSDiskCachingType = true
}
if valid == agentPoolProfile.DataDiskCachingType {
validDataDiskCachingType = true
}
}
if !validOSDiskCachingType {
return errors.Errorf("Invalid osDiskCachingType value \"%s\" for agentPoolProfile \"%s\", please use one of the following versions: %s", agentPoolProfile.OSDiskCachingType, agentPoolProfile.Name, cachingTypesValidValues)
}
if !validDataDiskCachingType {
return errors.Errorf("Invalid dataDiskCachingType value \"%s\" for agentPoolProfile \"%s\", please use one of the following versions: %s", agentPoolProfile.DataDiskCachingType, agentPoolProfile.Name, cachingTypesValidValues)
}
if agentPoolProfile.IsEphemeral() {
if agentPoolProfile.OSDiskCachingType != "" && agentPoolProfile.OSDiskCachingType != string(compute.CachingTypesReadOnly) {
return errors.Errorf("Invalid osDiskCachingType value \"%s\" for agentPoolProfile \"%s\" using Ephemeral Disk, you must use: %s", agentPoolProfile.OSDiskCachingType, agentPoolProfile.Name, string(compute.CachingTypesReadOnly))
}
}
}
return nil
}
func (a *Properties) validateZones() error {
if a.HasAvailabilityZones() {
var poolsWithZones, poolsWithoutZones []string
for _, pool := range a.AgentPoolProfiles {
if pool.HasAvailabilityZones() {
poolsWithZones = append(poolsWithZones, pool.Name)
} else {
poolsWithoutZones = append(poolsWithoutZones, pool.Name)
}
}
if !a.MastersAndAgentsUseAvailabilityZones() {
poolsWithZonesPrefix := "pool"
poolsWithoutZonesPrefix := "pool"
if len(poolsWithZones) > 1 {
poolsWithZonesPrefix = "pools"
}
if len(poolsWithoutZones) > 1 {
poolsWithoutZonesPrefix = "pools"
}
poolsWithZonesString := helpers.GetEnglishOrderedQuotedListWithOxfordCommas(poolsWithZones)
poolsWithoutZonesString := helpers.GetEnglishOrderedQuotedListWithOxfordCommas(poolsWithoutZones)
if !a.MasterProfile.HasAvailabilityZones() {
if len(poolsWithZones) == len(a.AgentPoolProfiles) {
log.Warnf("This cluster is using Availability Zones for %s %s, but not for master VMs", poolsWithZonesPrefix, poolsWithZonesString)
} else {
log.Warnf("This cluster is using Availability Zones for %s %s, but not for %s %s, nor for master VMs", poolsWithZonesPrefix, poolsWithZonesString, poolsWithoutZonesPrefix, poolsWithoutZonesString)
}
} else {
if len(poolsWithoutZones) > 0 {
log.Warnf("This cluster is using Availability Zones for master VMs, but not for %s %s", poolsWithoutZonesPrefix, poolsWithoutZonesString)
}
}
} else {
// 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 a.OrchestratorProfile.KubernetesConfig != nil && a.OrchestratorProfile.KubernetesConfig.LoadBalancerSku != "" && !strings.EqualFold(a.OrchestratorProfile.KubernetesConfig.LoadBalancerSku, StandardLoadBalancerSku) {
return errors.New("Availability Zones requires Standard LoadBalancer. Please set KubernetesConfig \"LoadBalancerSku\" to \"Standard\"")
}
}
}
return nil
}
func (a *Properties) validateLinuxProfile() error {
var validEth0MTU bool
if a.LinuxProfile.Eth0MTU != 0 {
if a.OrchestratorProfile != nil &&
a.OrchestratorProfile.KubernetesConfig != nil &&
a.OrchestratorProfile.KubernetesConfig.NetworkPlugin == NetworkPluginKubenet {
return errors.Errorf("Custom linuxProfile eth0MTU value not allowed when using Kubenet")
}
for _, valid := range linuxEth0MTUAllowedValues {
if valid == a.LinuxProfile.Eth0MTU {
validEth0MTU = true
break
}
}
if !validEth0MTU {
allowedMTUs := ""
for _, mtu := range linuxEth0MTUAllowedValues {
allowedMTUs += strconv.Itoa(mtu) + ", "
}
allowedMTUs = strings.TrimRight(allowedMTUs, ", ")
return errors.Errorf("Invalid linuxProfile eth0MTU value \"%d\", please use one of the following values: %s", a.LinuxProfile.Eth0MTU, allowedMTUs)
}
}
for _, publicKey := range a.LinuxProfile.SSH.PublicKeys {
if e := validate.Var(publicKey.KeyData, "required"); e != nil {
return errors.New("KeyData in LinuxProfile.SSH.PublicKeys cannot be empty string")
}
}
if a.LinuxProfile.EnableUnattendedUpgrades == nil {
log.Warnf("linuxProfile.enableUnattendedUpgrades configuration was not declared, your cluster nodes will be configured to run unattended-upgrade by default")
}
return validateKeyVaultSecrets(a.LinuxProfile.Secrets, false)
}
func (a *Properties) validateAddons(isUpdate bool) error {
if a.OrchestratorProfile.KubernetesConfig != nil && a.OrchestratorProfile.KubernetesConfig.Addons != nil {
var isAvailabilitySets bool
var kubeDNSEnabled bool
var corednsEnabled bool
var keyvaultFlexvolumeEnabled, csiSecretsStoreEnabled bool
for _, agentPool := range a.AgentPoolProfiles {
if agentPool.IsAvailabilitySets() {
isAvailabilitySets = 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)
}
}
if addon.Mode != "" {
if addon.Mode != AddonModeEnsureExists && addon.Mode != AddonModeReconcile {
return errors.Errorf("addon %s has a mode configuration '%s', must be either %s or %s", addon.Name, addon.Mode, AddonModeEnsureExists, AddonModeReconcile)
}
}
// Validation for addons if they are enabled
if to.Bool(addon.Enabled) {
switch addon.Name {
case "cluster-autoscaler":
if isAvailabilitySets {
return errors.Errorf("cluster-autoscaler addon can only be used with VirtualMachineScaleSets. Please specify \"availabilityProfile\": \"%s\"", VirtualMachineScaleSets)
}
for _, pool := range addon.Pools {
if pool.Name == "" {
return errors.Errorf("cluster-autoscaler addon pools configuration must have a 'name' property that correlates with a pool name in the agentPoolProfiles array")
}
if a.GetAgentPoolByName(pool.Name) == nil {
return errors.Errorf("cluster-autoscaler addon pool 'name' %s does not match any agentPoolProfiles nodepool name", pool.Name)
}
if pool.Config != nil {
var min, max int
var err error
if pool.Config["min-nodes"] != "" {
min, err = strconv.Atoi(pool.Config["min-nodes"])
if err != nil {
return errors.Errorf("cluster-autoscaler addon pool 'name' %s has invalid 'min-nodes' config, must be a string int, got %s", pool.Name, pool.Config["min-nodes"])
}
}
if pool.Config["max-nodes"] != "" {
max, err = strconv.Atoi(pool.Config["max-nodes"])
if err != nil {
return errors.Errorf("cluster-autoscaler addon pool 'name' %s has invalid 'max-nodes' config, must be a string int, got %s", pool.Name, pool.Config["max-nodes"])
}
}
if min > max {
return errors.Errorf("cluster-autoscaler addon pool 'name' %s has invalid config, 'max-nodes' %d must be greater than or equal to 'min-nodes' %d", pool.Name, max, min)
}
}
}
case "aad":
if !a.HasAADAdminGroupID() {
return errors.New("aad addon can't be enabled without a valid aadProfile w/ adminGroupID")
}
case "keyvault-flexvolume":
keyvaultFlexvolumeEnabled = true
if common.IsKubernetesVersionGe(a.OrchestratorProfile.OrchestratorVersion, "1.16.0") {
log.Warnf("%s add-on is DEPRECATED in favor of csi-secrets-store addon for 1.16+", addon.Name)
}
case "appgw-ingress":
if (a.ServicePrincipalProfile == nil || len(a.ServicePrincipalProfile.ObjectID) == 0) &&
!to.Bool(a.OrchestratorProfile.KubernetesConfig.UseManagedIdentity) {
return errors.New("appgw-ingress add-ons requires 'objectID' to be specified or UseManagedIdentity to be true")
}
if a.OrchestratorProfile.KubernetesConfig.NetworkPlugin != "azure" {
return errors.New("appgw-ingress add-ons can only be used with Network Plugin as 'azure'")
}
if len(addon.Config["appgw-subnet"]) == 0 {
return errors.New("appgw-ingress add-ons requires 'appgw-subnet' in the Config. It is used to provision the subnet for Application Gateway in the vnet")
}
case "cloud-node-manager":
if !to.Bool(a.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager) {
return errors.Errorf("%s add-on requires useCloudControllerManager to be true", addon.Name)
}
if !a.ShouldEnableAzureCloudAddon(addon.Name) {
minVersion := "1.16.0"
if a.HasWindows() {
minVersion = "1.18.0"
}
return errors.Errorf("%s add-on can only be used Kubernetes %s or above", addon.Name, minVersion)
}
case common.CiliumAddonName:
if !common.IsKubernetesVersionGe(a.OrchestratorProfile.OrchestratorVersion, "1.16.0") {
if a.OrchestratorProfile.KubernetesConfig.NetworkPolicy != NetworkPolicyCilium {
return errors.Errorf("%s addon may only be enabled if the networkPolicy=%s", common.CiliumAddonName, NetworkPolicyCilium)
}
} else {
return errors.Errorf("%s addon is not supported on Kubernetes v1.16.0 or greater", common.CiliumAddonName)
}
case common.AntreaAddonName:
if a.OrchestratorProfile.KubernetesConfig.NetworkPolicy != NetworkPolicyAntrea {
return errors.Errorf("%s addon may only be enabled if the networkPolicy=%s", common.AntreaAddonName, NetworkPolicyAntrea)
}
case common.FlannelAddonName:
if isUpdate {
if a.OrchestratorProfile.KubernetesConfig.NetworkPolicy != "" {
return errors.Errorf("%s addon does not support NetworkPolicy, replace %s with \"\"", common.FlannelAddonName, a.OrchestratorProfile.KubernetesConfig.NetworkPolicy)
}
networkPlugin := a.OrchestratorProfile.KubernetesConfig.NetworkPlugin
if networkPlugin != "" {
if networkPlugin != NetworkPluginFlannel {
return errors.Errorf("%s addon is not supported with networkPlugin=%s, please use networkPlugin=%s", common.FlannelAddonName, networkPlugin, NetworkPluginFlannel)
}
}
if a.OrchestratorProfile.KubernetesConfig.ContainerRuntime != Containerd {
return errors.Errorf("%s addon is only supported with containerRuntime=%s", common.FlannelAddonName, Containerd)
}
} else {
return errors.Errorf("%s addon is deprecated for new clusters", common.FlannelAddonName)
}
case common.KubeDNSAddonName:
kubeDNSEnabled = true
case common.CoreDNSAddonName:
corednsEnabled = true
case common.SecretsStoreCSIDriverAddonName:
csiSecretsStoreEnabled = true
if !common.IsKubernetesVersionGe(a.OrchestratorProfile.OrchestratorVersion, "1.16.0") {
return errors.Errorf("%s add-on can only be used in 1.16+", addon.Name)
}
case common.AzureArcOnboardingAddonName:
if err := addon.validateArcAddonConfig(); err != nil {
return err
}
case common.ReschedulerAddonName:
if isUpdate {
log.Warnf("The rescheduler addon has been deprecated and disabled, it will be removed during this update")
}
return errors.Errorf("The rescheduler addon has been deprecated and disabled, please remove it from your cluster configuration before creating a new cluster")
case common.DashboardAddonName:
log.Warnf("The kube-dashboard addon is deprecated, we recommend you install the dashboard yourself, see https://github.com/kubernetes/dashboard")
case common.AzureCNINetworkMonitorAddonName:
if isUpdate {
log.Warnf("The Azure CNI networkmonitor addon has been deprecated, it will be marked as disabled")
}
}
} else {
// Validation for addons if they are disabled
switch addon.Name {
case "cloud-node-manager":
if a.ShouldEnableAzureCloudAddon(addon.Name) {
minVersion := "1.16.0"
if a.HasWindows() {
minVersion = "1.18.0"
}
return errors.Errorf("%s add-on is required when useCloudControllerManager is true in Kubernetes %s or above", addon.Name, minVersion)
}
case common.AzureCloudProviderAddonName:
return errors.Errorf("%s add-on is required, it cannot be disabled", addon.Name)
}
}
}
if kubeDNSEnabled && corednsEnabled {
return errors.New("Both kube-dns and coredns addons are enabled, only one of these may be enabled on a cluster")
}
if keyvaultFlexvolumeEnabled && csiSecretsStoreEnabled {
return errors.New("Both keyvault-flexvolume and csi-secrets-store addons are enabled, only one of these may be enabled on a cluster")
}
}
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)
}
if agentPool.OSType == Windows && len(agentPool.Extensions) != 0 {
for _, e := range agentPool.Extensions {
if e.Name == "prometheus-grafana-k8s" {
return errors.Errorf("prometheus-grafana-k8s extension is currently not supported for Windows agents")
}
}
}
}
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 {
useManagedIdentityDisabled := a.OrchestratorProfile.KubernetesConfig != nil &&
a.OrchestratorProfile.KubernetesConfig.UseManagedIdentity != nil && !to.Bool(a.OrchestratorProfile.KubernetesConfig.UseManagedIdentity)
if useManagedIdentityDisabled {
if a.ServicePrincipalProfile == nil {
return errors.Errorf("ServicePrincipalProfile must be specified")
}
if e := validate.Var(a.ServicePrincipalProfile.ClientID, "required"); e != nil {
return errors.Errorf("the service principal client ID must be specified")
}
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")
}
if a.OrchestratorProfile.KubernetesConfig != nil && to.Bool(a.OrchestratorProfile.KubernetesConfig.EnableEncryptionWithExternalKms) && len(a.ServicePrincipalProfile.ObjectID) == 0 {
return errors.Errorf("the service principal object ID must be specified when enableEncryptionWithExternalKms is true")
}
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")
}
if e := validate.Var(a.ServicePrincipalProfile.KeyvaultSecretRef.SecretName, "required"); e != nil {
return errors.Errorf("the Keyvault Secret must be specified for the Service Principle")
}
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) validateAADProfile() error {
if profile := a.AADProfile; profile != nil {
if _, err := uuid.Parse(profile.ClientAppID); err != nil {
return errors.Errorf("clientAppID '%v' is invalid", profile.ClientAppID)
}
if _, err := uuid.Parse(profile.ServerAppID); err != nil {
return errors.Errorf("serverAppID '%v' is invalid", profile.ServerAppID)
}
if len(profile.TenantID) > 0 {
if _, err := uuid.Parse(profile.TenantID); err != nil {
return errors.Errorf("tenantID '%v' is invalid", profile.TenantID)
}
}
if len(profile.AdminGroupID) > 0 {
if _, err := uuid.Parse(profile.AdminGroupID); err != nil {
return errors.Errorf("adminGroupID '%v' is invalid", profile.AdminGroupID)
}
}
}
return nil
}
func (a *AgentPoolProfile) validateAvailabilityProfile() 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)
}
}
return nil
}
func (a *AgentPoolProfile) validateRoles() error {
validRoles := []AgentPoolProfileRole{AgentPoolProfileRoleEmpty}
var found bool
for _, validRole := range validRoles {
if a.Role == validRole {
found = true
break
}
}
if !found {
return errors.Errorf("Role %q is not supported", a.Role)
}
return nil
}
func (a *AgentPoolProfile) validateCustomNodeLabels() error {
if len(a.CustomNodeLabels) > 0 {
for k, v := range a.CustomNodeLabels {
if e := validateKubernetesLabelKey(k); e != nil {
return e
}