@@ -28,8 +28,8 @@ func ValidatePlatform(p *openstack.Platform, n *types.Networking, fldPath *field
2828 }
2929 }
3030
31- if c .OpenStack .ControlPlanePort != nil {
32- allErrs = append (allErrs , validateControlPlanePort (c , fldPath )... )
31+ if controlPlanePort := c .OpenStack .ControlPlanePort ; controlPlanePort != nil {
32+ allErrs = append (allErrs , validateControlPlanePort (controlPlanePort , fldPath . Child ( "controlPlanePort" ) )... )
3333 }
3434
3535 return allErrs
@@ -46,20 +46,31 @@ func validateLoadBalancer(lbType configv1.PlatformLoadBalancerType) bool {
4646}
4747
4848// validateControlPlanePort returns all the errors found when the control plane port is not valid.
49- func validateControlPlanePort (c * types.InstallConfig , fldPath * field.Path ) field.ErrorList {
50- controlPlanePort := c .OpenStack .ControlPlanePort
49+ func validateControlPlanePort (controlPlanePort * openstack.PortTarget , fldPath * field.Path ) field.ErrorList {
5150 var allErrs field.ErrorList
52- if len (controlPlanePort .FixedIPs ) <= 2 {
53- for _ , fixedIP := range controlPlanePort .FixedIPs {
51+
52+ if controlPlanePort .Network .ID != "" && ! validation .ValidUUIDv4 (controlPlanePort .Network .ID ) {
53+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("network" ), controlPlanePort .Network .ID , "invalid network ID: must be a UUIDv4" ))
54+ }
55+
56+ fixedIPsField := fldPath .Child ("fixedIPs" )
57+
58+ switch l := len (controlPlanePort .FixedIPs ); l {
59+ case 0 :
60+ allErrs = append (allErrs , field .Required (fixedIPsField , "it is required to set a subnet filter to the controlPlanePort" ))
61+ case 1 , 2 :
62+ for i , fixedIP := range controlPlanePort .FixedIPs {
63+ subnetField := fixedIPsField .Index (i ).Child ("subnet" )
5464 if fixedIP .Subnet .ID != "" && ! validation .ValidUUIDv4 (fixedIP .Subnet .ID ) {
55- allErrs = append (allErrs , field .Invalid (fldPath .Child ("controlPlanePort" ).Child ("fixedIPs" ), fixedIP .Subnet .ID , "invalid subnet ID" ))
65+ allErrs = append (allErrs , field .Invalid (subnetField .Child ("id" ), fixedIP .Subnet .ID , "invalid subnet ID: must be a UUIDv4" ))
66+ }
67+ if fixedIP .Subnet .ID == "" && fixedIP .Subnet .Name == "" {
68+ allErrs = append (allErrs , field .Required (subnetField , "either ID or Name must be set on the subnet filter" ))
5669 }
5770 }
58- if controlPlanePort .Network .ID != "" && ! validation .ValidUUIDv4 (controlPlanePort .Network .ID ) {
59- allErrs = append (allErrs , field .Invalid (fldPath .Child ("controlPlanePort" ).Child ("network" ), controlPlanePort .Network .ID , "invalid network ID" ))
60- }
61- } else {
62- allErrs = append (allErrs , field .TooMany (fldPath .Child ("fixedIPs" ), len (controlPlanePort .FixedIPs ), 2 ))
71+ default :
72+ allErrs = append (allErrs , field .TooMany (fixedIPsField , l , 2 ))
6373 }
74+
6475 return allErrs
6576}
0 commit comments