From fc6efd908317d81b64c1d33629ba0043101b4377 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Tue, 1 Feb 2022 12:57:41 -0800 Subject: [PATCH 1/4] add arch to binary cache path --- pkg/minikube/download/binary.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/download/binary.go b/pkg/minikube/download/binary.go index 62516027dd2d..95f13816f1ea 100644 --- a/pkg/minikube/download/binary.go +++ b/pkg/minikube/download/binary.go @@ -55,7 +55,7 @@ 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, version) + targetDir := localpath.MakeMiniPath("cache", osName, archName, version) targetFilepath := path.Join(targetDir, binary) targetLock := targetFilepath + ".lock" From 9d76d0cab202fdae684b224136e101961ae1c19f Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Tue, 1 Feb 2022 14:56:28 -0800 Subject: [PATCH 2/4] add arch to image and kicbase cache path --- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 3 ++- pkg/minikube/constants/constants.go | 4 ---- pkg/minikube/detect/detect.go | 11 +++++++++++ pkg/minikube/download/image.go | 6 +++--- pkg/minikube/image/cache.go | 4 ++-- pkg/minikube/image/image.go | 6 +++--- pkg/minikube/machine/cache_images.go | 10 +++++----- pkg/minikube/node/cache.go | 2 +- 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index c7f57b9ea572..ddf1fe0237cf 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -52,6 +52,7 @@ import ( "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/cruntime" + "k8s.io/minikube/pkg/minikube/detect" "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/kubeconfig" "k8s.io/minikube/pkg/minikube/machine" @@ -753,7 +754,7 @@ func (k *Bootstrapper) UpdateCluster(cfg config.ClusterConfig) error { } if cfg.KubernetesConfig.ShouldLoadCachedImages { - if err := machine.LoadCachedImages(&cfg, k.c, images, constants.ImageCacheDir, false); err != nil { + if err := machine.LoadCachedImages(&cfg, k.c, images, detect.ImageCacheDir(), false); err != nil { out.FailureT("Unable to load cached images: {{.error}}", out.V{"error": err}) } } diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 1300e2aa9bcd..00652ba750f0 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -184,10 +184,6 @@ var ( // ISOCacheDir is the path to the virtual machine image cache directory ISOCacheDir = localpath.MakeMiniPath("cache", "iso") - // KICCacheDir is the path to the container node image cache directory - KICCacheDir = localpath.MakeMiniPath("cache", "kic") - // ImageCacheDir is the path to the container image cache directory - ImageCacheDir = localpath.MakeMiniPath("cache", "images") // DefaultNamespaces are Kubernetes namespaces used by minikube, including addons DefaultNamespaces = []string{ diff --git a/pkg/minikube/detect/detect.go b/pkg/minikube/detect/detect.go index ebb9dd41b1c4..59b178c1d4ce 100644 --- a/pkg/minikube/detect/detect.go +++ b/pkg/minikube/detect/detect.go @@ -26,6 +26,7 @@ import ( "github.com/klauspost/cpuid" "golang.org/x/sys/cpu" + "k8s.io/minikube/pkg/minikube/localpath" ) // RuntimeOS returns the runtime operating system @@ -113,3 +114,13 @@ func GithubActionRunner() bool { // based on https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables return os.Getenv("GITHUB_ACTIONS") == "true" } + +// ImageCacheDir returns the path to the container image cache directory for the current architecture +func ImageCacheDir() string { + return filepath.Join(localpath.MakeMiniPath("cache", "images"), runtime.GOARCH) +} + +// KICCacheDir returns the path to the container node image cache directory for the current architecture +func KICCacheDir() string { + return filepath.Join(localpath.MakeMiniPath("cache", "kic"), runtime.GOARCH) +} diff --git a/pkg/minikube/download/image.go b/pkg/minikube/download/image.go index ee17a020a6ab..b3d63297cee4 100644 --- a/pkg/minikube/download/image.go +++ b/pkg/minikube/download/image.go @@ -33,7 +33,7 @@ import ( "github.com/google/go-containerregistry/pkg/v1/tarball" "github.com/pkg/errors" "k8s.io/klog/v2" - "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/detect" "k8s.io/minikube/pkg/minikube/localpath" ) @@ -46,7 +46,7 @@ var ( // imagePathInCache returns path in local cache directory func imagePathInCache(img string) string { - f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar") + f := filepath.Join(detect.KICCacheDir(), path.Base(img)+".tar") f = localpath.SanitizeCacheDir(f) return f } @@ -222,7 +222,7 @@ func CacheToDaemon(img string) error { // ImageToDaemon downloads img (if not present in daemon) and writes it to the local docker daemon func ImageToDaemon(img string) error { - fileLock := filepath.Join(constants.KICCacheDir, path.Base(img)+".d.lock") + fileLock := filepath.Join(detect.KICCacheDir(), path.Base(img)+".d.lock") fileLock = localpath.SanitizeCacheDir(fileLock) releaser, err := lockDownload(fileLock) diff --git a/pkg/minikube/image/cache.go b/pkg/minikube/image/cache.go index a6085c056546..bf9d72d8eb98 100644 --- a/pkg/minikube/image/cache.go +++ b/pkg/minikube/image/cache.go @@ -28,7 +28,7 @@ import ( "github.com/pkg/errors" "golang.org/x/sync/errgroup" "k8s.io/klog/v2" - "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/detect" "k8s.io/minikube/pkg/minikube/localpath" "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/util/lock" @@ -48,7 +48,7 @@ var errCacheImageDoesntExist = &cacheError{errors.New("the image you are trying // DeleteFromCacheDir deletes tar files stored in cache dir func DeleteFromCacheDir(images []string) error { for _, image := range images { - path := filepath.Join(constants.ImageCacheDir, image) + path := filepath.Join(detect.ImageCacheDir(), image) path = localpath.SanitizeCacheDir(path) klog.Infoln("Deleting image in cache at ", path) if err := os.Remove(path); err != nil { diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index 5603a8022fbd..c671b57e87d9 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -36,7 +36,7 @@ import ( "github.com/pkg/errors" "k8s.io/klog/v2" - "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/detect" "k8s.io/minikube/pkg/minikube/localpath" ) @@ -198,7 +198,7 @@ func retrieveRemote(ref name.Reference, p v1.Platform) (v1.Image, error) { // imagePathInCache returns path in local cache directory func imagePathInCache(img string) string { - f := filepath.Join(constants.ImageCacheDir, img) + f := filepath.Join(detect.ImageCacheDir(), img) f = localpath.SanitizeCacheDir(f) return f } @@ -278,7 +278,7 @@ func fixPlatform(ref name.Reference, img v1.Image, p v1.Platform) (v1.Image, err } func cleanImageCacheDir() error { - err := filepath.Walk(constants.ImageCacheDir, func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(localpath.MakeMiniPath("cache", "images"), func(path string, info os.FileInfo, err error) error { // If error is not nil, it's because the path was already deleted and doesn't exist // Move on to next path if err != nil { diff --git a/pkg/minikube/machine/cache_images.go b/pkg/minikube/machine/cache_images.go index 923e78a8f35c..3a70c1458851 100644 --- a/pkg/minikube/machine/cache_images.go +++ b/pkg/minikube/machine/cache_images.go @@ -41,8 +41,8 @@ import ( "k8s.io/minikube/pkg/minikube/bootstrapper" "k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/cruntime" + "k8s.io/minikube/pkg/minikube/detect" "k8s.io/minikube/pkg/minikube/image" "k8s.io/minikube/pkg/minikube/localpath" "k8s.io/minikube/pkg/minikube/out" @@ -65,7 +65,7 @@ func CacheImagesForBootstrapper(imageRepository string, version string, clusterB return errors.Wrap(err, "cached images list") } - if err := image.SaveToDir(images, constants.ImageCacheDir, false); err != nil { + if err := image.SaveToDir(images, detect.ImageCacheDir(), false); err != nil { return errors.Wrapf(err, "Caching images for %s", clusterBootstrapper) } @@ -192,11 +192,11 @@ func CacheAndLoadImages(images []string, profiles []*config.Profile, overwrite b } // This is the most important thing - if err := image.SaveToDir(images, constants.ImageCacheDir, overwrite); err != nil { + if err := image.SaveToDir(images, detect.ImageCacheDir(), overwrite); err != nil { return errors.Wrap(err, "save to dir") } - return DoLoadImages(images, profiles, constants.ImageCacheDir, overwrite) + return DoLoadImages(images, profiles, detect.ImageCacheDir(), overwrite) } // DoLoadImages loads images to all profiles @@ -382,7 +382,7 @@ func SaveAndCacheImages(images []string, profiles []*config.Profile) error { return nil } - return DoSaveImages(images, "", profiles, constants.ImageCacheDir) + return DoSaveImages(images, "", profiles, detect.ImageCacheDir()) } // DoSaveImages saves images from all profiles diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index 10b3cd2b4e0b..a965bf2cd46f 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -228,7 +228,7 @@ func saveImagesToTarFromConfig() error { if len(images) == 0 { return nil } - return image.SaveToDir(images, constants.ImageCacheDir, false) + return image.SaveToDir(images, detect.ImageCacheDir(), false) } // CacheAndLoadImagesInConfig loads the images currently in the config file From 5635ca72123d28e44585f3e0543b66ffe6c6f6b7 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Wed, 2 Feb 2022 16:12:20 -0800 Subject: [PATCH 3/4] Update pkg/minikube/detect/detect.go Co-authored-by: Medya Ghazizadeh --- pkg/minikube/detect/detect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/detect/detect.go b/pkg/minikube/detect/detect.go index 59b178c1d4ce..ad29310ca922 100644 --- a/pkg/minikube/detect/detect.go +++ b/pkg/minikube/detect/detect.go @@ -115,7 +115,7 @@ func GithubActionRunner() bool { return os.Getenv("GITHUB_ACTIONS") == "true" } -// ImageCacheDir returns the path to the container image cache directory for the current architecture +// ImageCacheDir returns the path to the container image cache directory in minikube home folder for the current architecture func ImageCacheDir() string { return filepath.Join(localpath.MakeMiniPath("cache", "images"), runtime.GOARCH) } From f74ea169b24b9ed58f22383a1e0ed6660783e703 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Thu, 3 Feb 2022 10:29:13 -0800 Subject: [PATCH 4/4] add arch to iso cache path, fix download only tests --- pkg/minikube/constants/constants.go | 4 ---- pkg/minikube/detect/detect.go | 9 +++++++-- pkg/minikube/download/iso.go | 4 ++-- test/integration/aaa_download_only_test.go | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index e77336e5c44a..03b4ad8f7a8a 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -23,7 +23,6 @@ import ( "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/util/homedir" - "k8s.io/minikube/pkg/minikube/localpath" ) var ( @@ -181,9 +180,6 @@ var ( // kubeadm (kubelet, kubeadm) and the addon manager (kubectl) KubernetesReleaseBinaries = []string{"kubelet", "kubeadm", "kubectl"} - // ISOCacheDir is the path to the virtual machine image cache directory - ISOCacheDir = localpath.MakeMiniPath("cache", "iso") - // DefaultNamespaces are Kubernetes namespaces used by minikube, including addons DefaultNamespaces = []string{ "kube-system", diff --git a/pkg/minikube/detect/detect.go b/pkg/minikube/detect/detect.go index ad29310ca922..c5910efc593b 100644 --- a/pkg/minikube/detect/detect.go +++ b/pkg/minikube/detect/detect.go @@ -115,12 +115,17 @@ func GithubActionRunner() bool { return os.Getenv("GITHUB_ACTIONS") == "true" } -// ImageCacheDir returns the path to the container image cache directory in minikube home folder for the current architecture +// ImageCacheDir returns the path in the minikube home directory to the container image cache for the current architecture func ImageCacheDir() string { return filepath.Join(localpath.MakeMiniPath("cache", "images"), runtime.GOARCH) } -// KICCacheDir returns the path to the container node image cache directory for the current architecture +// KICCacheDir returns the path in the minikube home directory to the container node cache for the current architecture func KICCacheDir() string { return filepath.Join(localpath.MakeMiniPath("cache", "kic"), runtime.GOARCH) } + +// ISOCacheDir returns the path in the minikube home directory to the virtual machine image cache for the current architecture +func ISOCacheDir() string { + return filepath.Join(localpath.MakeMiniPath("cache", "iso"), runtime.GOARCH) +} diff --git a/pkg/minikube/download/iso.go b/pkg/minikube/download/iso.go index 08f4042ba102..994b9c68c30e 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/constants" + "k8s.io/minikube/pkg/minikube/detect" "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(constants.ISOCacheDir, path.Base(u.Path)) + return filepath.Join(detect.ISOCacheDir(), path.Base(u.Path)) } // ISO downloads and returns the path to the downloaded ISO diff --git a/test/integration/aaa_download_only_test.go b/test/integration/aaa_download_only_test.go index d1f88dddfd30..e9a422f2ae01 100644 --- a/test/integration/aaa_download_only_test.go +++ b/test/integration/aaa_download_only_test.go @@ -143,7 +143,7 @@ func TestDownloadOnly(t *testing.T) { } // checking binaries downloaded (kubelet,kubeadm) for _, bin := range constants.KubernetesReleaseBinaries { - fp := filepath.Join(localpath.MiniPath(), "cache", "linux", v, bin) + fp := filepath.Join(localpath.MiniPath(), "cache", "linux", runtime.GOARCH, v, bin) _, err := os.Stat(fp) if err != nil { t.Errorf("expected the file for binary exist at %q but got error %v", fp, err) @@ -161,7 +161,7 @@ func TestDownloadOnly(t *testing.T) { if runtime.GOOS == "windows" { binary = "kubectl.exe" } - fp := filepath.Join(localpath.MiniPath(), "cache", runtime.GOOS, v, binary) + fp := filepath.Join(localpath.MiniPath(), "cache", runtime.GOOS, runtime.GOARCH, v, binary) if _, err := os.Stat(fp); err != nil { t.Errorf("expected the file for binary exist at %q but got error %v", fp, err) }