Skip to content

Commit 5bac07a

Browse files
committed
kvm2 driver: add static ip
1 parent f8a5272 commit 5bac07a

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

Diff for: cmd/minikube/cmd/start_flags.go

+3-16
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
311311
out.WarningT("With --network-plugin=cni, you will need to provide your own CNI. See --cni flag as a user-friendly alternative")
312312
}
313313

314-
if !driver.IsKIC(drvName) && viper.GetString(network) != "" {
315-
out.WarningT("--network flag is only valid with the docker/podman drivers, it will be ignored")
314+
if !(driver.IsKIC(drvName) || driver.IsKVM(drvName)) && viper.GetString(network) != "" {
315+
out.WarningT("--network flag is only valid with the docker/podman and KVM drivers, it will be ignored")
316316
}
317317

318318
checkNumaCount(k8sVersion)
@@ -342,7 +342,6 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
342342
HypervUseExternalSwitch: viper.GetBool(hypervUseExternalSwitch),
343343
HypervExternalAdapter: viper.GetString(hypervExternalAdapter),
344344
KVMNetwork: viper.GetString(kvmNetwork),
345-
KVMPrivateNetwork: viper.GetString(network),
346345
KVMQemuURI: viper.GetString(kvmQemuURI),
347346
KVMGPU: viper.GetBool(kvmGPU),
348347
KVMHidden: viper.GetBool(kvmHidden),
@@ -381,10 +380,6 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
381380
},
382381
MultiNodeRequested: viper.GetInt(nodes) > 1,
383382
}
384-
// if KVMPrivateNetwork is not user-defined, defaults to "mk-<cluster_name>"
385-
if cc.KVMPrivateNetwork == "" {
386-
cc.KVMPrivateNetwork = fmt.Sprintf("mk-%s", cc.KubernetesConfig.ClusterName)
387-
}
388383
cc.VerifyComponents = interpretWaitFlag(*cmd)
389384
if viper.GetBool(createMount) && driver.IsKIC(drvName) {
390385
cc.ContainerVolumeMounts = []string{viper.GetString(mountString)}
@@ -559,15 +554,7 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
559554
}
560555

561556
if cmd.Flags().Changed(kvmNetwork) {
562-
if cc.KVMNetwork != viper.GetString(kvmNetwork) {
563-
out.WarningT("You cannot change the KVM Default Network name for an exiting minikube cluster. Please first delete the cluster.")
564-
}
565-
}
566-
567-
if cmd.Flags().Changed(network) {
568-
if cc.KVMPrivateNetwork != viper.GetString(network) {
569-
out.WarningT("You cannot change the KVM Private Network name for an exiting minikube cluster. Please first delete the cluster.")
570-
}
557+
cc.KVMNetwork = viper.GetString(kvmNetwork)
571558
}
572559

