From 9dd5fe826bafe4185fc88a4c1bd0f39423a7e081 Mon Sep 17 00:00:00 2001 From: Robert Pothier Date: Fri, 11 Aug 2017 11:08:59 -0400 Subject: [PATCH] kubeadm: Add node-cidr-mask-size to pass to kube-controller-manager for IPv6 Due to the increased size of subnets with IPv6, the node-cidr-mask-size needs to be passed to kube-controller-manager. If the user passes a IPv6 cidr, the node-cidr-mask-size will be set to 64, If IPv4 it will be set to 24 as it was previously. --- .../app/phases/controlplane/manifests.go | 10 ++++++- .../app/phases/controlplane/manifests_test.go | 27 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/cmd/kubeadm/app/phases/controlplane/manifests.go b/cmd/kubeadm/app/phases/controlplane/manifests.go index 1e4920fb2b4..c22b793c9ed 100644 --- a/cmd/kubeadm/app/phases/controlplane/manifests.go +++ b/cmd/kubeadm/app/phases/controlplane/manifests.go @@ -18,6 +18,7 @@ package controlplane import ( "fmt" + "net" "os" "path/filepath" "strings" @@ -221,7 +222,14 @@ func getControllerManagerCommand(cfg *kubeadmapi.MasterConfiguration, k8sVersion // Let the controller-manager allocate Node CIDRs for the Pod network. // Each node will get a subspace of the address CIDR provided with --pod-network-cidr. if cfg.Networking.PodSubnet != "" { - command = append(command, "--allocate-node-cidrs=true", "--cluster-cidr="+cfg.Networking.PodSubnet) + maskSize := "24" + if ip, _, err := net.ParseCIDR(cfg.Networking.PodSubnet); err == nil { + if ip.To4() == nil { + maskSize = "64" + } + } + command = append(command, "--allocate-node-cidrs=true", "--cluster-cidr="+cfg.Networking.PodSubnet, + "--node-cidr-mask-size="+maskSize) } return command } diff --git a/cmd/kubeadm/app/phases/controlplane/manifests_test.go b/cmd/kubeadm/app/phases/controlplane/manifests_test.go index 23dcc03bf80..d0cec1dc5cc 100644 --- a/cmd/kubeadm/app/phases/controlplane/manifests_test.go +++ b/cmd/kubeadm/app/phases/controlplane/manifests_test.go @@ -373,7 +373,7 @@ func TestGetControllerManagerCommand(t *testing.T) { }, { cfg: &kubeadmapi.MasterConfiguration{ - Networking: kubeadmapi.Networking{PodSubnet: "bar"}, + Networking: kubeadmapi.Networking{PodSubnet: "10.0.1.15/16"}, CertificatesDir: testCertsDir, KubernetesVersion: "v1.7.0", }, @@ -389,7 +389,30 @@ func TestGetControllerManagerCommand(t *testing.T) { "--use-service-account-credentials=true", "--controllers=*,bootstrapsigner,tokencleaner", "--allocate-node-cidrs=true", - "--cluster-cidr=bar", + "--cluster-cidr=10.0.1.15/16", + "--node-cidr-mask-size=24", + }, + }, + { + cfg: &kubeadmapi.MasterConfiguration{ + Networking: kubeadmapi.Networking{PodSubnet: "2001:101:115::/48"}, + CertificatesDir: testCertsDir, + KubernetesVersion: "v1.7.0", + }, + expected: []string{ + "kube-controller-manager", + "--address=127.0.0.1", + "--leader-elect=true", + "--kubeconfig=" + kubeadmconstants.KubernetesDir + "/controller-manager.conf", + "--root-ca-file=" + testCertsDir + "/ca.crt", + "--service-account-private-key-file=" + testCertsDir + "/sa.key", + "--cluster-signing-cert-file=" + testCertsDir + "/ca.crt", + "--cluster-signing-key-file=" + testCertsDir + "/ca.key", + "--use-service-account-credentials=true", + "--controllers=*,bootstrapsigner,tokencleaner", + "--allocate-node-cidrs=true", + "--cluster-cidr=2001:101:115::/48", + "--node-cidr-mask-size=64", }, }, }