Skip to content

Commit

Permalink
kvm2 driver: add static ip
Browse files Browse the repository at this point in the history
  • Loading branch information
prezha committed Mar 25, 2021
1 parent f8a5272 commit 5bac07a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
19 changes: 3 additions & 16 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
out.WarningT("With --network-plugin=cni, you will need to provide your own CNI. See --cni flag as a user-friendly alternative")
}

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

checkNumaCount(k8sVersion)
Expand Down Expand Up @@ -342,7 +342,6 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
HypervUseExternalSwitch: viper.GetBool(hypervUseExternalSwitch),
HypervExternalAdapter: viper.GetString(hypervExternalAdapter),
KVMNetwork: viper.GetString(kvmNetwork),
KVMPrivateNetwork: viper.GetString(network),
KVMQemuURI: viper.GetString(kvmQemuURI),
KVMGPU: viper.GetBool(kvmGPU),
KVMHidden: viper.GetBool(kvmHidden),
Expand Down Expand Up @@ -381,10 +380,6 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
},
MultiNodeRequested: viper.GetInt(nodes) > 1,
}
// if KVMPrivateNetwork is not user-defined, defaults to "mk-<cluster_name>"
if cc.KVMPrivateNetwork == "" {
cc.KVMPrivateNetwork = fmt.Sprintf("mk-%s", cc.KubernetesConfig.ClusterName)
}
cc.VerifyComponents = interpretWaitFlag(*cmd)
if viper.GetBool(createMount) && driver.IsKIC(drvName) {
cc.ContainerVolumeMounts = []string{viper.GetString(mountString)}
Expand Down Expand Up @@ -559,15 +554,7 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
}

if cmd.Flags().Changed(kvmNetwork) {
if cc.KVMNetwork != viper.GetString(kvmNetwork) {
out.WarningT("You cannot change the KVM Default Network name for an exiting minikube cluster. Please first delete the cluster.")
}
}

if cmd.Flags().Changed(network) {
if cc.KVMPrivateNetwork != viper.GetString(network) {
out.WarningT("You cannot change the KVM Private Network name for an exiting minikube cluster. Please first delete the cluster.")
}
cc.KVMNetwork = viper.GetString(kvmNetwork)
}

if cmd.Flags().Changed(kvmQemuURI) {
Expand Down
1 change: 0 additions & 1 deletion pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type ClusterConfig struct {
HypervUseExternalSwitch bool
HypervExternalAdapter string
KVMNetwork string // Only used by the KVM2 driver
KVMPrivateNetwork string // Only used by the KVM2 driver
KVMQemuURI string // Only used by the KVM2 driver
KVMGPU bool // Only used by the KVM2 driver
KVMHidden bool // Only used by the KVM2 driver
Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func IsMock(name string) bool {
return name == Mock
}

// IsKVM checks if the driver is a KVM[2]
func IsKVM(name string) bool {
return name == KVM2 || name == AliasKVM
}

// IsVM checks if the driver is a VM
func IsVM(name string) bool {
if IsKIC(name) || BareMetal(name) {
Expand Down
10 changes: 9 additions & 1 deletion pkg/minikube/registry/drvs/kvm2/kvm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
Memory: cc.Memory,
CPU: cc.CPUs,
Network: cc.KVMNetwork,
PrivateNetwork: cc.KVMPrivateNetwork,
PrivateNetwork: privateNetwork(cc),
Boot2DockerURL: download.LocalISOResource(cc.MinikubeISO),
DiskSize: cc.DiskSize,
DiskPath: filepath.Join(localpath.MiniPath(), "machines", name, fmt.Sprintf("%s.rawdisk", name)),
Expand All @@ -95,6 +95,14 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
}, nil
}

// if network is not user-defined it defaults to "mk-<cluster_name>"
func privateNetwork(cc config.ClusterConfig) string {
if cc.Network == "" {
return fmt.Sprintf("mk-%s", cc.KubernetesConfig.ClusterName)
}
return cc.Network
}

// defaultURI returns the QEMU URI to connect to for health checks
func defaultURI() string {
u := os.Getenv("LIBVIRT_DEFAULT_URI")
Expand Down
4 changes: 2 additions & 2 deletions translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"- Ensure your {{.driver_name}} daemon has access to enough CPU/memory resources.": "",
"- Prune unused {{.driver_name}} images, volumes, networks and abandoned containers.\n\n\t\t\t\t{{.driver_name}} system prune --volumes": "",
"- Restart your {{.driver_name}} service": "{{.driver_name}} 서비스를 다시 시작하세요",
"--network flag is only valid with the docker/podman drivers, it will be ignored": "",
"--network flag is only valid with the docker/podman and KVM drivers, it will be ignored": "",
"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": "",
"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": "",
"A set of key=value pairs that describe feature gates for alpha/experimental features.": "",
Expand Down Expand Up @@ -687,7 +687,7 @@
"mount failed": "마운트 실패",
"namespaces to pause": "잠시 멈추려는 네임스페이스",
"namespaces to unpause": "재개하려는 네임스페이스",
"network to run minikube with. Only available with the docker/podman drivers. If left empty, minikube will create a new network.": "",
"network to run minikube with. Now it is used by docker/podman and KVM drivers. If left empty, minikube will create a new network.": "",
"none driver does not support multi-node clusters": "",
"not enough arguments ({{.ArgCount}}).\\nusage: minikube config set PROPERTY_NAME PROPERTY_VALUE": "",
"output layout (EXPERIMENTAL, JSON only): 'nodes' or 'cluster'": "",
Expand Down
4 changes: 2 additions & 2 deletions translations/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"- Ensure your {{.driver_name}} daemon has access to enough CPU/memory resources.": "",
"- Prune unused {{.driver_name}} images, volumes, networks and abandoned containers.\n\n\t\t\t\t{{.driver_name}} system prune --volumes": "",
"- Restart your {{.driver_name}} service": "",
"--network flag is only valid with the docker/podman drivers, it will be ignored": "",
"--network flag is only valid with the docker/podman and KVM drivers, it will be ignored": "",
"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": "",
"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": "",
"A set of key=value pairs that describe feature gates for alpha/experimental features.": "",
Expand Down Expand Up @@ -613,7 +613,7 @@
"mount failed": "",
"namespaces to pause": "",
"namespaces to unpause": "",
"network to run minikube with. Only available with the docker/podman drivers. If left empty, minikube will create a new network.": "",
"network to run minikube with. Now it is used by docker/podman and KVM drivers. If left empty, minikube will create a new network.": "",
"none driver does not support multi-node clusters": "",
"not enough arguments ({{.ArgCount}}).\\nusage: minikube config set PROPERTY_NAME PROPERTY_VALUE": "",
"output layout (EXPERIMENTAL, JSON only): 'nodes' or 'cluster'": "",
Expand Down

0 comments on commit 5bac07a

Please sign in to comment.