573560
if cmd.Flags().Changed(kvmQemuURI) {

Diff for: pkg/minikube/config/types.go

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ type ClusterConfig struct {
5353
HypervUseExternalSwitch bool
5454
HypervExternalAdapter string
5555
KVMNetwork string // Only used by the KVM2 driver
56-
KVMPrivateNetwork string // Only used by the KVM2 driver
5756
KVMQemuURI string // Only used by the KVM2 driver
5857
KVMGPU bool // Only used by the KVM2 driver
5958
KVMHidden bool // Only used by the KVM2 driver

Diff for: pkg/minikube/driver/driver.go

+5
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ func IsMock(name string) bool {
141141
return name == Mock
142142
}
143143

144+
// IsKVM checks if the driver is a KVM[2]
145+
func IsKVM(name string) bool {
146+
return name == KVM2 || name == AliasKVM
147+
}
148+
144149
// IsVM checks if the driver is a VM
145150
func IsVM(name string) bool {
146151
if IsKIC(name) || BareMetal(name) {

Diff for: pkg/minikube/registry/drvs/kvm2/kvm2.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
8383
Memory: cc.Memory,
8484
CPU: cc.CPUs,
8585
Network: cc.KVMNetwork,
86-
PrivateNetwork: cc.KVMPrivateNetwork,
86+
PrivateNetwork: privateNetwork(cc),
8787
Boot2DockerURL: download.LocalISOResource(cc.MinikubeISO),
8888
DiskSize: cc.DiskSize,
8989
DiskPath: filepath.Join(localpath.MiniPath(), "machines", name, fmt.Sprintf("%s.rawdisk", name)),
@@ -95,6 +95,14 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
9595
}, nil
9696
}
9797

98+
// if network is not user-defined it defaults to "mk-<cluster_name>"
99+
func privateNetwork(cc config.ClusterConfig) string {
100+
if cc.Network == "" {
101+
return fmt.Sprintf("mk-%s", cc.KubernetesConfig.ClusterName)
102+
}
103+
return cc.Network
104+
}
105+
98106
// defaultURI returns the QEMU URI to connect to for health checks
99107
func defaultURI() string {
100108
u := os.Getenv("LIBVIRT_DEFAULT_URI")

Diff for: translations/ko.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"- Ensure your {{.driver_name}} daemon has access to enough CPU/memory resources.": "",
2121
"- Prune unused {{.driver_name}} images, volumes, networks and abandoned containers.\n\n\t\t\t\t{{.driver_name}} system prune --volumes": "",
2222
"- Restart your {{.driver_name}} service": "{{.driver_name}} 서비스를 다시 시작하세요",
23-
"--network flag is only valid with the docker/podman drivers, it will be ignored": "",
23+
"--network flag is only valid with the docker/podman and KVM drivers, it will be ignored": "",
2424
"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": "",
2525
"A set of apiserver names 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": "",
2626
"A set of key=value pairs that describe feature gates for alpha/experimental features.": "",
@@ -687,7 +687,7 @@
687687
"mount failed": "마운트 실패",
688688
"namespaces to pause": "잠시 멈추려는 네임스페이스",
689689
"namespaces to unpause": "재개하려는 네임스페이스",
690-
"network to run minikube with. Only available with the docker/podman drivers. If left empty, minikube will create a new network.": "",
690+
"network to run minikube with. Now it is used by docker/podman and KVM drivers. If left empty, minikube will create a new network.": "",
691691
"none driver does not support multi-node clusters": "",
692692
"not enough arguments ({{.ArgCount}}).\\nusage: minikube config set PROPERTY_NAME PROPERTY_VALUE": "",
693693
"output layout (EXPERIMENTAL, JSON only): 'nodes' or 'cluster'": "",

Diff for: translations/strings.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"- Ensure your {{.driver_name}} daemon has access to enough CPU/memory resources.": "",
1515
"- Prune unused {{.driver_name}} images, volumes, networks and abandoned containers.\n\n\t\t\t\t{{.driver_name}} system prune --volumes": "",
1616
"- Restart your {{.driver_name}} service": "",
17-
"--network flag is only valid with the docker/podman drivers, it will be ignored": "",
17+
"--network flag is only valid with the docker/podman and KVM drivers, it will be ignored": "",
1818
"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": "",
1919
"A set of apiserver names 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": "",
2020
"A set of key=value pairs that describe feature gates for alpha/experimental features.": "",
@@ -613,7 +613,7 @@
613613
"mount failed": "",
614614
"namespaces to pause": "",
615615
"namespaces to unpause": "",
616-
"network to run minikube with. Only available with the docker/podman drivers. If left empty, minikube will create a new network.": "",
616+
"network to run minikube with. Now it is used by docker/podman and KVM drivers. If left empty, minikube will create a new network.": "",
617617
"none driver does not support multi-node clusters": "",
618618
"not enough arguments ({{.ArgCount}}).\\nusage: minikube config set PROPERTY_NAME PROPERTY_VALUE": "",
619619
"output layout (EXPERIMENTAL, JSON only): 'nodes' or 'cluster'": "",

0 commit comments

Comments
 (0)