Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add arch to binary and image cache paths #13539

Merged
merged 7 commits into from
Feb 10, 2022
3 changes: 2 additions & 1 deletion pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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})
}
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ var (

// ISOCacheDir is the path to the virtual machine image cache directory
ISOCacheDir = localpath.MakeMiniPath("cache", "iso")
sharifelgamal marked this conversation as resolved.
Show resolved Hide resolved
// 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{
Expand Down
11 changes: 11 additions & 0 deletions pkg/minikube/detect/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
sharifelgamal marked this conversation as resolved.
Show resolved Hide resolved
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)
}
2 changes: 1 addition & 1 deletion pkg/minikube/download/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions pkg/minikube/download/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/image/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/minikube/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions pkg/minikube/machine/cache_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/node/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down