diff --git a/cmd/kube-controller-manager/app/core.go b/cmd/kube-controller-manager/app/core.go index e6f639adfa5..240259ed43d 100644 --- a/cmd/kube-controller-manager/app/core.go +++ b/cmd/kube-controller-manager/app/core.go @@ -159,8 +159,12 @@ func startNodeIpamController(ctx ControllerContext) (http.Handler, bool, error) var nodeCIDRMaskSizeIPv4, nodeCIDRMaskSizeIPv6 int if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.IPv6DualStack) { + // only --node-cidr-mask-size-ipv4 and --node-cidr-mask-size-ipv6 supported with dual stack clusters. + // --node-cidr-mask-size flag is incompatible with dual stack clusters. nodeCIDRMaskSizeIPv4, nodeCIDRMaskSizeIPv6, err = setNodeCIDRMaskSizesDualStack(ctx.ComponentConfig.NodeIPAMController) } else { + // only --node-cidr-mask-size supported with single stack clusters. + // --node-cidr-mask-size-ipv4 and --node-cidr-mask-size-ipv6 flags are incompatible with dual stack clusters. nodeCIDRMaskSizeIPv4, nodeCIDRMaskSizeIPv6, err = setNodeCIDRMaskSizes(ctx.ComponentConfig.NodeIPAMController) } @@ -623,12 +627,13 @@ func setNodeCIDRMaskSizesDualStack(cfg nodeipamconfig.NodeIPAMControllerConfigur // getNodeCIDRMaskSizes is a helper function that helps the generate the node cidr mask // sizes slice based on the cluster cidr slice func getNodeCIDRMaskSizes(clusterCIDRs []*net.IPNet, maskSizeIPv4, maskSizeIPv6 int) []int { - nodeMaskCIDRs := []int{} - for _, clusterCIDR := range clusterCIDRs { + nodeMaskCIDRs := make([]int, len(clusterCIDRs)) + + for idx, clusterCIDR := range clusterCIDRs { if netutils.IsIPv6CIDR(clusterCIDR) { - nodeMaskCIDRs = append(nodeMaskCIDRs, maskSizeIPv6) + nodeMaskCIDRs[idx] = maskSizeIPv6 } else { - nodeMaskCIDRs = append(nodeMaskCIDRs, maskSizeIPv4) + nodeMaskCIDRs[idx] = maskSizeIPv4 } } return nodeMaskCIDRs diff --git a/pkg/controller/nodeipam/config/types.go b/pkg/controller/nodeipam/config/types.go index 84431b4e3c2..8c923e198b9 100644 --- a/pkg/controller/nodeipam/config/types.go +++ b/pkg/controller/nodeipam/config/types.go @@ -23,9 +23,12 @@ type NodeIPAMControllerConfiguration struct { // secondaryServiceCIDR is CIDR Range for Services in cluster. This is used in dual stack clusters. SecondaryServiceCIDR must be of different IP family than ServiceCIDR SecondaryServiceCIDR string // NodeCIDRMaskSize is the mask size for node cidr in single-stack cluster. + // This can be used only with single stack clusters and is incompatible with dual stack clusters. NodeCIDRMaskSize int32 - // NodeCIDRMaskSizeIPv4 is the mask size for node cidr in dual-stack cluster. + // NodeCIDRMaskSizeIPv4 is the mask size for IPv4 node cidr in dual-stack cluster. + // This can be used only with dual stack clusters and is incompatible with single stack clusters. NodeCIDRMaskSizeIPv4 int32 - // NodeCIDRMaskSizeIPv6 is the mask size for node cidr in dual-stack cluster. + // NodeCIDRMaskSizeIPv6 is the mask size for IPv6 node cidr in dual-stack cluster. + // This can be used only with dual stack clusters and is incompatible with single stack clusters. NodeCIDRMaskSizeIPv6 int32 }