-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathinstallconfig.go
1519 lines (1323 loc) · 62.5 KB
/
installconfig.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
package validation
import (
"fmt"
"net"
"net/url"
"os"
"regexp"
"sort"
"strconv"
"strings"
dockerref "github.com/containers/image/v5/docker/reference"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
utilsnet "k8s.io/utils/net"
configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
operv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/installer/pkg/hostcrypt"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
awsvalidation "github.com/openshift/installer/pkg/types/aws/validation"
"github.com/openshift/installer/pkg/types/azure"
azurevalidation "github.com/openshift/installer/pkg/types/azure/validation"
"github.com/openshift/installer/pkg/types/baremetal"
baremetalvalidation "github.com/openshift/installer/pkg/types/baremetal/validation"
"github.com/openshift/installer/pkg/types/external"
"github.com/openshift/installer/pkg/types/featuregates"
"github.com/openshift/installer/pkg/types/gcp"
gcpvalidation "github.com/openshift/installer/pkg/types/gcp/validation"
"github.com/openshift/installer/pkg/types/ibmcloud"
ibmcloudvalidation "github.com/openshift/installer/pkg/types/ibmcloud/validation"
"github.com/openshift/installer/pkg/types/nutanix"
nutanixvalidation "github.com/openshift/installer/pkg/types/nutanix/validation"
"github.com/openshift/installer/pkg/types/openstack"
openstackvalidation "github.com/openshift/installer/pkg/types/openstack/validation"
"github.com/openshift/installer/pkg/types/ovirt"
ovirtvalidation "github.com/openshift/installer/pkg/types/ovirt/validation"
"github.com/openshift/installer/pkg/types/powervs"
powervsvalidation "github.com/openshift/installer/pkg/types/powervs/validation"
"github.com/openshift/installer/pkg/types/vsphere"
vspherevalidation "github.com/openshift/installer/pkg/types/vsphere/validation"
"github.com/openshift/installer/pkg/validate"
"github.com/openshift/installer/pkg/version"
)
// hostCryptBypassedAnnotation is set if the host crypt check was bypassed via environment variable.
const hostCryptBypassedAnnotation = "install.openshift.io/hostcrypt-check-bypassed"
// list of known plugins that require hostPrefix to be set
var pluginsUsingHostPrefix = sets.NewString(string(operv1.NetworkTypeOVNKubernetes))
// ValidateInstallConfig checks that the specified install config is valid.
//
//nolint:gocyclo
func ValidateInstallConfig(c *types.InstallConfig, usingAgentMethod bool) field.ErrorList {
allErrs := field.ErrorList{}
if c.TypeMeta.APIVersion == "" {
return field.ErrorList{field.Required(field.NewPath("apiVersion"), "install-config version required")}
}
switch v := c.APIVersion; v {
case types.InstallConfigVersion:
// Current version
default:
return field.ErrorList{field.Invalid(field.NewPath("apiVersion"), c.TypeMeta.APIVersion, fmt.Sprintf("install-config version must be %q", types.InstallConfigVersion))}
}
if c.FIPS {
allErrs = append(allErrs, validateFIPSconfig(c)...)
} else if c.SSHKey != "" {
if err := validate.SSHPublicKey(c.SSHKey); err != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("sshKey"), c.SSHKey, err.Error()))
}
}
if c.AdditionalTrustBundle != "" {
if err := validate.CABundle(c.AdditionalTrustBundle); err != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("additionalTrustBundle"), c.AdditionalTrustBundle, err.Error()))
}
}
if c.AdditionalTrustBundlePolicy != "" {
if err := validateAdditionalCABundlePolicy(c); err != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("additionalTrustBundlePolicy"), c.AdditionalTrustBundlePolicy, err.Error()))
}
}
nameErr := validate.ClusterName(c.ObjectMeta.Name)
if c.Platform.GCP != nil || c.Platform.Azure != nil {
nameErr = validate.ClusterName1035(c.ObjectMeta.Name)
}
if c.Platform.VSphere != nil || c.Platform.BareMetal != nil || c.Platform.OpenStack != nil || c.Platform.Nutanix != nil {
nameErr = validate.OnPremClusterName(c.ObjectMeta.Name)
}
if nameErr != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "name"), c.ObjectMeta.Name, nameErr.Error()))
}
baseDomainErr := validate.DomainName(c.BaseDomain, true)
if baseDomainErr != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("baseDomain"), c.BaseDomain, baseDomainErr.Error()))
}
if nameErr == nil && baseDomainErr == nil {
clusterDomain := c.ClusterDomain()
if err := validate.DomainName(clusterDomain, true); err != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("baseDomain"), clusterDomain, err.Error()))
}
}
if c.Networking != nil {
allErrs = append(allErrs, validateNetworking(c.Networking, field.NewPath("networking"))...)
allErrs = append(allErrs, validateNetworkingIPVersion(c.Networking, &c.Platform)...)
allErrs = append(allErrs, validateNetworkingClusterNetworkMTU(c, field.NewPath("networking", "clusterNetworkMTU"))...)
allErrs = append(allErrs, validateVIPsForPlatform(c.Networking, &c.Platform, field.NewPath("platform"))...)
allErrs = append(allErrs, validateOVNKubernetesConfig(c.Networking, field.NewPath("networking"))...)
} else {
allErrs = append(allErrs, field.Required(field.NewPath("networking"), "networking is required"))
}
allErrs = append(allErrs, validatePlatform(&c.Platform, usingAgentMethod, field.NewPath("platform"), c.Networking, c)...)
if c.ControlPlane != nil {
allErrs = append(allErrs, validateControlPlane(&c.Platform, c.ControlPlane, field.NewPath("controlPlane"))...)
} else {
allErrs = append(allErrs, field.Required(field.NewPath("controlPlane"), "controlPlane is required"))
}
multiArchEnabled := types.MultiArchFeatureGateEnabled(c.Platform.Name(), c.EnabledFeatureGates())
allErrs = append(allErrs, validateCompute(&c.Platform, c.ControlPlane, c.Compute, field.NewPath("compute"), multiArchEnabled)...)
releaseArch, err := version.ReleaseArchitecture()
if err != nil {
allErrs = append(allErrs, field.InternalError(nil, err))
} else {
allErrs = append(allErrs, validateReleaseArchitecture(c.ControlPlane, c.Compute, types.Architecture(releaseArch))...)
}
if err := validate.ImagePullSecret(c.PullSecret); err != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("pullSecret"), c.PullSecret, err.Error()))
}
if c.Proxy != nil {
allErrs = append(allErrs, validateProxy(c.Proxy, c, field.NewPath("proxy"))...)
}
allErrs = append(allErrs, validateImageContentSources(c.DeprecatedImageContentSources, field.NewPath("imageContentSources"))...)
if _, ok := validPublishingStrategies[c.Publish]; !ok {
allErrs = append(allErrs, field.NotSupported(field.NewPath("publish"), c.Publish, validPublishingStrategyValues))
}
allErrs = append(allErrs, validateImageDigestSources(c.ImageDigestSources, field.NewPath("imageDigestSources"))...)
if _, ok := validPublishingStrategies[c.Publish]; !ok {
allErrs = append(allErrs, field.NotSupported(field.NewPath("publish"), c.Publish, validPublishingStrategyValues))
}
if len(c.DeprecatedImageContentSources) != 0 && len(c.ImageDigestSources) != 0 {
allErrs = append(allErrs, field.Invalid(field.NewPath("imageContentSources"), c.Publish, "cannot set imageContentSources and imageDigestSources at the same time"))
}
if len(c.DeprecatedImageContentSources) != 0 {
logrus.Warningln("imageContentSources is deprecated, please use ImageDigestSources")
}
allErrs = append(allErrs, validateCloudCredentialsMode(c.CredentialsMode, field.NewPath("credentialsMode"), c.Platform)...)
if c.Capabilities != nil {
allErrs = append(allErrs, validateCapabilities(c.Capabilities, field.NewPath("capabilities"))...)
}
if c.Publish == types.InternalPublishingStrategy {
switch platformName := c.Platform.Name(); platformName {
case aws.Name, azure.Name, gcp.Name, ibmcloud.Name, powervs.Name:
default:
allErrs = append(allErrs, field.Invalid(field.NewPath("publish"), c.Publish, fmt.Sprintf("Internal publish strategy is not supported on %q platform", platformName)))
}
}
if c.Publish == types.MixedPublishingStrategy {
switch platformName := c.Platform.Name(); platformName {
case azure.Name:
default:
allErrs = append(allErrs, field.Invalid(field.NewPath("publish"), c.Publish, fmt.Sprintf("mixed publish strategy is not supported on %q platform", platformName)))
}
if c.OperatorPublishingStrategy == nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("publish"), c.Publish, "please specify the operator publishing strategy for mixed publish strategy"))
}
} else if c.OperatorPublishingStrategy != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("operatorPublishingStrategy"), c.Publish, "operator publishing strategy is only allowed with mixed publishing strategy installs"))
}
if c.OperatorPublishingStrategy != nil {
acceptedValues := sets.New[string]("Internal", "External")
if c.OperatorPublishingStrategy.APIServer == "" {
c.OperatorPublishingStrategy.APIServer = "External"
}
if c.OperatorPublishingStrategy.Ingress == "" {
c.OperatorPublishingStrategy.Ingress = "External"
}
if !acceptedValues.Has(c.OperatorPublishingStrategy.APIServer) {
allErrs = append(allErrs, field.NotSupported(field.NewPath("apiserver"), c.OperatorPublishingStrategy.APIServer, sets.List(acceptedValues)))
}
if !acceptedValues.Has(c.OperatorPublishingStrategy.Ingress) {
allErrs = append(allErrs, field.NotSupported(field.NewPath("ingress"), c.OperatorPublishingStrategy.Ingress, sets.List(acceptedValues)))
}
if c.OperatorPublishingStrategy.APIServer == "Internal" && c.OperatorPublishingStrategy.Ingress == "Internal" {
allErrs = append(allErrs, field.Invalid(field.NewPath("publish"), c.OperatorPublishingStrategy.APIServer, "cannot set both fields to internal in a mixed cluster, use publish internal instead"))
}
}
if c.Capabilities != nil {
capSet := c.Capabilities.BaselineCapabilitySet
if capSet == "" {
capSet = configv1.ClusterVersionCapabilitySetCurrent
}
enabledCaps := sets.New[configv1.ClusterVersionCapability](configv1.ClusterVersionCapabilitySets[capSet]...)
enabledCaps.Insert(c.Capabilities.AdditionalEnabledCapabilities...)
if c.Capabilities.BaselineCapabilitySet == configv1.ClusterVersionCapabilitySetNone {
enabledCaps := sets.New[configv1.ClusterVersionCapability](c.Capabilities.AdditionalEnabledCapabilities...)
if enabledCaps.Has(configv1.ClusterVersionCapabilityMarketplace) && !enabledCaps.Has(configv1.ClusterVersionCapabilityOperatorLifecycleManager) {
allErrs = append(allErrs, field.Invalid(field.NewPath("additionalEnabledCapabilities"), c.Capabilities.AdditionalEnabledCapabilities,
"the marketplace capability requires the OperatorLifecycleManager capability"))
}
if c.Platform.BareMetal != nil && !enabledCaps.Has(configv1.ClusterVersionCapabilityBaremetal) {
allErrs = append(allErrs, field.Invalid(field.NewPath("additionalEnabledCapabilities"), c.Capabilities.AdditionalEnabledCapabilities,
"platform baremetal requires the baremetal capability"))
}
}
if enabledCaps.Has(configv1.ClusterVersionCapabilityMarketplace) && !enabledCaps.Has(configv1.ClusterVersionCapabilityOperatorLifecycleManager) {
allErrs = append(allErrs, field.Invalid(field.NewPath("additionalEnabledCapabilities"), c.Capabilities.AdditionalEnabledCapabilities,
"the marketplace capability requires the OperatorLifecycleManager capability"))
}
if !enabledCaps.Has(configv1.ClusterVersionCapabilityCloudCredential) {
// check if platform is cloud
if c.None == nil && c.BareMetal == nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("capabilities"), c.Capabilities,
"disabling CloudCredential capability available only for baremetal platforms"))
}
}
if !enabledCaps.Has(configv1.ClusterVersionCapabilityCloudControllerManager) {
if c.None == nil && c.BareMetal == nil && c.External == nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("capabilities"), c.Capabilities,
"disabling CloudControllerManager is only supported on the Baremetal, None, or External platform with cloudControllerManager value none"))
}
if c.External != nil && c.External.CloudControllerManager == external.CloudControllerManagerTypeExternal {
allErrs = append(allErrs, field.Invalid(field.NewPath("capabilities"), c.Capabilities,
"disabling CloudControllerManager on External platform supported only with cloudControllerManager value none"))
}
}
if !enabledCaps.Has(configv1.ClusterVersionCapabilityIngress) {
allErrs = append(allErrs, field.Invalid(field.NewPath("capabilities"), c.Capabilities,
"the Ingress capability is required"))
}
}
allErrs = append(allErrs, ValidateFeatureSet(c)...)
return allErrs
}
// ipAddressType indicates the address types provided for a given field
type ipAddressType struct {
IPv4 bool
IPv6 bool
Primary corev1.IPFamily
}
// ipAddressTypeByField is a map of field path to ipAddressType
type ipAddressTypeByField map[string]ipAddressType
// ipNetByField is a map of field path to the IPNets
type ipNetByField map[string][]ipnet.IPNet
// inferIPVersionFromInstallConfig infers the user's desired ip version from the networking config.
// Presence field names match the field path of the struct within the Networking type. This function
// assumes a valid install config.
func inferIPVersionFromInstallConfig(n *types.Networking) (hasIPv4, hasIPv6 bool, presence ipAddressTypeByField, addresses ipNetByField) {
if n == nil {
return
}
addresses = make(ipNetByField)
for _, network := range n.MachineNetwork {
addresses["machineNetwork"] = append(addresses["machineNetwork"], network.CIDR)
}
for _, network := range n.ServiceNetwork {
addresses["serviceNetwork"] = append(addresses["serviceNetwork"], network)
}
for _, network := range n.ClusterNetwork {
addresses["clusterNetwork"] = append(addresses["clusterNetwork"], network.CIDR)
}
presence = make(ipAddressTypeByField)
for k, ipnets := range addresses {
for i, ipnet := range ipnets {
has := presence[k]
if ipnet.IP.To4() != nil {
has.IPv4 = true
if i == 0 {
has.Primary = corev1.IPv4Protocol
}
if k == "serviceNetwork" {
hasIPv4 = true
}
} else {
has.IPv6 = true
if i == 0 {
has.Primary = corev1.IPv6Protocol
}
if k == "serviceNetwork" {
hasIPv6 = true
}
}
presence[k] = has
}
}
return
}
func ipnetworksToStrings(networks []ipnet.IPNet) []string {
var diag []string
for _, sn := range networks {
diag = append(diag, sn.String())
}
return diag
}
// validateNetworkingIPVersion checks parameters for consistency when the user
// requests single-stack IPv6 or dual-stack modes.
func validateNetworkingIPVersion(n *types.Networking, p *types.Platform) field.ErrorList {
var allErrs field.ErrorList
hasIPv4, hasIPv6, presence, addresses := inferIPVersionFromInstallConfig(n)
switch {
case hasIPv4 && hasIPv6:
if len(n.ServiceNetwork) != 2 {
allErrs = append(allErrs, field.Invalid(field.NewPath("networking", "serviceNetwork"), strings.Join(ipnetworksToStrings(n.ServiceNetwork), ", "), "when installing dual-stack IPv4/IPv6 you must provide two service networks, one for each IP address type"))
}
allowV6Primary := false
experimentalDualStackEnabled, _ := strconv.ParseBool(os.Getenv("OPENSHIFT_INSTALL_EXPERIMENTAL_DUAL_STACK"))
switch {
case p.Azure != nil && experimentalDualStackEnabled:
logrus.Warnf("Using experimental Azure dual-stack support")
case p.BareMetal != nil:
// We now support ipv6-primary dual stack on baremetal
allowV6Primary = true
case p.VSphere != nil:
// as well as on vSphere
allowV6Primary = true
case p.OpenStack != nil:
allowV6Primary = true
case p.Ovirt != nil:
case p.Nutanix != nil:
case p.None != nil:
case p.External != nil:
default:
allErrs = append(allErrs, field.Invalid(field.NewPath("networking"), "DualStack", "dual-stack IPv4/IPv6 is not supported for this platform, specify only one type of address"))
}
for k, v := range presence {
switch {
case v.IPv4 && !v.IPv6:
allErrs = append(allErrs, field.Invalid(field.NewPath("networking", k), strings.Join(ipnetworksToStrings(addresses[k]), ", "), "dual-stack IPv4/IPv6 requires an IPv6 network in this list"))
case !v.IPv4 && v.IPv6:
allErrs = append(allErrs, field.Invalid(field.NewPath("networking", k), strings.Join(ipnetworksToStrings(addresses[k]), ", "), "dual-stack IPv4/IPv6 requires an IPv4 network in this list"))
}
// FIXME: we should allow either all-networks-IPv4Primary or
// all-networks-IPv6Primary, but the latter currently causes
// confusing install failures, so block it.
if !allowV6Primary && v.IPv4 && v.IPv6 && v.Primary != corev1.IPv4Protocol {
allErrs = append(allErrs, field.Invalid(field.NewPath("networking", k), strings.Join(ipnetworksToStrings(addresses[k]), ", "), "IPv4 addresses must be listed before IPv6 addresses"))
}
}
case hasIPv6:
switch {
case p.BareMetal != nil:
case p.VSphere != nil:
case p.OpenStack != nil:
case p.Ovirt != nil:
case p.Nutanix != nil:
case p.None != nil:
case p.External != nil:
case p.Azure != nil && p.Azure.CloudName == azure.StackCloud:
allErrs = append(allErrs, field.Invalid(field.NewPath("networking"), "IPv6", "Azure Stack does not support IPv6"))
default:
allErrs = append(allErrs, field.Invalid(field.NewPath("networking"), "IPv6", "single-stack IPv6 is not supported for this platform"))
}
case hasIPv4:
if len(n.ServiceNetwork) > 1 {
allErrs = append(allErrs, field.Invalid(field.NewPath("networking", "serviceNetwork"), strings.Join(ipnetworksToStrings(n.ServiceNetwork), ", "), "only one service network can be specified"))
}
default:
// we should have a validation error for no specified machineNetwork, serviceNetwork, or clusterNetwork
}
return allErrs
}
func validateNetworking(n *types.Networking, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if len(n.NetworkType) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("networkType"), "network provider type required"))
}
// NOTE(dulek): We're hardcoding "Kuryr" here as the plan is to remove it from the API very soon. We can remove
// this check once some more general validation of the supported NetworkTypes is in place.
if strings.EqualFold(n.NetworkType, "Kuryr") {
allErrs = append(allErrs, field.Invalid(fldPath.Child("networkType"), n.NetworkType, "networkType Kuryr is not supported on OpenShift later than 4.14"))
}
if strings.EqualFold(n.NetworkType, string(operv1.NetworkTypeOpenShiftSDN)) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("networkType"), n.NetworkType, "networkType OpenShiftSDN is not supported, please use OVNKubernetes"))
}
if len(n.MachineNetwork) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("machineNetwork"), "at least one machine network is required"))
}
for i, mn := range n.MachineNetwork {
allErrs = append(allErrs, validateMachineNetwork(n, &mn, i, fldPath.Child("machineNetwork").Index(i))...)
}
if len(n.ServiceNetwork) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("serviceNetwork"), "a service network is required"))
}
for i, sn := range n.ServiceNetwork {
allErrs = append(allErrs, validateServiceNetwork(n, &sn, i, fldPath.Child("serviceNetwork").Index(i))...)
}
if len(n.ClusterNetwork) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("clusterNetwork"), "cluster network required"))
}
for i, cn := range n.ClusterNetwork {
allErrs = append(allErrs, validateClusterNetwork(n, &cn, i, fldPath.Child("clusterNetwork").Index(i))...)
}
return allErrs
}
func validateMachineNetwork(n *types.Networking, mn *types.MachineNetworkEntry, idx int, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if err := validate.SubnetCIDR(&mn.CIDR.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath, mn.CIDR.String(), err.Error()))
return allErrs // CIDR value is invalid, so no further validation.
}
if validate.DoCIDRsOverlap(&mn.CIDR.IPNet, validate.DockerBridgeSubnet) {
logrus.Warnf("%s: %s overlaps with default Docker Bridge subnet", fldPath, mn.CIDR.String())
}
allErrs = append(allErrs, validateNetworkNotOverlapDefaultOVNSubnets(n, &mn.CIDR.IPNet, fldPath)...)
for i, subNetwork := range n.MachineNetwork[0:idx] {
if validate.DoCIDRsOverlap(&mn.CIDR.IPNet, &subNetwork.CIDR.IPNet) {
allErrs = append(allErrs, field.Invalid(fldPath, mn.CIDR.String(), fmt.Sprintf("machine network must not overlap with machine network %d", i)))
}
}
return allErrs
}
func validateServiceNetwork(n *types.Networking, sn *ipnet.IPNet, idx int, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if err := validate.ServiceSubnetCIDR(&sn.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath, sn.String(), err.Error()))
return allErrs // CIDR value is invalid, so no further validation.
}
if validate.DoCIDRsOverlap(&sn.IPNet, validate.DockerBridgeSubnet) {
logrus.Warnf("%s: %s overlaps with default Docker Bridge subnet", fldPath, sn.String())
}
allErrs = append(allErrs, validateNetworkNotOverlapDefaultOVNSubnets(n, &sn.IPNet, fldPath)...)
for _, mn := range n.MachineNetwork {
if validate.DoCIDRsOverlap(&sn.IPNet, &mn.CIDR.IPNet) {
allErrs = append(allErrs, field.Invalid(fldPath, sn.String(), "service network must not overlap with any of the machine networks"))
}
}
for i, snn := range n.ServiceNetwork[0:idx] {
if validate.DoCIDRsOverlap(&sn.IPNet, &snn.IPNet) {
allErrs = append(allErrs, field.Invalid(fldPath, sn.String(), fmt.Sprintf("service network must not overlap with service network %d", i)))
}
}
return allErrs
}
func validateClusterNetwork(n *types.Networking, cn *types.ClusterNetworkEntry, idx int, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if err := validate.SubnetCIDR(&cn.CIDR.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("cidr"), cn.CIDR.IPNet.String(), err.Error()))
return allErrs // CIDR value is invalid, so no further validation.
}
if validate.DoCIDRsOverlap(&cn.CIDR.IPNet, validate.DockerBridgeSubnet) {
logrus.Warnf("%s: %s overlaps with default Docker Bridge subnet", fldPath.Index(idx), cn.CIDR.String())
}
allErrs = append(allErrs, validateNetworkNotOverlapDefaultOVNSubnets(n, &cn.CIDR.IPNet, fldPath.Child("cidr"))...)
for _, network := range n.MachineNetwork {
if validate.DoCIDRsOverlap(&cn.CIDR.IPNet, &network.CIDR.IPNet) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("cidr"), cn.CIDR.String(), "cluster network must not overlap with any of the machine networks"))
}
}
for i, sn := range n.ServiceNetwork {
if validate.DoCIDRsOverlap(&cn.CIDR.IPNet, &sn.IPNet) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("cidr"), cn.CIDR.String(), fmt.Sprintf("cluster network must not overlap with service network %d", i)))
}
}
for i, acn := range n.ClusterNetwork[0:idx] {
if validate.DoCIDRsOverlap(&cn.CIDR.IPNet, &acn.CIDR.IPNet) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("cidr"), cn.CIDR.String(), fmt.Sprintf("cluster network must not overlap with cluster network %d", i)))
}
}
// ignore hostPrefix if the plugin does not use it and has it unset
if pluginsUsingHostPrefix.Has(n.NetworkType) || (cn.HostPrefix != 0) {
if cn.HostPrefix < 0 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("hostPrefix"), cn.HostPrefix, "hostPrefix must be positive"))
} else if ones, bits := cn.CIDR.Mask.Size(); cn.HostPrefix < int32(ones) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("hostPrefix"), cn.HostPrefix, "cluster network host subnetwork prefix must not be larger size than CIDR "+cn.CIDR.String()))
} else if bits == 32 {
// setting different value for clusternetwork CIDR host prefix is not allowed
// we only need to check IPv4 as IPv6 prefix must be 64
for _, acn := range n.ClusterNetwork[0:idx] {
if acn.CIDR.IP.To4() != nil && cn.HostPrefix != acn.HostPrefix {
allErrs = append(allErrs, field.Invalid(fldPath.Child("hostPrefix"), cn.HostPrefix, "cluster network host subnetwork prefix must be the same value for IPv4 networks"))
break
}
}
} else if bits == 128 && cn.HostPrefix != 64 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("hostPrefix"), cn.HostPrefix, "cluster network host subnetwork prefix must be 64 for IPv6 networks"))
}
}
return allErrs
}
func validateNetworkNotOverlapDefaultOVNSubnets(n *types.Networking, network *net.IPNet, fldPath *field.Path) field.ErrorList {
if !strings.EqualFold(n.NetworkType, string(operv1.NetworkTypeOVNKubernetes)) {
return nil
}
allErrs := field.ErrorList{}
// getOVNSubnet returns the *net.IPNet for each type of subnet that will be used by OVNKubernetes
// and whether it is user-defined in the install-config.
getOVNSubnet := func(defaultSubnet *net.IPNet) (*net.IPNet, bool) {
if n.OVNKubernetesConfig == nil {
return defaultSubnet, false
}
ovnConfig := n.OVNKubernetesConfig
// Since each subnet has a unique non-overlapping CIDR,
// we can use that to distinguish the type of subnet without having to define extra constants.
switch defaultSubnet.String() {
case validate.OVNIPv4JoinSubnet.String():
if ovnConfig.IPv4 != nil && ovnConfig.IPv4.InternalJoinSubnet != nil {
return &ovnConfig.IPv4.InternalJoinSubnet.IPNet, true
}
default:
}
return defaultSubnet, false
}
// We only check against OVNKubernetes default subnets.
// Any overrides of default subnets is validated in func validateOVNKubernetesConfig.
subnetsCheck := func(joinSubnet, transitSubnet, masqueradeSubnet *net.IPNet) {
// Join subnet
if ovnsubnet, configured := getOVNSubnet(joinSubnet); !configured && validate.DoCIDRsOverlap(network, ovnsubnet) {
allErrs = append(allErrs, field.Invalid(fldPath, network.String(), fmt.Sprintf("must not overlap with OVNKubernetes default internal subnet %s", ovnsubnet.String())))
}
// Transit subnet
if ovnsubnet, configured := getOVNSubnet(transitSubnet); !configured && validate.DoCIDRsOverlap(network, ovnsubnet) {
allErrs = append(allErrs, field.Invalid(fldPath, network.String(), fmt.Sprintf("must not overlap with OVNKubernetes default transit subnet %s", ovnsubnet.String())))
}
// Masquerade subnet
if ovnsubnet, configured := getOVNSubnet(masqueradeSubnet); !configured && validate.DoCIDRsOverlap(network, ovnsubnet) {
allErrs = append(allErrs, field.Invalid(fldPath, network.String(), fmt.Sprintf("must not overlap with OVNKubernetes default masquerade subnet %s", ovnsubnet.String())))
}
}
if network.IP.To4() != nil {
subnetsCheck(validate.OVNIPv4JoinSubnet, validate.OVNIPv4TransitSubnet, validate.OVNIPv4MasqueradeSubnet)
} else {
subnetsCheck(validate.OVNIPv6JoinSubnet, validate.OVNIPv6TransitSubnet, validate.OVNIPv6MasqueradeSubnet)
}
return allErrs
}
func validateNetworkingClusterNetworkMTU(c *types.InstallConfig, fldPath *field.Path) field.ErrorList {
// higherLimitMTUVPC is the MTU limit for AWS VPC.
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/network_mtu.html#jumbo_frame_instances
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/network_mtu.html
const higherLimitMTUVPC uint32 = uint32(9001)
// lowerLimitMTUVPC is the lower limit to prevent users setting too low values impacting in the
// cluster network performance. Tested values with 1100 decreases 70% in the network performance
// in AWS deployments:
const lowerLimitMTUVPC uint32 = uint32(1000)
// higherLimitMTUEdge defines the maximium generally supported MTU in AWS Local and Wavelength Zones.
// Mostly AWS Local or Wavelength zones have limited MTU between those and in the Region.
// It is required to raise a warning message when the user-defined MTU is higher than general supported.
// https://docs.aws.amazon.com/local-zones/latest/ug/how-local-zones-work.html#considerations
// https://docs.aws.amazon.com/wavelength/latest/developerguide/how-wavelengths-work.html
const higherLimitMTUEdge uint32 = uint32(1300)
// MTU overhead for the network plugin OVNKubernetes.
// https://docs.openshift.com/container-platform/4.14/networking/changing-cluster-network-mtu.html#mtu-value-selection_changing-cluster-network-mtu
const minOverheadOVN uint32 = uint32(100)
allErrs := field.ErrorList{}
if c.Networking == nil {
return nil
}
if c.Networking.ClusterNetworkMTU == 0 {
return nil
}
if c.Platform.Name() != aws.Name {
return append(allErrs, field.Invalid(fldPath, int(c.Networking.ClusterNetworkMTU), "cluster network MTU is allowed only in AWS deployments"))
}
network := c.NetworkType
mtu := c.Networking.ClusterNetworkMTU
// Calculating the MTU limits considering the base overhead for each network plugin.
limitEdgeOVNKubernetes := higherLimitMTUEdge - minOverheadOVN
limitOVNKubernetes := higherLimitMTUVPC - minOverheadOVN
if mtu > higherLimitMTUVPC {
return append(allErrs, field.Invalid(fldPath, int(mtu), fmt.Sprintf("cluster network MTU exceeds the maximum value of %d", higherLimitMTUVPC)))
}
// Prevent too low MTU values.
// Tests in AWS Local Zones with MTU of 1100 decreased the network
// performance in 70%. The check protects the cluster stability from
// user defining too lower numbers.
// https://issues.redhat.com/browse/OCPBUGS-11098
if mtu < lowerLimitMTUVPC {
return append(allErrs, field.Invalid(fldPath, int(mtu), fmt.Sprintf("cluster network MTU is lower than the minimum value of %d", lowerLimitMTUVPC)))
}
hasEdgePool := false
warnEdgePool := false
for _, compute := range c.Compute {
if compute.Name == types.MachinePoolEdgeRoleName {
hasEdgePool = true
break
}
}
if network != string(operv1.NetworkTypeOVNKubernetes) {
return append(allErrs, field.Invalid(fldPath, int(mtu), fmt.Sprintf("cluster network MTU is not valid with network plugin %s", network)))
}
if mtu > limitOVNKubernetes {
return append(allErrs, field.Invalid(fldPath, int(mtu), fmt.Sprintf("cluster network MTU exceeds the maximum value with the network plugin %s of %d", network, limitOVNKubernetes)))
}
if hasEdgePool && (mtu > limitEdgeOVNKubernetes) {
warnEdgePool = true
}
if warnEdgePool {
logrus.Warnf("networking.ClusterNetworkMTU exceeds the maximum value generally supported by AWS Local or Wavelength zones. Please ensure all AWS Zones defined in the edge compute pool accepts the MTU %d bytes between nodes (EC2) in the zone and in the Region.", mtu)
}
return allErrs
}
func validateOVNKubernetesConfig(n *types.Networking, fldPath *field.Path) field.ErrorList {
if n.OVNKubernetesConfig == nil {
return nil
}
allErrs := field.ErrorList{}
if !strings.EqualFold(n.NetworkType, string(operv1.NetworkTypeOVNKubernetes)) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("networkType"), n.NetworkType, "ovnKubernetesConfig may only be specified with the OVNKubernetes networkType"))
}
allErrs = append(allErrs, validateOVNIPv4InternalJoinSubnet(n, fldPath.Child("ovnKubernetesConfig", "ipv4", "internalJoinSubnet"))...)
return allErrs
}
func validateOVNIPv4InternalJoinSubnet(n *types.Networking, fldPath *field.Path) field.ErrorList {
if ipv4 := n.OVNKubernetesConfig.IPv4; ipv4 == nil || ipv4.InternalJoinSubnet == nil {
return nil
}
allErrs := field.ErrorList{}
ipv4JoinNet := n.OVNKubernetesConfig.IPv4.InternalJoinSubnet
if err := validate.SubnetCIDR(&ipv4JoinNet.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath, ipv4JoinNet.IPNet.String(), err.Error()))
return allErrs // CIDR value is invalid, so we cannot perform further validation.
}
for _, net := range n.ClusterNetwork {
if validate.DoCIDRsOverlap(&ipv4JoinNet.IPNet, &net.CIDR.IPNet) {
errMsg := fmt.Sprintf("must not overlap with clusterNetwork %s", net.CIDR.String())
allErrs = append(allErrs, field.Invalid(fldPath, ipv4JoinNet.String(), errMsg))
}
}
for _, net := range n.MachineNetwork {
if validate.DoCIDRsOverlap(&ipv4JoinNet.IPNet, &net.CIDR.IPNet) {
errMsg := fmt.Sprintf("must not overlap with machineNetwork %s", net.CIDR.String())
allErrs = append(allErrs, field.Invalid(fldPath, ipv4JoinNet.String(), errMsg))
}
}
for _, net := range n.ServiceNetwork {
if validate.DoCIDRsOverlap(&ipv4JoinNet.IPNet, &net.IPNet) {
errMsg := fmt.Sprintf("must not overlap with serviceNetwork %s", net.String())
allErrs = append(allErrs, field.Invalid(fldPath, ipv4JoinNet.String(), errMsg))
}
}
if largeEnough, err := isV4NodeSubnetLargeEnough(n.ClusterNetwork, ipv4JoinNet); err == nil && !largeEnough {
errMsg := `ipv4InternalJoinSubnet is not large enough for the maximum number of nodes which can be supported by ClusterNetwork`
allErrs = append(allErrs, field.Invalid(fldPath, ipv4JoinNet.String(), errMsg))
} else if err != nil {
allErrs = append(allErrs, field.InternalError(fldPath, err))
}
return allErrs
}
func validateControlPlane(platform *types.Platform, pool *types.MachinePool, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if pool.Name != types.MachinePoolControlPlaneRoleName {
allErrs = append(allErrs, field.NotSupported(fldPath.Child("name"), pool.Name, []string{types.MachinePoolControlPlaneRoleName}))
}
if pool.Replicas != nil && *pool.Replicas == 0 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("replicas"), pool.Replicas, "number of control plane replicas must be positive"))
}
allErrs = append(allErrs, ValidateMachinePool(platform, pool, fldPath)...)
return allErrs
}
func validateComputeEdge(platform *types.Platform, pName string, fldPath *field.Path, pfld *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if platform.Name() != aws.Name {
allErrs = append(allErrs, field.NotSupported(pfld.Child("name"), pName, []string{types.MachinePoolComputeRoleName}))
}
return allErrs
}
func validateCompute(platform *types.Platform, control *types.MachinePool, pools []types.MachinePool, fldPath *field.Path, isMultiArchEnabled bool) field.ErrorList {
allErrs := field.ErrorList{}
poolNames := map[string]bool{}
for i, p := range pools {
poolFldPath := fldPath.Index(i)
switch p.Name {
case types.MachinePoolComputeRoleName:
case types.MachinePoolEdgeRoleName:
allErrs = append(allErrs, validateComputeEdge(platform, p.Name, poolFldPath, poolFldPath)...)
default:
allErrs = append(allErrs, field.NotSupported(poolFldPath.Child("name"), p.Name, []string{types.MachinePoolComputeRoleName, types.MachinePoolEdgeRoleName}))
}
if poolNames[p.Name] {
allErrs = append(allErrs, field.Duplicate(poolFldPath.Child("name"), p.Name))
}
poolNames[p.Name] = true
if control != nil && control.Architecture != p.Architecture && !isMultiArchEnabled {
allErrs = append(allErrs, field.Invalid(poolFldPath.Child("architecture"), p.Architecture, "heteregeneous multi-arch is not supported; compute pool architecture must match control plane"))
}
allErrs = append(allErrs, ValidateMachinePool(platform, &p, poolFldPath)...)
}
return allErrs
}
// vips defines the VIPs to validate
type vips struct {
API []string
Ingress []string
}
// vipFields defines the field names to which validation errors for each VIP
// type should be assigned to
type vipFields struct {
APIVIPs string
IngressVIPs string
}
// validateVIPsForPlatform validates the VIPs (for API and Ingress) for the
// given platform
func validateVIPsForPlatform(network *types.Networking, platform *types.Platform, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
virtualIPs := vips{}
newVIPsFields := vipFields{
APIVIPs: "apiVIPs",
IngressVIPs: "ingressVIPs",
}
var lbType configv1.PlatformLoadBalancerType
switch {
case platform.BareMetal != nil:
virtualIPs = vips{
API: platform.BareMetal.APIVIPs,
Ingress: platform.BareMetal.IngressVIPs,
}
if platform.BareMetal.LoadBalancer != nil {
lbType = platform.BareMetal.LoadBalancer.Type
}
allErrs = append(allErrs, validateAPIAndIngressVIPs(virtualIPs, newVIPsFields, true, true, lbType, network, fldPath.Child(baremetal.Name))...)
case platform.Nutanix != nil:
allErrs = append(allErrs, ensureIPv4IsFirstInDualStackSlice(&platform.Nutanix.APIVIPs, fldPath.Child(nutanix.Name, newVIPsFields.APIVIPs))...)
allErrs = append(allErrs, ensureIPv4IsFirstInDualStackSlice(&platform.Nutanix.IngressVIPs, fldPath.Child(nutanix.Name, newVIPsFields.IngressVIPs))...)
virtualIPs = vips{
API: platform.Nutanix.APIVIPs,
Ingress: platform.Nutanix.IngressVIPs,
}
if platform.Nutanix.LoadBalancer != nil {
lbType = platform.Nutanix.LoadBalancer.Type
}
allErrs = append(allErrs, validateAPIAndIngressVIPs(virtualIPs, newVIPsFields, false, false, lbType, network, fldPath.Child(nutanix.Name))...)
case platform.OpenStack != nil:
virtualIPs = vips{
API: platform.OpenStack.APIVIPs,
Ingress: platform.OpenStack.IngressVIPs,
}
if platform.OpenStack.LoadBalancer != nil {
lbType = platform.OpenStack.LoadBalancer.Type
}
allErrs = append(allErrs, validateAPIAndIngressVIPs(virtualIPs, newVIPsFields, true, true, lbType, network, fldPath.Child(openstack.Name))...)
case platform.VSphere != nil:
virtualIPs = vips{
API: platform.VSphere.APIVIPs,
Ingress: platform.VSphere.IngressVIPs,
}
if platform.VSphere.LoadBalancer != nil {
lbType = platform.VSphere.LoadBalancer.Type
}
allErrs = append(allErrs, validateAPIAndIngressVIPs(virtualIPs, newVIPsFields, false, false, lbType, network, fldPath.Child(vsphere.Name))...)
case platform.Ovirt != nil:
allErrs = append(allErrs, ensureIPv4IsFirstInDualStackSlice(&platform.Ovirt.APIVIPs, fldPath.Child(ovirt.Name, newVIPsFields.APIVIPs))...)
allErrs = append(allErrs, ensureIPv4IsFirstInDualStackSlice(&platform.Ovirt.IngressVIPs, fldPath.Child(ovirt.Name, newVIPsFields.IngressVIPs))...)
newVIPsFields = vipFields{
APIVIPs: "api_vips",
IngressVIPs: "ingress_vips",
}
virtualIPs = vips{
API: platform.Ovirt.APIVIPs,
Ingress: platform.Ovirt.IngressVIPs,
}
if platform.Ovirt.LoadBalancer != nil {
lbType = platform.Ovirt.LoadBalancer.Type
}
allErrs = append(allErrs, validateAPIAndIngressVIPs(virtualIPs, newVIPsFields, true, true, lbType, network, fldPath.Child(ovirt.Name))...)
default:
//no vips to validate on this platform
}
return allErrs
}
func ensureIPv4IsFirstInDualStackSlice(vips *[]string, fldPath *field.Path) field.ErrorList {
errList := field.ErrorList{}
isDualStack, err := utilsnet.IsDualStackIPStrings(*vips)
if err != nil {
errList = append(errList, field.Invalid(fldPath, vips, err.Error()))
return errList
}
if isDualStack {
if len(*vips) == 2 {
if utilsnet.IsIPv4String((*vips)[1]) && utilsnet.IsIPv6String((*vips)[0]) {
(*vips)[0], (*vips)[1] = (*vips)[1], (*vips)[0]
}
} else {
errList = append(errList, field.Invalid(fldPath, vips, "wrong number of VIPs given. Expecting 2 VIPs for dual stack"))
return errList
}
}
return errList
}
// validateAPIAndIngressVIPs validates the API and Ingress VIPs
//
//nolint:gocyclo
func validateAPIAndIngressVIPs(vips vips, fieldNames vipFields, vipIsRequired, reqVIPinMachineCIDR bool, lbType configv1.PlatformLoadBalancerType, n *types.Networking, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if len(vips.API) == 0 {
if vipIsRequired {
allErrs = append(allErrs, field.Required(fldPath.Child(fieldNames.APIVIPs), "must specify at least one VIP for the API"))
}
} else if len(vips.API) <= 2 {
for _, vip := range vips.API {
if err := validate.IP(vip); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldNames.APIVIPs), vip, err.Error()))
}
// When using user-managed loadbalancer we do not require API and Ingress VIP to be different as well as
// we allow them to be from outside the machine network CIDR.
if lbType != configv1.LoadBalancerTypeUserManaged {
for _, ingressVIP := range vips.Ingress {
apiVIPNet := net.ParseIP(vip)
ingressVIPNet := net.ParseIP(ingressVIP)
if apiVIPNet.Equal(ingressVIPNet) {
allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldNames.APIVIPs), vip, "VIP for API must not be one of the Ingress VIPs"))
}
}
if err := ValidateIPinMachineCIDR(vip, n); reqVIPinMachineCIDR && err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldNames.APIVIPs), vip, err.Error()))
}
}
}
if len(vips.Ingress) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child(fieldNames.IngressVIPs), "must specify VIP for ingress, when VIP for API is set"))
}
if len(vips.API) == 1 {
hasIPv4, hasIPv6, presence, _ := inferIPVersionFromInstallConfig(n)
apiVIPIPFamily := corev1.IPv4Protocol
if utilsnet.IsIPv6String(vips.API[0]) {
apiVIPIPFamily = corev1.IPv6Protocol
}
if hasIPv4 && hasIPv6 && apiVIPIPFamily != presence["machineNetwork"].Primary {
allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldNames.APIVIPs), vips.API[0], "VIP for the API must be of the same IP family with machine network's primary IP Family for dual-stack IPv4/IPv6"))
}
} else if len(vips.API) == 2 {
if isDualStack, _ := utilsnet.IsDualStackIPStrings(vips.API); !isDualStack {
allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldNames.APIVIPs), vips.API, "If two API VIPs are given, one must be an IPv4 address, the other an IPv6"))
}
}
} else {
allErrs = append(allErrs, field.TooMany(fldPath.Child(fieldNames.APIVIPs), len(vips.API), 2))
}
if len(vips.Ingress) == 0 {
if vipIsRequired {
allErrs = append(allErrs, field.Required(fldPath.Child(fieldNames.IngressVIPs), "must specify at least one VIP for the Ingress"))
}
} else if len(vips.Ingress) <= 2 {
for _, vip := range vips.Ingress {
if err := validate.IP(vip); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldNames.IngressVIPs), vip, err.Error()))
}
// When using user-managed loadbalancer we do not require API and Ingress VIP to be different as well as
// we allow them to be from outside the machine network CIDR.
if lbType != configv1.LoadBalancerTypeUserManaged {
if err := ValidateIPinMachineCIDR(vip, n); reqVIPinMachineCIDR && err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldNames.IngressVIPs), vip, err.Error()))
}
}
}
if len(vips.API) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child(fieldNames.APIVIPs), "must specify VIP for API, when VIP for ingress is set"))
}
if len(vips.Ingress) == 1 {
hasIPv4, hasIPv6, presence, _ := inferIPVersionFromInstallConfig(n)
ingressVIPIPFamily := corev1.IPv4Protocol
if utilsnet.IsIPv6String(vips.Ingress[0]) {
ingressVIPIPFamily = corev1.IPv6Protocol
}
if hasIPv4 && hasIPv6 && ingressVIPIPFamily != presence["machineNetwork"].Primary {
allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldNames.IngressVIPs), vips.Ingress[0], "VIP for the Ingress must be of the same IP family with machine network's primary IP Family for dual-stack IPv4/IPv6"))
}
} else if len(vips.Ingress) == 2 {
if isDualStack, _ := utilsnet.IsDualStackIPStrings(vips.Ingress); !isDualStack {