Revert "Introduce APIs to support multiple ClusterCIDRs (#108290)"

This reverts commit b9792a9dae.
This commit is contained in:
James Laverack
2022-04-12 16:00:35 +01:00
parent 7380fc735a
commit 7d57d5c70d
98 changed files with 1 additions and 8740 deletions

View File

@@ -602,81 +602,3 @@ func allowInvalidWildcardHostRule(oldIngress *networking.Ingress) bool {
}
return false
}
// ValidateClusterCIDRConfigName validates that the given name can be used as an
// ClusterCIDRConfig name.
var ValidateClusterCIDRConfigName = apimachineryvalidation.NameIsDNSLabel
// ValidateClusterCIDRConfig validates a clusterCIDRConfig.
func ValidateClusterCIDRConfig(ccc *networking.ClusterCIDRConfig) field.ErrorList {
allErrs := apivalidation.ValidateObjectMeta(&ccc.ObjectMeta, false, ValidateClusterCIDRConfigName, field.NewPath("metadata"))
allErrs = append(allErrs, ValidateClusterCIDRConfigSpec(&ccc.Spec, field.NewPath("spec"))...)
return allErrs
}
// ValidateClusterCIDRConfigSpec validates clusterCIDRConfig Spec.
func ValidateClusterCIDRConfigSpec(spec *networking.ClusterCIDRConfigSpec, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if spec.NodeSelector != nil {
allErrs = append(allErrs, apivalidation.ValidateNodeSelector(spec.NodeSelector, fldPath.Child("nodeSelector"))...)
}
// Validate if CIDR is configured for at least one IP Family(IPv4/IPv6).
if spec.IPv4CIDR == "" && spec.IPv6CIDR == "" {
allErrs = append(allErrs, field.Required(fldPath, "one or both of `ipv4` and `ipv6` must be configured"))
}
// Validate configured IPv4 CIDR and PerNodeHostBits.
if spec.IPv4CIDR != "" {
if !netutils.IsIPv4CIDRString(spec.IPv4CIDR) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("ipv4CIDR"), spec.IPv4CIDR, "must be a valid IPv4 CIDR"))
return allErrs
}
allErrs = append(allErrs, validatePerNodeHostBits(spec.IPv4CIDR, spec.PerNodeHostBits, 32, fldPath)...)
}
// Validate configured IPv6 CIDR and PerNodeHostBits.
if spec.IPv6CIDR != "" {
if !netutils.IsIPv6CIDRString(spec.IPv6CIDR) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("ipv6CIDR"), spec.IPv6CIDR, "must be a valid IPv6 CIDR"))
return allErrs
}
allErrs = append(allErrs, validatePerNodeHostBits(spec.IPv6CIDR, spec.PerNodeHostBits, 128, fldPath)...)
}
return allErrs
}
func validatePerNodeHostBits(configCIDR string, perNodeHostBits, maxMaskSize int32, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
minPerNodeHostBits := int32(4)
_, cidr, _ := netutils.ParseCIDRSloppy(configCIDR)
maskSize, _ := cidr.Mask.Size()
maxPerNodeHostBits := maxMaskSize - int32(maskSize)
if perNodeHostBits < minPerNodeHostBits || perNodeHostBits > maxPerNodeHostBits {
allErrs = append(allErrs, field.Invalid(fldPath.Child("perNodeHostBits"), perNodeHostBits, fmt.Sprintf("must be greater than %d and less than or equal to %d", minPerNodeHostBits, maxPerNodeHostBits)))
}
return allErrs
}
// ValidateClusterCIDRConfigUpdate tests if an update to a ClusterCIDRConfig is valid.
func ValidateClusterCIDRConfigUpdate(update, old *networking.ClusterCIDRConfig) field.ErrorList {
allErrs := field.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta, field.NewPath("metadata"))...)
allErrs = append(allErrs, validateClusterCIDRConfigUpdateSpec(&update.Spec, &old.Spec, field.NewPath("spec"))...)
return allErrs
}
func validateClusterCIDRConfigUpdateSpec(update, old *networking.ClusterCIDRConfigSpec, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateImmutableField(update.NodeSelector, old.NodeSelector, fldPath.Child("nodeSelector"))...)
allErrs = append(allErrs, apivalidation.ValidateImmutableField(update.PerNodeHostBits, old.PerNodeHostBits, fldPath.Child("perNodeHostBits"))...)
allErrs = append(allErrs, apivalidation.ValidateImmutableField(update.IPv4CIDR, old.IPv4CIDR, fldPath.Child("ipv4CIDR"))...)
allErrs = append(allErrs, apivalidation.ValidateImmutableField(update.IPv6CIDR, old.IPv6CIDR, fldPath.Child("ipv6CIDR"))...)
return allErrs
}