diff --git a/pkg/minikube/download/binary.go b/pkg/minikube/download/binary.go index 6de9d9c42814..bc98f1057c3a 100644 --- a/pkg/minikube/download/binary.go +++ b/pkg/minikube/download/binary.go @@ -53,7 +53,10 @@ func binaryWithChecksumURL(binaryName, version, osName, archName, binaryURL stri // Binary will download a binary onto the host func Binary(binary, version, osName, archName, binaryURL string) (string, error) { - targetDir := localpath.MakeMiniPath("cache", osName, archName, version) + targetDir := localpath.MakeMiniPath("cache", "bin", osName, archName, version) + if err := os.MkdirAll(targetDir, 0755); err != nil { + return "", errors.Wrapf(err, "failed to create target dir %s", targetDir) + } targetFilepath := path.Join(targetDir, binary) targetLock := targetFilepath + ".lock" diff --git a/pkg/minikube/download/download_test.go b/pkg/minikube/download/download_test.go index beb44643fbd1..234a646d6c79 100644 --- a/pkg/minikube/download/download_test.go +++ b/pkg/minikube/download/download_test.go @@ -20,11 +20,13 @@ import ( "fmt" "io/fs" "os" + "path/filepath" "sync" "testing" "time" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/localpath" ) // Force download tests to run in serial. @@ -242,3 +244,24 @@ func testPreloadWithCachedSizeZero(t *testing.T) { t.Errorf("Expected only 1 download attempt but got %v!", downloadNum) } } + +func TestBinaryCreatesBinariesDir(t *testing.T) { + // mock download function that creates a fake binary file + DownloadMock = func(src, dst string) error { + // create a fake binary file at dst + return os.WriteFile(dst, []byte("fake-binary"), 0755) + } + + _, err := Binary("kubectl", "v1.31.0", "linux", "amd64", "") + if err != nil { + t.Fatalf("Binary() failed: %v", err) + } + + // check that the bin directory was created + targetDir := filepath.Join( + localpath.MiniPath(), "cache", "bin", "linux", "amd64", "v1.31.0", + ) + if _, err := os.Stat(targetDir); os.IsNotExist(err) { + t.Errorf("Expected bin dir %s to exist, but it does not", targetDir) + } +}