@@ -403,6 +403,25 @@ func ValidateIPNetFromString(subnetStr string, minAddrs int64, isDualStack bool,
403
403
return allErrs
404
404
}
405
405
406
+ // ValidateServiceSubnetSize validates that the maximum subnet size is not exceeded
407
+ // Should be a small cidr due to how it is stored in etcd.
408
+ // bigger cidr (specially those offered by IPv6) will add no value
409
+ // and significantly increase snapshotting time.
410
+ // NOTE: This is identical to validation performed in the apiserver.
411
+ func ValidateServiceSubnetSize (subnetStr string , fldPath * field.Path ) field.ErrorList {
412
+ allErrs := field.ErrorList {}
413
+ // subnets were already validated
414
+ subnets , _ := utilnet .ParseCIDRs (strings .Split (subnetStr , "," ))
415
+ for _ , serviceSubnet := range subnets {
416
+ ones , bits := serviceSubnet .Mask .Size ()
417
+ if bits - ones > constants .MaximumBitsForServiceSubnet {
418
+ errMsg := fmt .Sprintf ("specified service subnet is too large; for %d-bit addresses, the mask must be >= %d" , bits , bits - constants .MaximumBitsForServiceSubnet )
419
+ allErrs = append (allErrs , field .Invalid (fldPath , serviceSubnet .String (), errMsg ))
420
+ }
421
+ }
422
+ return allErrs
423
+ }
424
+
406
425
// ValidatePodSubnetNodeMask validates that the relation between podSubnet and node-masks is correct
407
426
func ValidatePodSubnetNodeMask (subnetStr string , c * kubeadm.ClusterConfiguration , fldPath * field.Path ) field.ErrorList {
408
427
allErrs := field.ErrorList {}
@@ -468,6 +487,8 @@ func ValidateNetworking(c *kubeadm.ClusterConfiguration, fldPath *field.Path) fi
468
487
469
488
if len (c .Networking .ServiceSubnet ) != 0 {
470
489
allErrs = append (allErrs , ValidateIPNetFromString (c .Networking .ServiceSubnet , constants .MinimumAddressesInServiceSubnet , isDualStack , field .NewPath ("serviceSubnet" ))... )
490
+ // Service subnet was already validated, we need to validate now the subnet size
491
+ allErrs = append (allErrs , ValidateServiceSubnetSize (c .Networking .ServiceSubnet , field .NewPath ("serviceSubnet" ))... )
471
492
}
472
493
if len (c .Networking .PodSubnet ) != 0 {
473
494
allErrs = append (allErrs , ValidateIPNetFromString (c .Networking .PodSubnet , constants .MinimumAddressesInPodSubnet , isDualStack , field .NewPath ("podSubnet" ))... )
0 commit comments