From 6fe47f3677bf9c74adca216478fa97993041e27d Mon Sep 17 00:00:00 2001 From: Jan Janik <11janci@seznam.cz> Date: Mon, 18 Mar 2019 18:00:58 +1300 Subject: [PATCH] =?UTF-8?q?Expose=20=E2=80=98=E2=80=94pod-network-cidr?= =?UTF-8?q?=E2=80=99=20argument=20in=20minikube?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/minikube/cmd/start.go | 3 ++ pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 2 + .../bootstrapper/kubeadm/kubeadm_test.go | 1 + .../bootstrapper/kubeadm/templates.go | 2 +- .../containerd-pod-network-cidr__default.yaml | 43 +++++++++++++++++++ .../containerd-pod-network-cidr__new.yaml | 43 +++++++++++++++++++ ...containerd-pod-network-cidr__obsolete.yaml | 17 ++++++++ .../containerd-pod-network-cidr__old.yaml | 39 +++++++++++++++++ .../containerd-pod-network-cidr__recent.yaml | 39 +++++++++++++++++ pkg/minikube/config/types.go | 1 + test/integration/start_stop_delete_test.go | 38 ++++++++++++++-- 11 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__default.yaml create mode 100644 pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__new.yaml create mode 100644 pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__obsolete.yaml create mode 100644 pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__old.yaml create mode 100644 pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__recent.yaml diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index f500a1524bab..0bb77b2e4d1b 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -79,6 +79,7 @@ const ( apiServerPort = "apiserver-port" dnsDomain = "dns-domain" serviceCIDR = "service-cluster-ip-range" + podSubnet = "pod-network-cidr" imageRepository = "image-repository" imageMirrorCountry = "image-mirror-country" mountString = "mount-string" @@ -131,6 +132,7 @@ func init() { startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().String(dnsDomain, constants.ClusterDNSDomain, "The cluster dns domain name used in the kubernetes cluster") startCmd.Flags().String(serviceCIDR, pkgutil.DefaultServiceCIDR, "The CIDR to be used for service cluster IPs.") + startCmd.Flags().String(podSubnet, "", "Specify range of IP addresses for the pod network. If set, the control plane will automatically allocate CIDRs for every node.") startCmd.Flags().StringSliceVar(&insecureRegistry, "insecure-registry", nil, "Insecure Docker registries to pass to the Docker daemon. The default service CIDR range will automatically be added.") startCmd.Flags().StringSliceVar(®istryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon") startCmd.Flags().String(imageRepository, "", "Alternative image repository to pull docker images from. This can be used when you have limited access to gcr.io. Set it to \"auto\" to let minikube decide one for you. For Chinese mainland users, you may use local gcr.io mirrors such as registry.cn-hangzhou.aliyuncs.com/google_containers") @@ -457,6 +459,7 @@ func generateConfig(cmd *cobra.Command, k8sVersion string) (cfg.Config, error) { CRISocket: viper.GetString(criSocket), NetworkPlugin: selectedNetworkPlugin, ServiceCIDR: viper.GetString(serviceCIDR), + PodSubnet: viper.GetString(podSubnet), ImageRepository: repository, ExtraOptions: extraOptions, ShouldLoadCachedImages: viper.GetBool(cacheImages), diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 81d99dcfda6f..8889c4204f11 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -501,6 +501,7 @@ func generateConfig(k8s config.KubernetesConfig, r cruntime.Manager) (string, er opts := struct { CertDir string ServiceCIDR string + PodSubnet string AdvertiseAddress string APIServerPort int KubernetesVersion string @@ -514,6 +515,7 @@ func generateConfig(k8s config.KubernetesConfig, r cruntime.Manager) (string, er }{ CertDir: util.DefaultCertPath, ServiceCIDR: util.DefaultServiceCIDR, + PodSubnet: k8s.PodSubnet, AdvertiseAddress: k8s.NodeIP, APIServerPort: nodePort, KubernetesVersion: k8s.KubernetesVersion, diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go index 188351f1f89a..093f9fb0bed5 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go @@ -177,6 +177,7 @@ func TestGenerateConfig(t *testing.T) { {"crio-options-gates", "crio", false, config.KubernetesConfig{ExtraOptions: extraOpts, FeatureGates: "a=b"}}, {"unknown-component", "docker", true, config.KubernetesConfig{ExtraOptions: util.ExtraOptionSlice{util.ExtraOption{Component: "not-a-real-component", Key: "killswitch", Value: "true"}}}}, {"containerd-api-port", "containerd", false, config.KubernetesConfig{NodePort: 12345}}, + {"containerd-pod-network-cidr", "containerd", false, config.KubernetesConfig{PodSubnet: "192.168.32.0/20"}}, {"image-repository", "docker", false, config.KubernetesConfig{ImageRepository: "test/repo"}}, } for vname, version := range versions { diff --git a/pkg/minikube/bootstrapper/kubeadm/templates.go b/pkg/minikube/bootstrapper/kubeadm/templates.go index e5a63efc4456..e1b14bc1840f 100644 --- a/pkg/minikube/bootstrapper/kubeadm/templates.go +++ b/pkg/minikube/bootstrapper/kubeadm/templates.go @@ -85,7 +85,7 @@ etcd: kubernetesVersion: {{.KubernetesVersion}} networking: dnsDomain: cluster.local - podSubnet: "" + podSubnet: {{if .PodSubnet}}{{.PodSubnet}}{{else}}""{{end}} serviceSubnet: {{.ServiceCIDR}} --- apiVersion: kubelet.config.k8s.io/v1beta1 diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__default.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__default.yaml new file mode 100644 index 000000000000..147a6ccbec0d --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__default.yaml @@ -0,0 +1,43 @@ +apiVersion: kubeadm.k8s.io/v1beta1 +kind: InitConfiguration +localAPIEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /run/containerd/containerd.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1beta1 +kind: ClusterConfiguration +apiServer: + extraArgs: + enable-admission-plugins: "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs/ +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +dns: + type: CoreDNS +etcd: + local: + dataDir: /data/minikube +kubernetesVersion: v1.14.0 +networking: + dnsDomain: cluster.local + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +imageGCHighThresholdPercent: 100 +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__new.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__new.yaml new file mode 100644 index 000000000000..147a6ccbec0d --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__new.yaml @@ -0,0 +1,43 @@ +apiVersion: kubeadm.k8s.io/v1beta1 +kind: InitConfiguration +localAPIEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /run/containerd/containerd.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1beta1 +kind: ClusterConfiguration +apiServer: + extraArgs: + enable-admission-plugins: "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs/ +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +dns: + type: CoreDNS +etcd: + local: + dataDir: /data/minikube +kubernetesVersion: v1.14.0 +networking: + dnsDomain: cluster.local + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +imageGCHighThresholdPercent: 100 +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__obsolete.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__obsolete.yaml new file mode 100644 index 000000000000..b2d73f912bff --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__obsolete.yaml @@ -0,0 +1,17 @@ +apiVersion: kubeadm.k8s.io/v1alpha1 +kind: MasterConfiguration +noTaintMaster: true +api: + advertiseAddress: 1.1.1.1 + bindPort: 8443 + controlPlaneEndpoint: localhost +kubernetesVersion: v1.10.0 +certificatesDir: /var/lib/minikube/certs/ +networking: + serviceSubnet: 10.96.0.0/12 +etcd: + dataDir: /data/minikube +nodeName: mk +criSocket: /run/containerd/containerd.sock +apiServerExtraArgs: + admission-control: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__old.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__old.yaml new file mode 100644 index 000000000000..64bf678f0229 --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__old.yaml @@ -0,0 +1,39 @@ +apiVersion: kubeadm.k8s.io/v1alpha3 +kind: InitConfiguration +apiEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /run/containerd/containerd.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1alpha3 +kind: ClusterConfiguration +apiServerExtraArgs: + enable-admission-plugins: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs/ +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +etcd: + local: + dataDir: /data/minikube +kubernetesVersion: v1.12.0 +networking: + dnsDomain: cluster.local + podSubnet: 192.168.32.0/20 + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__recent.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__recent.yaml new file mode 100644 index 000000000000..ecc9a146311f --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/containerd-pod-network-cidr__recent.yaml @@ -0,0 +1,39 @@ +apiVersion: kubeadm.k8s.io/v1alpha3 +kind: InitConfiguration +apiEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /run/containerd/containerd.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1alpha3 +kind: ClusterConfiguration +apiServerExtraArgs: + enable-admission-plugins: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs/ +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +etcd: + local: + dataDir: /data/minikube +kubernetesVersion: v1.13.0 +networking: + dnsDomain: cluster.local + podSubnet: 192.168.32.0/20 + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/pkg/minikube/config/types.go b/pkg/minikube/config/types.go index 2537ebbd2fd8..4a82698ce408 100644 --- a/pkg/minikube/config/types.go +++ b/pkg/minikube/config/types.go @@ -71,6 +71,7 @@ type KubernetesConfig struct { NetworkPlugin string FeatureGates string ServiceCIDR string + PodSubnet string ImageRepository string ExtraOptions util.ExtraOptionSlice diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index 4a740a50c245..78e63c70d4dc 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -19,6 +19,7 @@ limitations under the License. package integration import ( + "encoding/json" "fmt" "net" "strings" @@ -32,13 +33,14 @@ import ( func TestStartStop(t *testing.T) { tests := []struct { - name string - args []string + name string + args []string + assertCustom func(t *testing.T) }{ {"nocache_oldest", []string{ "--cache-images=false", fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion), - }}, + }, nil}, {"feature_gates_newest_cni", []string{ "--feature-gates", "ServerSideApply=true", @@ -55,7 +57,10 @@ func TestStartStop(t *testing.T) { "--container-runtime=crio", "--extra-config", "kubeadm.ignore-preflight-errors=SystemVerification", - }}, + }, nil}, + {"podCidr", []string{ + "--pod-network-cidr=192.168.111.111/16", + }, assertPodCIDR}, } for _, test := range tests { @@ -71,6 +76,10 @@ func TestStartStop(t *testing.T) { r.Start(test.args...) r.CheckStatus(state.Running.String()) + if test.assertCustom != nil { + test.assertCustom(t) + } + ip := r.RunCommand("ip", true) ip = strings.TrimRight(ip, "\n") if net.ParseIP(ip) == nil { @@ -109,3 +118,24 @@ func TestStartStop(t *testing.T) { }) } } + +func assertPodCIDR(t *testing.T) { + kr := util.NewKubectlRunner(t) + out, err := kr.RunCommand([]string{"get", "nodes", "-o", "json"}) + if err != nil { + t.Fatalf("Failed to obtain nodes info") + } + + var result map[string]interface{} + json.Unmarshal([]byte(out), &result) + + items := result["items"].([]interface{}) + for _, item := range items { + spec := item.(map[string]interface{})["spec"] + podCidr := spec.(map[string]interface{})["podCIDR"].(string) + + if !strings.HasPrefix(podCidr, "192.168.0.0") { + t.Errorf("Unexpected podCIDR: %s", podCidr) + } + } +}