Skip to content

Commit

Permalink
Change MINIKUBE_HOME logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-sol committed Jul 4, 2024
1 parent ca9cc89 commit 6f03675
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/minikube/kubeconfig/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func TestUpdateIP(t *testing.T) {
},
}

t.Setenv(localpath.MinikubeHome, "/home/la-croix")
t.Setenv(localpath.MinikubeHome, "/home/la-croix/.minikube")

for _, test := range tests {
test := test
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestUpdateIP(t *testing.T) {
}

func TestMissingContext(t *testing.T) {
t.Setenv(localpath.MinikubeHome, "/home/la-croix")
t.Setenv(localpath.MinikubeHome, "/home/la-croix/.minikube")
configFilename := tempFile(t, kubeConfigMissingContext)
defer os.Remove(configFilename)
if _, err := UpdateEndpoint("minikube", "192.168.10.100", 8080, configFilename, nil); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/minikube/localpath/localpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func MiniPath() string {
if filepath.Base(minikubeHomeEnv) == ".minikube" {
return minikubeHomeEnv
}
return filepath.Join(minikubeHomeEnv, ".minikube")

legacyMinikubeHome := filepath.Join(minikubeHomeEnv, ".minikube")
if _, err := os.Stat(legacyMinikubeHome); !os.IsNotExist(err) {
return legacyMinikubeHome
}
return filepath.Clean(minikubeHomeEnv)
}

// MakeMiniPath is a utility to calculate a relative path to our directory.
Expand Down
13 changes: 6 additions & 7 deletions pkg/minikube/localpath/localpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,18 @@ func TestHasWindowsDriveLetter(t *testing.T) {

func TestMiniPath(t *testing.T) {
var testCases = []struct {
env, basePath string
env, expectedPath string
}{
{"/tmp/.minikube", "/tmp/"},
{"/tmp/", "/tmp"},
{"", homedir.HomeDir()},
{"/tmp/.minikube", "/tmp/.minikube"},
{"/tmp", "/tmp"},
{"", filepath.Join(homedir.HomeDir(), ".minikube")},
}
for _, tc := range testCases {
t.Run(tc.env, func(t *testing.T) {
expectedPath := filepath.Join(tc.basePath, ".minikube")
t.Setenv(MinikubeHome, tc.env)
path := MiniPath()
if path != expectedPath {
t.Errorf("MiniPath expected to return '%s', but got '%s'", expectedPath, path)
if path != tc.expectedPath {
t.Errorf("MiniPath expected to return '%s', but got '%s'", tc.expectedPath, path)
}
})
}
Expand Down

0 comments on commit 6f03675

Please sign in to comment.