@@ -3790,7 +3790,7 @@ func validatePodDNSConfig(dnsConfig *core.PodDNSConfig, dnsPolicy *core.DNSPolic
3790
3790
allErrs = append (allErrs , field .Invalid (fldPath .Child ("nameservers" ), dnsConfig .Nameservers , fmt .Sprintf ("must not have more than %v nameservers" , MaxDNSNameservers )))
3791
3791
}
3792
3792
for i , ns := range dnsConfig .Nameservers {
3793
- allErrs = append (allErrs , validation . IsValidIP (fldPath .Child ("nameservers" ).Index (i ), ns )... )
3793
+ allErrs = append (allErrs , IsValidIPForLegacyField (fldPath .Child ("nameservers" ).Index (i ), ns )... )
3794
3794
}
3795
3795
// Validate searches.
3796
3796
if len (dnsConfig .Searches ) > MaxDNSSearchPaths {
@@ -3966,7 +3966,7 @@ func validateOnlyDeletedSchedulingGates(newGates, oldGates []core.PodSchedulingG
3966
3966
func ValidateHostAliases (hostAliases []core.HostAlias , fldPath * field.Path ) field.ErrorList {
3967
3967
allErrs := field.ErrorList {}
3968
3968
for i , hostAlias := range hostAliases {
3969
- allErrs = append (allErrs , validation . IsValidIP (fldPath .Index (i ).Child ("ip" ), hostAlias .IP )... )
3969
+ allErrs = append (allErrs , IsValidIPForLegacyField (fldPath .Index (i ).Child ("ip" ), hostAlias .IP )... )
3970
3970
for j , hostname := range hostAlias .Hostnames {
3971
3971
allErrs = append (allErrs , ValidateDNS1123Subdomain (hostname , fldPath .Index (i ).Child ("hostnames" ).Index (j ))... )
3972
3972
}
@@ -4115,7 +4115,7 @@ func validatePodIPs(pod *core.Pod) field.ErrorList {
4115
4115
4116
4116
// all PodIPs must be valid IPs
4117
4117
for i , podIP := range pod .Status .PodIPs {
4118
- allErrs = append (allErrs , validation . IsValidIP (podIPsField .Index (i ), podIP .IP )... )
4118
+ allErrs = append (allErrs , IsValidIPForLegacyField (podIPsField .Index (i ), podIP .IP )... )
4119
4119
}
4120
4120
4121
4121
// if we have more than one Pod.PodIP then we must have a dual-stack pair
@@ -4156,7 +4156,7 @@ func validateHostIPs(pod *core.Pod) field.ErrorList {
4156
4156
4157
4157
// all HostIPs must be valid IPs
4158
4158
for i , hostIP := range pod .Status .HostIPs {
4159
- allErrs = append (allErrs , validation . IsValidIP (hostIPsField .Index (i ), hostIP .IP )... )
4159
+ allErrs = append (allErrs , IsValidIPForLegacyField (hostIPsField .Index (i ), hostIP .IP )... )
4160
4160
}
4161
4161
4162
4162
// if we have more than one Pod.HostIP then we must have a dual-stack pair
@@ -5940,7 +5940,7 @@ func ValidateService(service *core.Service) field.ErrorList {
5940
5940
ipPath := specPath .Child ("externalIPs" )
5941
5941
for i , ip := range service .Spec .ExternalIPs {
5942
5942
idxPath := ipPath .Index (i )
5943
- if errs := validation . IsValidIP (idxPath , ip ); len (errs ) != 0 {
5943
+ if errs := IsValidIPForLegacyField (idxPath , ip ); len (errs ) != 0 {
5944
5944
allErrs = append (allErrs , errs ... )
5945
5945
} else {
5946
5946
// For historical reasons, this uses ValidateEndpointIP even
@@ -6008,7 +6008,7 @@ func ValidateService(service *core.Service) field.ErrorList {
6008
6008
// Note: due to a historical accident around transition from the
6009
6009
// annotation value, these values are allowed to be space-padded.
6010
6010
value = strings .TrimSpace (value )
6011
- allErrs = append (allErrs , validation . IsValidCIDR (fieldPath .Index (idx ), value )... )
6011
+ allErrs = append (allErrs , IsValidCIDRForLegacyField (fieldPath .Index (idx ), value )... )
6012
6012
}
6013
6013
} else if val , annotationSet := service .Annotations [core .AnnotationLoadBalancerSourceRangesKey ]; annotationSet {
6014
6014
fieldPath := field .NewPath ("metadata" , "annotations" ).Key (core .AnnotationLoadBalancerSourceRangesKey )
@@ -6021,7 +6021,7 @@ func ValidateService(service *core.Service) field.ErrorList {
6021
6021
cidrs := strings .Split (val , "," )
6022
6022
for _ , value := range cidrs {
6023
6023
value = strings .TrimSpace (value )
6024
- allErrs = append (allErrs , validation . IsValidCIDR (fieldPath , value )... )
6024
+ allErrs = append (allErrs , IsValidCIDRForLegacyField (fieldPath , value )... )
6025
6025
}
6026
6026
}
6027
6027
}
@@ -6405,7 +6405,7 @@ func ValidateNode(node *core.Node) field.ErrorList {
6405
6405
6406
6406
// all PodCIDRs should be valid ones
6407
6407
for idx , value := range node .Spec .PodCIDRs {
6408
- allErrs = append (allErrs , validation . IsValidCIDR (podCIDRsField .Index (idx ), value )... )
6408
+ allErrs = append (allErrs , IsValidCIDRForLegacyField (podCIDRsField .Index (idx ), value )... )
6409
6409
}
6410
6410
6411
6411
// if more than PodCIDR then it must be a dual-stack pair
@@ -7481,7 +7481,7 @@ func validateEndpointSubsets(subsets []core.EndpointSubset, fldPath *field.Path)
7481
7481
7482
7482
func validateEndpointAddress (address * core.EndpointAddress , fldPath * field.Path ) field.ErrorList {
7483
7483
allErrs := field.ErrorList {}
7484
- allErrs = append (allErrs , validation . IsValidIP (fldPath .Child ("ip" ), address .IP )... )
7484
+ allErrs = append (allErrs , IsValidIPForLegacyField (fldPath .Child ("ip" ), address .IP )... )
7485
7485
if len (address .Hostname ) > 0 {
7486
7486
allErrs = append (allErrs , ValidateDNS1123Label (address .Hostname , fldPath .Child ("hostname" ))... )
7487
7487
}
@@ -7853,7 +7853,7 @@ func ValidateLoadBalancerStatus(status *core.LoadBalancerStatus, fldPath *field.
7853
7853
for i , ingress := range status .Ingress {
7854
7854
idxPath := ingrPath .Index (i )
7855
7855
if len (ingress .IP ) > 0 {
7856
- allErrs = append (allErrs , validation . IsValidIP (idxPath .Child ("ip" ), ingress .IP )... )
7856
+ allErrs = append (allErrs , IsValidIPForLegacyField (idxPath .Child ("ip" ), ingress .IP )... )
7857
7857
}
7858
7858
7859
7859
if utilfeature .DefaultFeatureGate .Enabled (features .LoadBalancerIPMode ) && ingress .IPMode == nil {
@@ -8188,7 +8188,7 @@ func ValidateServiceClusterIPsRelatedFields(service *core.Service) field.ErrorLi
8188
8188
}
8189
8189
8190
8190
// is it valid ip?
8191
- errorMessages := validation . IsValidIP (clusterIPsField .Index (i ), clusterIP )
8191
+ errorMessages := IsValidIPForLegacyField (clusterIPsField .Index (i ), clusterIP )
8192
8192
hasInvalidIPs = (len (errorMessages ) != 0 ) || hasInvalidIPs
8193
8193
allErrs = append (allErrs , errorMessages ... )
8194
8194
}
@@ -8703,3 +8703,17 @@ func isRestartableInitContainer(initContainer *core.Container) bool {
8703
8703
}
8704
8704
return * initContainer .RestartPolicy == core .ContainerRestartPolicyAlways
8705
8705
}
8706
+
8707
+ // IsValidIPForLegacyField is a wrapper around validation.IsValidIPForLegacyField that
8708
+ // handles setting strictValidation correctly. This is only for fields that use legacy IP
8709
+ // address validation; use validation.IsValidIP for new fields.
8710
+ func IsValidIPForLegacyField (fldPath * field.Path , value string ) field.ErrorList {
8711
+ return validation .IsValidIPForLegacyField (fldPath , value , utilfeature .DefaultFeatureGate .Enabled (features .StrictIPCIDRValidation ))
8712
+ }
8713
+
8714
+ // IsValidCIDRForLegacyField is a wrapper around validation.IsValidCIDRForLegacyField that
8715
+ // handles setting strictValidation correctly. This is only for fields that use legacy CIDR
8716
+ // value validation; use validation.IsValidCIDR for new fields.
8717
+ func IsValidCIDRForLegacyField (fldPath * field.Path , value string ) field.ErrorList {
8718
+ return validation .IsValidCIDRForLegacyField (fldPath , value , utilfeature .DefaultFeatureGate .Enabled (features .StrictIPCIDRValidation ))
8719
+ }
0 commit comments