@@ -642,14 +642,21 @@ func validateVIPsForPlatform(network *types.Networking, platform *types.Platform
642642 APIVIPs : "apiVIPs" ,
643643 IngressVIPs : "ingressVIPs" ,
644644 }
645+
646+ var lbType configv1.PlatformLoadBalancerType
647+
645648 switch {
646649 case platform .BareMetal != nil :
647650 virtualIPs = vips {
648651 API : platform .BareMetal .APIVIPs ,
649652 Ingress : platform .BareMetal .IngressVIPs ,
650653 }
651654
652- allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , true , true , network , fldPath .Child (baremetal .Name ))... )
655+ if platform .BareMetal .LoadBalancer != nil {
656+ lbType = platform .BareMetal .LoadBalancer .Type
657+ }
658+
659+ allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , true , true , lbType , network , fldPath .Child (baremetal .Name ))... )
653660 case platform .Nutanix != nil :
654661 allErrs = append (allErrs , ensureIPv4IsFirstInDualStackSlice (& platform .Nutanix .APIVIPs , fldPath .Child (nutanix .Name , newVIPsFields .APIVIPs ))... )
655662 allErrs = append (allErrs , ensureIPv4IsFirstInDualStackSlice (& platform .Nutanix .IngressVIPs , fldPath .Child (nutanix .Name , newVIPsFields .IngressVIPs ))... )
@@ -659,21 +666,33 @@ func validateVIPsForPlatform(network *types.Networking, platform *types.Platform
659666 Ingress : platform .Nutanix .IngressVIPs ,
660667 }
661668
662- allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , false , false , network , fldPath .Child (nutanix .Name ))... )
669+ if platform .Nutanix .LoadBalancer != nil {
670+ lbType = platform .Nutanix .LoadBalancer .Type
671+ }
672+
673+ allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , false , false , lbType , network , fldPath .Child (nutanix .Name ))... )
663674 case platform .OpenStack != nil :
664675 virtualIPs = vips {
665676 API : platform .OpenStack .APIVIPs ,
666677 Ingress : platform .OpenStack .IngressVIPs ,
667678 }
668679
669- allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , true , true , network , fldPath .Child (openstack .Name ))... )
680+ if platform .OpenStack .LoadBalancer != nil {
681+ lbType = platform .OpenStack .LoadBalancer .Type
682+ }
683+
684+ allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , true , true , lbType , network , fldPath .Child (openstack .Name ))... )
670685 case platform .VSphere != nil :
671686 virtualIPs = vips {
672687 API : platform .VSphere .APIVIPs ,
673688 Ingress : platform .VSphere .IngressVIPs ,
674689 }
675690
676- allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , false , false , network , fldPath .Child (vsphere .Name ))... )
691+ if platform .VSphere .LoadBalancer != nil {
692+ lbType = platform .VSphere .LoadBalancer .Type
693+ }
694+
695+ allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , false , false , lbType , network , fldPath .Child (vsphere .Name ))... )
677696 case platform .Ovirt != nil :
678697 allErrs = append (allErrs , ensureIPv4IsFirstInDualStackSlice (& platform .Ovirt .APIVIPs , fldPath .Child (ovirt .Name , newVIPsFields .APIVIPs ))... )
679698 allErrs = append (allErrs , ensureIPv4IsFirstInDualStackSlice (& platform .Ovirt .IngressVIPs , fldPath .Child (ovirt .Name , newVIPsFields .IngressVIPs ))... )
@@ -687,7 +706,11 @@ func validateVIPsForPlatform(network *types.Networking, platform *types.Platform
687706 Ingress : platform .Ovirt .IngressVIPs ,
688707 }
689708
690- allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , true , true , network , fldPath .Child (ovirt .Name ))... )
709+ if platform .Ovirt .LoadBalancer != nil {
710+ lbType = platform .Ovirt .LoadBalancer .Type
711+ }
712+
713+ allErrs = append (allErrs , validateAPIAndIngressVIPs (virtualIPs , newVIPsFields , true , true , lbType , network , fldPath .Child (ovirt .Name ))... )
691714 default :
692715 //no vips to validate on this platform
693716 }
@@ -720,7 +743,7 @@ func ensureIPv4IsFirstInDualStackSlice(vips *[]string, fldPath *field.Path) fiel
720743// validateAPIAndIngressVIPs validates the API and Ingress VIPs
721744//
722745//nolint:gocyclo
723- func validateAPIAndIngressVIPs (vips vips , fieldNames vipFields , vipIsRequired , reqVIPinMachineCIDR bool , n * types.Networking , fldPath * field.Path ) field.ErrorList {
746+ func validateAPIAndIngressVIPs (vips vips , fieldNames vipFields , vipIsRequired , reqVIPinMachineCIDR bool , lbType configv1. PlatformLoadBalancerType , n * types.Networking , fldPath * field.Path ) field.ErrorList {
724747 allErrs := field.ErrorList {}
725748
726749 if len (vips .API ) == 0 {
@@ -733,17 +756,21 @@ func validateAPIAndIngressVIPs(vips vips, fieldNames vipFields, vipIsRequired, r
733756 allErrs = append (allErrs , field .Invalid (fldPath .Child (fieldNames .APIVIPs ), vip , err .Error ()))
734757 }
735758
736- for _ , ingressVIP := range vips .Ingress {
737- apiVIPNet := net .ParseIP (vip )
738- ingressVIPNet := net .ParseIP (ingressVIP )
759+ // When using user-managed loadbalancer we do not require API and Ingress VIP to be different as well as
760+ // we allow them to be from outside the machine network CIDR.
761+ if lbType != configv1 .LoadBalancerTypeUserManaged {
762+ for _ , ingressVIP := range vips .Ingress {
763+ apiVIPNet := net .ParseIP (vip )
764+ ingressVIPNet := net .ParseIP (ingressVIP )
739765
740- if apiVIPNet .Equal (ingressVIPNet ) {
741- allErrs = append (allErrs , field .Invalid (fldPath .Child (fieldNames .APIVIPs ), vip , "VIP for API must not be one of the Ingress VIPs" ))
766+ if apiVIPNet .Equal (ingressVIPNet ) {
767+ allErrs = append (allErrs , field .Invalid (fldPath .Child (fieldNames .APIVIPs ), vip , "VIP for API must not be one of the Ingress VIPs" ))
768+ }
742769 }
743- }
744770
745- if err := ValidateIPinMachineCIDR (vip , n ); reqVIPinMachineCIDR && err != nil {
746- allErrs = append (allErrs , field .Invalid (fldPath .Child (fieldNames .APIVIPs ), vip , err .Error ()))
771+ if err := ValidateIPinMachineCIDR (vip , n ); reqVIPinMachineCIDR && err != nil {
772+ allErrs = append (allErrs , field .Invalid (fldPath .Child (fieldNames .APIVIPs ), vip , err .Error ()))
773+ }
747774 }
748775
749776 if utilsnet .IsIPv6String (vip ) && n .NetworkType == string (operv1 .NetworkTypeOpenShiftSDN ) {
@@ -785,8 +812,12 @@ func validateAPIAndIngressVIPs(vips vips, fieldNames vipFields, vipIsRequired, r
785812 allErrs = append (allErrs , field .Invalid (fldPath .Child (fieldNames .IngressVIPs ), vip , err .Error ()))
786813 }
787814
788- if err := ValidateIPinMachineCIDR (vip , n ); reqVIPinMachineCIDR && err != nil {
789- allErrs = append (allErrs , field .Invalid (fldPath .Child (fieldNames .IngressVIPs ), vip , err .Error ()))
815+ // When using user-managed loadbalancer we do not require API and Ingress VIP to be different as well as
816+ // we allow them to be from outside the machine network CIDR.
817+ if lbType != configv1 .LoadBalancerTypeUserManaged {
818+ if err := ValidateIPinMachineCIDR (vip , n ); reqVIPinMachineCIDR && err != nil {
819+ allErrs = append (allErrs , field .Invalid (fldPath .Child (fieldNames .IngressVIPs ), vip , err .Error ()))
820+ }
790821 }
791822
792823 if utilsnet .IsIPv6String (vip ) && n .NetworkType == string (operv1 .NetworkTypeOpenShiftSDN ) {
0 commit comments