Skip to content

Commit b79f98f

Browse files
committed
Expose ‘—pod-network-cidr’ argument in minikube
1 parent 4e8a7f4 commit b79f98f

File tree

8 files changed

+145
-16
lines changed

8 files changed

+145
-16
lines changed

cmd/minikube/cmd/start.go

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const (
7676
apiServerPort = "apiserver-port"
7777
dnsDomain = "dns-domain"
7878
serviceCIDR = "service-cluster-ip-range"
79+
podSubnet = "pod-network-cidr"
7980
mountString = "mount-string"
8081
disableDriverMounts = "disable-driver-mounts"
8182
cacheImages = "cache-images"
@@ -124,6 +125,7 @@ func init() {
124125
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")
125126
startCmd.Flags().String(dnsDomain, constants.ClusterDNSDomain, "The cluster dns domain name used in the kubernetes cluster")
126127
startCmd.Flags().String(serviceCIDR, pkgutil.DefaultServiceCIDR, "The CIDR to be used for service cluster IPs.")
128+
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.")
127129
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.")
128130
startCmd.Flags().StringSliceVar(&registryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon")
129131
startCmd.Flags().String(containerRuntime, "docker", "The container runtime to be used (docker, crio, containerd)")
@@ -316,6 +318,7 @@ func generateConfig(cmd *cobra.Command, k8sVersion string) (cfg.Config, error) {
316318
CRISocket: viper.GetString(criSocket),
317319
NetworkPlugin: selectedNetworkPlugin,
318320
ServiceCIDR: viper.GetString(serviceCIDR),
321+
PodSubnet: viper.GetString(podSubnet),
319322
ExtraOptions: extraOptions,
320323
ShouldLoadCachedImages: viper.GetBool(cacheImages),
321324
EnableDefaultCNI: selectedEnableDefaultCNI,

pkg/minikube/bootstrapper/kubeadm/kubeadm.go

+2
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ func generateConfig(k8s config.KubernetesConfig, r cruntime.Manager) (string, er
511511
opts := struct {
512512
CertDir string
513513
ServiceCIDR string
514+
PodSubnet string
514515
AdvertiseAddress string
515516
APIServerPort int
516517
KubernetesVersion string
@@ -523,6 +524,7 @@ func generateConfig(k8s config.KubernetesConfig, r cruntime.Manager) (string, er
523524
}{
524525
CertDir: util.DefaultCertPath,
525526
ServiceCIDR: util.DefaultServiceCIDR,
527+
PodSubnet: k8s.PodSubnet,
526528
AdvertiseAddress: k8s.NodeIP,
527529
APIServerPort: nodePort,
528530
KubernetesVersion: k8s.KubernetesVersion,

pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go

+99-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ imageGCHighThresholdPercent: 100
169169
evictionHard:
170170
nodefs.available: "0%"
171171
nodefs.inodesFree: "0%"
172-
imagefs.available: "0%"
173-
`,
172+
imagefs.available: "0%"`,
174173
}, {
175174
description: "two extra args for one component",
176175
cfg: config.KubernetesConfig{
@@ -323,6 +322,104 @@ apiServerExtraArgs:
323322
admission-control: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota"
324323
`,
325324
},
325+
{
326+
description: "no PodSubnet",
327+
cfg: config.KubernetesConfig{
328+
NodeIP: "192.168.1.100",
329+
KubernetesVersion: "v1.12.0",
330+
NodeName: "minikube",
331+
PodSubnet: "",
332+
},
333+
expectedCfg: `apiVersion: kubeadm.k8s.io/v1alpha3
334+
kind: InitConfiguration
335+
apiEndpoint:
336+
advertiseAddress: 192.168.1.100
337+
bindPort: 8443
338+
bootstrapTokens:
339+
- groups:
340+
- system:bootstrappers:kubeadm:default-node-token
341+
ttl: 24h0m0s
342+
usages:
343+
- signing
344+
- authentication
345+
nodeRegistration:
346+
criSocket: /var/run/dockershim.sock
347+
name: minikube
348+
taints: []
349+
---
350+
apiVersion: kubeadm.k8s.io/v1alpha3
351+
kind: ClusterConfiguration
352+
apiServerExtraArgs:
353+
enable-admission-plugins: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota"
354+
355+
certificatesDir: /var/lib/minikube/certs/
356+
clusterName: kubernetes
357+
controlPlaneEndpoint: localhost:8443
358+
etcd:
359+
local:
360+
dataDir: /data/minikube
361+
kubernetesVersion: v1.12.0
362+
networking:
363+
dnsDomain: cluster.local
364+
podSubnet: ""
365+
serviceSubnet: 10.96.0.0/12
366+
---
367+
apiVersion: kubelet.config.k8s.io/v1beta1
368+
kind: KubeletConfiguration
369+
evictionHard:
370+
nodefs.available: "0%"
371+
nodefs.inodesFree: "0%"
372+
imagefs.available: "0%"`,
373+
},
374+
{
375+
description: "with PodSubnet",
376+
cfg: config.KubernetesConfig{
377+
NodeIP: "192.168.1.100",
378+
KubernetesVersion: "v1.12.0",
379+
NodeName: "minikube",
380+
PodSubnet: "192.168.32.0/20",
381+
},
382+
expectedCfg: `apiVersion: kubeadm.k8s.io/v1alpha3
383+
kind: InitConfiguration
384+
apiEndpoint:
385+
advertiseAddress: 192.168.1.100
386+
bindPort: 8443
387+
bootstrapTokens:
388+
- groups:
389+
- system:bootstrappers:kubeadm:default-node-token
390+
ttl: 24h0m0s
391+
usages:
392+
- signing
393+
- authentication
394+
nodeRegistration:
395+
criSocket: /var/run/dockershim.sock
396+
name: minikube
397+
taints: []
398+
---
399+
apiVersion: kubeadm.k8s.io/v1alpha3
400+
kind: ClusterConfiguration
401+
apiServerExtraArgs:
402+
enable-admission-plugins: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota"
403+
404+
certificatesDir: /var/lib/minikube/certs/
405+
clusterName: kubernetes
406+
controlPlaneEndpoint: localhost:8443
407+
etcd:
408+
local:
409+
dataDir: /data/minikube
410+
kubernetesVersion: v1.12.0
411+
networking:
412+
dnsDomain: cluster.local
413+
podSubnet: 192.168.32.0/20
414+
serviceSubnet: 10.96.0.0/12
415+
---
416+
apiVersion: kubelet.config.k8s.io/v1beta1
417+
kind: KubeletConfiguration
418+
evictionHard:
419+
nodefs.available: "0%"
420+
nodefs.inodesFree: "0%"
421+
imagefs.available: "0%"`,
422+
},
326423
}
327424

328425
for _, test := range tests {

pkg/minikube/bootstrapper/kubeadm/templates.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,15 @@ etcd:
8282
kubernetesVersion: {{.KubernetesVersion}}
8383
networking:
8484
dnsDomain: cluster.local
85-
podSubnet: ""
85+
podSubnet: {{if .PodSubnet}}{{.PodSubnet}}{{else}}""{{end}}
8686
serviceSubnet: {{.ServiceCIDR}}
8787
---
8888
apiVersion: kubelet.config.k8s.io/v1beta1
8989
kind: KubeletConfiguration
9090
evictionHard:
9191
nodefs.available: "0%"
9292
nodefs.inodesFree: "0%"
93-
imagefs.available: "0%"
94-
`))
93+
imagefs.available: "0%"`))
9594

9695
// configTmplV1Beta1 is for Kubernetes v1.13+
9796
var configTmplV1Beta1 = template.Must(template.New("configTmpl-v1beta1").Funcs(template.FuncMap{
@@ -141,8 +140,7 @@ imageGCHighThresholdPercent: 100
141140
evictionHard:
142141
nodefs.available: "0%"
143142
nodefs.inodesFree: "0%"
144-
imagefs.available: "0%"
145-
`))
143+
imagefs.available: "0%"`))
146144

147145
var kubeletSystemdTemplate = template.Must(template.New("kubeletSystemdTemplate").Parse(`
148146
[Unit]

pkg/minikube/config/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type KubernetesConfig struct {
7070
NetworkPlugin string
7171
FeatureGates string
7272
ServiceCIDR string
73+
PodSubnet string
7374
ExtraOptions util.ExtraOptionSlice
7475

7576
ShouldLoadCachedImages bool

pkg/minikube/constants/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ const (
202202
// DefaultMsize is the default number of bytes to use for 9p packet payload
203203
DefaultMsize = 262144
204204
// DefaultMountVersion is the default 9p version to use for mount
205-
DefaultMountVersion = "9p2000.L"
205+
DefaultMountVersion = "9p2000.L"
206206
)
207207

208208
// GetKubernetesReleaseURL gets the location of a kubernetes client

test/integration/start_stop_delete_test.go

+35-8
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,25 @@ limitations under the License.
1919
package integration
2020

2121
import (
22+
"encoding/json"
23+
"github.com/docker/machine/libmachine/state"
24+
"k8s.io/minikube/test/integration/util"
2225
"net"
2326
"strings"
2427
"testing"
2528
"time"
26-
27-
"github.com/docker/machine/libmachine/state"
28-
"k8s.io/minikube/test/integration/util"
2929
)
3030

3131
func TestStartStop(t *testing.T) {
3232
tests := []struct {
33-
name string
34-
args []string
33+
name string
34+
args []string
35+
assertCustom func(t *testing.T)
3536
}{
36-
{"docker+cache", []string{"--container-runtime=docker", "--cache-images"}},
37-
{"containerd+cache", []string{"--container-runtime=containerd", "--docker-opt containerd=/var/run/containerd/containerd.sock", "--cache-images"}},
38-
{"crio+cache", []string{"--container-runtime=crio", "--cache-images"}},
37+
{"docker+cache", []string{"--container-runtime=docker", "--cache-images"}, nil},
38+
{"containerd+cache", []string{"--container-runtime=containerd", "--docker-opt containerd=/var/run/containerd/containerd.sock", "--cache-images"}, nil},
39+
{"crio+cache", []string{"--container-runtime=crio", "--cache-images"}, nil},
40+
{"podCidr", []string{"--pod-network-cidr=192.168.111.111/16"}, assertPodCIDR},
3941
}
4042

4143
for _, test := range tests {
@@ -51,6 +53,10 @@ func TestStartStop(t *testing.T) {
5153
r.Start(test.args...)
5254
r.CheckStatus(state.Running.String())
5355

56+
if test.assertCustom != nil {
57+
test.assertCustom(t)
58+
}
59+
5460
ip := r.RunCommand("ip", true)
5561
ip = strings.TrimRight(ip, "\n")
5662
if net.ParseIP(ip) == nil {
@@ -74,3 +80,24 @@ func TestStartStop(t *testing.T) {
7480
})
7581
}
7682
}
83+
84+
func assertPodCIDR(t *testing.T) {
85+
kr := util.NewKubectlRunner(t)
86+
out, err := kr.RunCommand([]string{"get", "nodes", "-o", "json"})
87+
if err != nil {
88+
t.Fatalf("Failed to obtain nodes info")
89+
}
90+
91+
var result map[string]interface{}
92+
json.Unmarshal([]byte(out), &result)
93+
94+
items := result["items"].([]interface{})
95+
for _, item := range items {
96+
spec := item.(map[string]interface{})["spec"]
97+
podCidr := spec.(map[string]interface{})["podCIDR"].(string)
98+
99+
if !strings.HasPrefix(podCidr, "192.168.0.0") {
100+
t.Errorf("Unexpected podCIDR: %s", podCidr)
101+
}
102+
}
103+
}

test/integration/util/util.go

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func (m *MinikubeRunner) RunDaemon2(command string) (*exec.Cmd, *bufio.Reader, *
191191
}
192192
return cmd, bufio.NewReader(stdoutPipe), bufio.NewReader(stderrPipe)
193193
}
194+
194195
// SSH returns the output of running a command using SSH
195196
func (m *MinikubeRunner) SSH(command string) (string, error) {
196197
path, _ := filepath.Abs(m.BinaryPath)

0 commit comments

Comments
 (0)