From ff23ccf3184a4fc8564416c51f92501f2044a9f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Tue, 30 Mar 2021 20:09:44 +0200 Subject: [PATCH] Add constant for the ISO cache directory --- cmd/minikube/cmd/root.go | 1 - pkg/minikube/constants/constants.go | 5 ++++- pkg/minikube/download/iso.go | 7 +++++-- pkg/minikube/tests/dir_utils.go | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 5f63436e8b..680a2dfa5a 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -48,7 +48,6 @@ var dirs = [...]string{ localpath.MakeMiniPath("certs"), localpath.MakeMiniPath("machines"), localpath.MakeMiniPath("cache"), - localpath.MakeMiniPath("cache", "iso"), localpath.MakeMiniPath("config"), localpath.MakeMiniPath("addons"), localpath.MakeMiniPath("files"), diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 8690fe20d1..b180b05ddb 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -146,7 +146,10 @@ var ( // KubernetesReleaseBinaries are Kubernetes release binaries required for // kubeadm (kubelet, kubeadm) and the addon manager (kubectl) KubernetesReleaseBinaries = []string{"kubelet", "kubeadm", "kubectl"} - // ImageCacheDir is the path to the image cache directory + + // ISOCacheDir is the path to the virtual machine image cache directory + ISOCacheDir = localpath.MakeMiniPath("cache", "iso") + // ImageCacheDir is the path to the container image cache directory ImageCacheDir = localpath.MakeMiniPath("cache", "images") // DefaultNamespaces are Kubernetes namespaces used by minikube, including addons diff --git a/pkg/minikube/download/iso.go b/pkg/minikube/download/iso.go index d63c9fd2c2..b030600b60 100644 --- a/pkg/minikube/download/iso.go +++ b/pkg/minikube/download/iso.go @@ -28,7 +28,7 @@ import ( "github.com/juju/mutex" "github.com/pkg/errors" "k8s.io/klog/v2" - "k8s.io/minikube/pkg/minikube/localpath" + "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/style" "k8s.io/minikube/pkg/util/lock" @@ -75,7 +75,7 @@ func localISOPath(u *url.URL) string { return u.String() } - return filepath.Join(localpath.MiniPath(), "cache", "iso", path.Base(u.Path)) + return filepath.Join(constants.ISOCacheDir, path.Base(u.Path)) } // ISO downloads and returns the path to the downloaded ISO @@ -115,6 +115,9 @@ func downloadISO(isoURL string, skipChecksum bool) error { // Lock before we check for existence to avoid thundering herd issues dst := localISOPath(u) + if err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil { + return errors.Wrapf(err, "making cache image directory: %s", dst) + } spec := lock.PathMutexSpec(dst) spec.Timeout = 10 * time.Minute klog.Infof("acquiring lock: %+v", spec) diff --git a/pkg/minikube/tests/dir_utils.go b/pkg/minikube/tests/dir_utils.go index 7ba9b6f615..7cf9ba2f48 100644 --- a/pkg/minikube/tests/dir_utils.go +++ b/pkg/minikube/tests/dir_utils.go @@ -37,7 +37,7 @@ func MakeTempDir() string { if err != nil { log.Fatal(err) } - err = os.MkdirAll(filepath.Join(tempDir, "cache", "iso"), 0777) + err = os.MkdirAll(filepath.Join(tempDir, "cache"), 0777) if err != nil { log.Fatal(err) }