Skip to content

Commit

Permalink
Merge pull request #12719 from spowelljr/retainMountAfterStop
Browse files Browse the repository at this point in the history
Persist mount settings after stop start
  • Loading branch information
spowelljr authored Oct 19, 2021
2 parents c1ee410 + ecebde8 commit c11ecd2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
4 changes: 4 additions & 0 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s
SSHPort: viper.GetInt(sshSSHPort),
ExtraDisks: viper.GetInt(extraDisks),
CertExpiration: viper.GetDuration(certExpiration),
Mount: viper.GetBool(createMount),
MountString: viper.GetString(mountString),
KubernetesConfig: config.KubernetesConfig{
KubernetesVersion: k8sVersion,
ClusterName: ClusterFlagValue(),
Expand Down Expand Up @@ -659,6 +661,8 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
updateBoolFromFlag(cmd, &cc.KubernetesConfig.ShouldLoadCachedImages, cacheImages)
updateIntFromFlag(cmd, &cc.KubernetesConfig.NodePort, apiServerPort)
updateDurationFromFlag(cmd, &cc.CertExpiration, certExpiration)
updateBoolFromFlag(cmd, &cc.Mount, createMount)
updateStringFromFlag(cmd, &cc.MountString, mountString)

if cmd.Flags().Changed(kubernetesVersion) {
cc.KubernetesConfig.KubernetesVersion = getKubernetesVersion(existing)
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type ClusterConfig struct {
MultiNodeRequested bool
ExtraDisks int // currently only implemented for hyperkit and kvm2
CertExpiration time.Duration
Mount bool
MountString string
}

// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
Expand Down
8 changes: 4 additions & 4 deletions pkg/minikube/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ func showVersionInfo(k8sVersion string, cr cruntime.Manager) {
}

// configureMounts configures any requested filesystem mounts
func configureMounts(wg *sync.WaitGroup) {
func configureMounts(wg *sync.WaitGroup, mount bool, mountString string) {
wg.Add(1)
defer wg.Done()

if !viper.GetBool(createMount) {
if !mount {
return
}

out.Step(style.Mounting, "Creating mount {{.name}} ...", out.V{"name": viper.GetString(mountString)})
out.Step(style.Mounting, "Creating mount {{.name}} ...", out.V{"name": mountString})
path := os.Args[0]
mountDebugVal := 0
if klog.V(8).Enabled() {
mountDebugVal = 1
}
profile := viper.GetString("profile")
mountCmd := exec.Command(path, "mount", "-p", profile, fmt.Sprintf("--v=%d", mountDebugVal), viper.GetString(mountString))
mountCmd := exec.Command(path, "mount", "-p", profile, fmt.Sprintf("--v=%d", mountDebugVal), mountString)
mountCmd.Env = append(os.Environ(), constants.IsMinikubeChildProcess+"=true")
if klog.V(8).Enabled() {
mountCmd.Stdout = os.Stdout
Expand Down
6 changes: 0 additions & 6 deletions pkg/minikube/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ import (
"k8s.io/minikube/pkg/minikube/machine"
)

// TODO: Share these between cluster and node packages
const (
mountString = "mount-string"
createMount = "mount"
)

// Add adds a new node config to an existing cluster.
func Add(cc *config.ClusterConfig, n config.Node, delOnFail bool) error {
profiles, err := config.ListValidProfiles()
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func Start(starter Starter, apiServer bool) (*kubeconfig.Settings, error) {

var wg sync.WaitGroup
if !driver.IsKIC(starter.Cfg.Driver) {
go configureMounts(&wg)
go configureMounts(&wg, starter.Cfg.Mount, starter.Cfg.MountString)
}

wg.Add(1)
Expand Down
6 changes: 6 additions & 0 deletions site/content/en/docs/contrib/tests.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ starts a cluster with mount enabled
#### validateMount
checks if the cluster has a folder mounted

#### validateMountStop
stops a cluster

#### validateRestart
restarts a cluster

## TestMultiNode
tests all multi node cluster functionality

Expand Down
28 changes: 26 additions & 2 deletions test/integration/mount_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ func TestMountStart(t *testing.T) {
t.Skip("skipping: none driver does not support mount")
}

MaybeParallel(t)

type validateFunc func(context.Context, *testing.T, string)
profile1 := UniqueProfileName("mount-start-1")
profile2 := UniqueProfileName("mount-start-2")
Expand All @@ -53,6 +51,9 @@ func TestMountStart(t *testing.T) {
{"VerifyMountSecond", validateMount, profile2},
{"DeleteFirst", validateDelete, profile1},
{"VerifyMountPostDelete", validateMount, profile2},
{"Stop", validateMountStop, profile2},
{"RestartStopped", validateRestart, profile2},
{"VerifyMountPostStop", validateMount, profile2},
}

for _, test := range tests {
Expand All @@ -72,6 +73,7 @@ func validateStartWithMount(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

args := []string{"start", "-p", profile, "--memory=2048", "--mount"}
args = append(args, StartArgs()...)
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Fatalf("failed to start minikube with args: %q : %v", rr.Command(), err)
Expand All @@ -88,3 +90,25 @@ func validateMount(ctx context.Context, t *testing.T, profile string) {
t.Fatalf("mount failed: %q : %v", rr.Command(), err)
}
}

// validateMountStop stops a cluster
func validateMountStop(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

args := []string{"stop", "-p", profile}
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Fatalf("stop failed: %q : %v", rr.Command(), err)
}
}

// validateRestart restarts a cluster
func validateRestart(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

args := []string{"start", "-p", profile}
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Fatalf("restart failed: %q : %v", rr.Command(), err)
}
}

0 comments on commit c11ecd2

Please sign in to comment.