Skip to content

Commit

Permalink
Merge pull request #13539 from sharifelgamal/arch-binary
Browse files Browse the repository at this point in the history
add arch to binary and image cache paths
  • Loading branch information
medyagh committed Feb 10, 2022
2 parents 10d2413 + a1e273e commit d11e45a
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 28 deletions.
3 changes: 2 additions & 1 deletion pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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 @@ -897,7 +898,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
8 changes: 0 additions & 8 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"k8s.io/minikube/pkg/minikube/localpath"
)

var (
Expand Down Expand Up @@ -181,13 +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")
// 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{
"kube-system",
Expand Down
16 changes: 16 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,18 @@ 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 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 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)
}
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/download/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
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
4 changes: 2 additions & 2 deletions test/integration/aaa_download_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit d11e45a

Please sign in to comment.