From 2a489bf7e133f034f365017f67bc1aa9d8e46b7f Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Thu, 14 Oct 2021 14:44:51 -0700 Subject: [PATCH 1/5] fix mounting on non-default profile & make mounting processes cluster independent --- cmd/minikube/cmd/delete.go | 3 +- pkg/minikube/node/config.go | 5 +- test/integration/mount_start_test.go | 86 ++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 test/integration/mount_start_test.go diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index 229fefcf71..e000712547 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -517,7 +517,8 @@ func deleteMachineDirectories(cc *config.ClusterConfig) { // killMountProcess kills the mount process, if it is running func killMountProcess() error { - pidPath := filepath.Join(localpath.MiniPath(), constants.MountProcessFileName) + profile := viper.GetString("profile") + pidPath := filepath.Join(localpath.Profile(profile), constants.MountProcessFileName) if _, err := os.Stat(pidPath); os.IsNotExist(err) { return nil } diff --git a/pkg/minikube/node/config.go b/pkg/minikube/node/config.go index 5d3d926e73..81ebe1011b 100644 --- a/pkg/minikube/node/config.go +++ b/pkg/minikube/node/config.go @@ -65,7 +65,8 @@ func configureMounts(wg *sync.WaitGroup) { if klog.V(8).Enabled() { mountDebugVal = 1 } - mountCmd := exec.Command(path, "mount", fmt.Sprintf("--v=%d", mountDebugVal), viper.GetString(mountString)) + profile := viper.GetString("profile") + mountCmd := exec.Command(path, "mount", "-p", profile, fmt.Sprintf("--v=%d", mountDebugVal), viper.GetString(mountString)) mountCmd.Env = append(os.Environ(), constants.IsMinikubeChildProcess+"=true") if klog.V(8).Enabled() { mountCmd.Stdout = os.Stdout @@ -74,7 +75,7 @@ func configureMounts(wg *sync.WaitGroup) { if err := mountCmd.Start(); err != nil { exit.Error(reason.GuestMount, "Error starting mount", err) } - if err := lock.WriteFile(filepath.Join(localpath.MiniPath(), constants.MountProcessFileName), []byte(strconv.Itoa(mountCmd.Process.Pid)), 0o644); err != nil { + if err := lock.WriteFile(filepath.Join(localpath.Profile(profile), constants.MountProcessFileName), []byte(strconv.Itoa(mountCmd.Process.Pid)), 0o644); err != nil { exit.Error(reason.HostMountPid, "Error writing mount pid", err) } } diff --git a/test/integration/mount_start_test.go b/test/integration/mount_start_test.go new file mode 100644 index 0000000000..1ea7d97deb --- /dev/null +++ b/test/integration/mount_start_test.go @@ -0,0 +1,86 @@ +//go:build integration +// +build integration + +/* +Copyright 2021 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integration + +import ( + "context" + "os/exec" + "testing" +) + +// TestMountStart tests using the mount command on start +func TestMountStart(t *testing.T) { + MaybeParallel(t) + + type validateFunc func(context.Context, *testing.T, string) + profile1 := UniqueProfileName("mount-start-1") + profile2 := UniqueProfileName("mount-start-2") + ctx, cancel := context.WithTimeout(context.Background(), Minutes(15)) + defer Cleanup(t, profile1, cancel) + defer Cleanup(t, profile2, cancel) + + // Serial tests + t.Run("serial", func(t *testing.T) { + tests := []struct { + name string + validator validateFunc + profile string + }{ + {"StartWithMountFirst", validateStartWithMount, profile1}, + {"StartWithMountSecond", validateStartWithMount, profile2}, + {"VerifyMountFirst", validateMount, profile1}, + {"VerifyMountSecond", validateMount, profile2}, + {"DeleteFirst", validateDelete, profile1}, + {"VerifyMountPostDelete", validateMount, profile2}, + } + + for _, test := range tests { + if ctx.Err() == context.DeadlineExceeded { + t.Fatalf("Unable to run more tests (deadline exceeded)") + } + + t.Run(test.name, func(t *testing.T) { + test.validator(ctx, t, test.profile) + }) + } + }) +} + +// validateStartWithMount starts a cluster with mount enabled +func validateStartWithMount(ctx context.Context, t *testing.T, profile string) { + defer PostMortemLogs(t, profile) + + args := []string{"start", "-p", profile, "--memory=2048", "--mount"} + 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) + } +} + +// validateMount checks if the cluster has a folder mounted +func validateMount(ctx context.Context, t *testing.T, profile string) { + defer PostMortemLogs(t, profile) + + args := []string{"-p", profile, "ssh", "ls", "/minikube-host"} + rr, err := Run(t, exec.CommandContext(ctx, Target(), args...)) + if err != nil { + t.Fatalf("mount failed: %q : %v", rr.Command(), err) + } +} From ad47329d17701b39265d34ab9252888ca263fa24 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Thu, 14 Oct 2021 14:49:20 -0700 Subject: [PATCH 2/5] updated docs --- site/content/en/docs/contrib/tests.en.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/site/content/en/docs/contrib/tests.en.md b/site/content/en/docs/contrib/tests.en.md index b33a96a8ec..fe73f90df1 100644 --- a/site/content/en/docs/contrib/tests.en.md +++ b/site/content/en/docs/contrib/tests.en.md @@ -243,6 +243,15 @@ verifies the docker driver and run with an existing network ## TestingKicBaseImage will return true if the integraiton test is running against a passed --base-image flag +## TestMountStart +tests using the mount command on start + +#### validateStartWithMount +starts a cluster with mount enabled + +#### validateMount +checks if the cluster has a folder mounted + ## TestMultiNode tests all multi node cluster functionality From 9a89855997d2d53864d9f1e836d4c669fa5e486f Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Thu, 14 Oct 2021 16:01:59 -0700 Subject: [PATCH 3/5] add backwards compatible mount-process delete --- cmd/minikube/cmd/delete.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index e000712547..67fcb756aa 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -518,7 +518,22 @@ func deleteMachineDirectories(cc *config.ClusterConfig) { // killMountProcess kills the mount process, if it is running func killMountProcess() error { profile := viper.GetString("profile") - pidPath := filepath.Join(localpath.Profile(profile), constants.MountProcessFileName) + paths := []string{ + localpath.MiniPath(), // legacy mount-process path for backwards compatibility + filepath.Join(localpath.Profile(profile)), + } + + for _, path := range paths { + if err := killProcess(path); err != nil { + return err + } + } + + return nil +} + +func killProcess(path string) error { + pidPath := filepath.Join(path, constants.MountProcessFileName) if _, err := os.Stat(pidPath); os.IsNotExist(err) { return nil } From 0623f34e99a88d4987d7789a494156f811f5d08e Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Thu, 14 Oct 2021 17:27:06 -0700 Subject: [PATCH 4/5] skip test on none driver --- test/integration/mount_start_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/integration/mount_start_test.go b/test/integration/mount_start_test.go index 1ea7d97deb..104c3095c1 100644 --- a/test/integration/mount_start_test.go +++ b/test/integration/mount_start_test.go @@ -27,6 +27,10 @@ import ( // TestMountStart tests using the mount command on start func TestMountStart(t *testing.T) { + if NoneDriver() { + t.Skip("skipping: none driver does not support mount") + } + MaybeParallel(t) type validateFunc func(context.Context, *testing.T, string) From 0fcf1eddec0cab3602e8f1134040ac3883f31ee1 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Fri, 15 Oct 2021 09:14:18 -0700 Subject: [PATCH 5/5] remove unnecessary join --- cmd/minikube/cmd/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index 67fcb756aa..74764207dd 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -520,7 +520,7 @@ func killMountProcess() error { profile := viper.GetString("profile") paths := []string{ localpath.MiniPath(), // legacy mount-process path for backwards compatibility - filepath.Join(localpath.Profile(profile)), + localpath.Profile(profile), } for _, path := range paths {