Skip to content

Commit 24b81ec

Browse files
committed
merge the --mount and --mount-string flags into --mount
1 parent b2c2ea4 commit 24b81ec

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

cmd/minikube/cmd/start.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,17 @@ func runStart(cmd *cobra.Command, _ []string) {
269269

270270
validateBuiltImageVersion(starter.Runner, ds.Name)
271271

272-
if viper.GetBool(createMount) {
272+
if cmd.Flags().Changed(createMount) || cmd.Flags().Changed(mountString) {
273273
warnAboutMountFlag()
274274
}
275275

276-
if existing != nil && driver.IsKIC(existing.Driver) && viper.GetString(mountString) != "" {
276+
if existing != nil && driver.IsKIC(existing.Driver) && cmd.Flags().Changed(createMount) {
277277
old := ""
278278
if len(existing.ContainerVolumeMounts) > 0 {
279279
old = existing.ContainerVolumeMounts[0]
280280
}
281-
if mount := viper.GetString(mountString); old != mount {
281+
_, mount := interpretMountFlag(cmd)
282+
if old != mount {
282283
exit.Message(reason.GuestMountConflict, "Sorry, {{.driver}} does not allow mounts to be changed after container creation (previous mount: '{{.old}}', new mount: '{{.new}})'", out.V{
283284
"driver": existing.Driver,
284285
"new": mount,

cmd/minikube/cmd/start_flags.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ func initMinikubeFlags() {
173173
startCmd.Flags().Bool(keepContext, false, "This will keep the existing kubectl context and will create a minikube context.")
174174
startCmd.Flags().Bool(embedCerts, false, "if true, will embed the certs in kubeconfig.")
175175
startCmd.Flags().StringP(containerRuntime, "c", constants.DefaultContainerRuntime, fmt.Sprintf("The container runtime to be used. Valid options: %s (default: auto)", strings.Join(cruntime.ValidRuntimes(), ", ")))
176-
startCmd.Flags().Bool(createMount, false, "Kept for backward compatibility, value is ignored.")
177-
startCmd.Flags().String(mountString, "", "Directory to mount in the guest using format '/host-path:/guest-path'.")
176+
startCmd.Flags().String(createMount, "", "Kept for backward compatibility, value is ignored.")
177+
startCmd.Flags().String(mountString, "", "DEPRECATED: specify mount path in old style")
178178
startCmd.Flags().String(mount9PVersion, defaultMount9PVersion, mount9PVersionDescription)
179179
startCmd.Flags().String(mountGID, defaultMountGID, mountGIDDescription)
180180
startCmd.Flags().String(mountIPFlag, defaultMountIP, mountIPDescription)
@@ -655,7 +655,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
655655
}
656656
cc.VerifyComponents = interpretWaitFlag(*cmd)
657657

658-
if viper.GetString(mountString) != "" && driver.IsKIC(drvName) {
658+
if cmd.Flags().Changed(createMount) && driver.IsKIC(drvName) {
659659
cc.ContainerVolumeMounts = []string{viper.GetString(mountString)}
660660
}
661661

@@ -922,6 +922,11 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
922922
cc.ScheduledStop = nil
923923
}
924924

925+
if cmd.Flags().Changed(createMount) || cmd.Flags().Changed(mountString) {
926+
cc.Mount, cc.MountString = interpretMountFlag(cmd)
927+
klog.Infof("Parsed mount flags => Mount: %v, MountString: %q", cc.Mount, cc.MountString)
928+
}
929+
925930
return cc
926931
}
927932

@@ -1012,6 +1017,39 @@ func interpretWaitFlag(cmd cobra.Command) map[string]bool {
10121017
return waitComponents
10131018
}
10141019

1020+
func interpretMountFlag(cmd *cobra.Command) (bool, string) {
1021+
mountBool := false
1022+
mountPath := ""
1023+
1024+
mountVal, _ := cmd.Flags().GetString(createMount)
1025+
mountStringFlag, _ := cmd.Flags().GetString(mountString)
1026+
1027+
if mountVal == "" && mountStringFlag == "" {
1028+
klog.Infof("No mount flag provided. Mount disabled by default.")
1029+
return false, ""
1030+
}
1031+
1032+
// parse mount flag
1033+
if mountVal == "true" {
1034+
mountBool = true
1035+
} else if mountVal == "false" || mountVal == "none" {
1036+
mountBool = false
1037+
} else if mountVal != "" {
1038+
// mount=/host:/guest
1039+
mountBool = true
1040+
mountPath = mountVal
1041+
}
1042+
1043+
// mount-string flag takes precedence over create-mount flag
1044+
if mountStringFlag != "" {
1045+
mountBool = true
1046+
mountPath = mountStringFlag
1047+
}
1048+
1049+
klog.Infof("Mount enabled: %v, Mount path: %q", mountBool, mountPath)
1050+
return mountBool, mountPath
1051+
}
1052+
10151053
func checkExtraDiskOptions(cmd *cobra.Command, driverName string) {
10161054
supportedDrivers := []string{driver.HyperKit, driver.KVM2, driver.QEMU2, driver.VFKit, driver.Krunkit}
10171055

pkg/minikube/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type ClusterConfig struct {
8888
MultiNodeRequested bool
8989
ExtraDisks int // currently only implemented for hyperkit and kvm2
9090
CertExpiration time.Duration
91+
Mount bool
9192
MountString string
9293
Mount9PVersion string
9394
MountGID string

0 commit comments

Comments
 (0)