@@ -30,7 +30,7 @@ import (
3030 "k8s.io/apimachinery/pkg/runtime"
3131 "k8s.io/apimachinery/pkg/util/validation/field"
3232 "k8s.io/utils/ptr"
33- clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1 "
33+ clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2 "
3434 ctrl "sigs.k8s.io/controller-runtime"
3535 "sigs.k8s.io/controller-runtime/pkg/client"
3636 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -523,12 +523,12 @@ func validateManagedClusterNetwork(cli client.Client, labels map[string]string,
523523 ctx := context .Background ()
524524
525525 // Fetch the Cluster.
526- clusterName , ok := labels [clusterv1beta1 .ClusterNameLabel ]
526+ clusterName , ok := labels [clusterv1 .ClusterNameLabel ]
527527 if ! ok {
528528 return nil
529529 }
530530
531- ownerCluster := & clusterv1beta1 .Cluster {}
531+ ownerCluster := & clusterv1 .Cluster {}
532532 key := client.ObjectKey {
533533 Namespace : namespace ,
534534 Name : clusterName ,
@@ -539,24 +539,19 @@ func validateManagedClusterNetwork(cli client.Client, labels map[string]string,
539539 return allErrs
540540 }
541541
542- if clusterNetwork := ownerCluster .Spec .ClusterNetwork ; clusterNetwork != nil {
543- if clusterNetwork .Services != nil {
544- // A user may provide zero or one CIDR blocks. If they provide an empty array,
545- // we ignore it and use the default. AKS doesn't support > 1 Service/Pod CIDR.
546- if len (clusterNetwork .Services .CIDRBlocks ) > 1 {
547- allErrs = append (allErrs , field .TooMany (field .NewPath ("Cluster" , "spec" , "clusterNetwork" , "services" , "cidrBlocks" ), len (clusterNetwork .Services .CIDRBlocks ), 1 ))
548- }
549- if len (clusterNetwork .Services .CIDRBlocks ) == 1 {
550- serviceCIDR = clusterNetwork .Services .CIDRBlocks [0 ]
551- }
552- }
553- if clusterNetwork .Pods != nil {
554- // A user may provide zero or one CIDR blocks. If they provide an empty array,
555- // we ignore it and use the default. AKS doesn't support > 1 Service/Pod CIDR.
556- if len (clusterNetwork .Pods .CIDRBlocks ) > 1 {
557- allErrs = append (allErrs , field .TooMany (field .NewPath ("Cluster" , "spec" , "clusterNetwork" , "pods" , "cidrBlocks" ), len (clusterNetwork .Pods .CIDRBlocks ), 1 ))
558- }
559- }
542+ clusterNetwork := ownerCluster .Spec .ClusterNetwork
543+ // A user may provide zero or one CIDR blocks. If they provide an empty array,
544+ // we ignore it and use the default. AKS doesn't support > 1 Service/Pod CIDR.
545+ if len (clusterNetwork .Services .CIDRBlocks ) > 1 {
546+ allErrs = append (allErrs , field .TooMany (field .NewPath ("Cluster" , "spec" , "clusterNetwork" , "services" , "cidrBlocks" ), len (clusterNetwork .Services .CIDRBlocks ), 1 ))
547+ }
548+ if len (clusterNetwork .Services .CIDRBlocks ) == 1 {
549+ serviceCIDR = clusterNetwork .Services .CIDRBlocks [0 ]
550+ }
551+ // A user may provide zero or one CIDR blocks. If they provide an empty array,
552+ // we ignore it and use the default. AKS doesn't support > 1 Service/Pod CIDR.
553+ if len (clusterNetwork .Pods .CIDRBlocks ) > 1 {
554+ allErrs = append (allErrs , field .TooMany (field .NewPath ("Cluster" , "spec" , "clusterNetwork" , "pods" , "cidrBlocks" ), len (clusterNetwork .Pods .CIDRBlocks ), 1 ))
560555 }
561556
562557 if dnsServiceIP != nil {
0 commit comments