Skip to content

Commit d11e45a

Browse files
authored
Merge pull request #13539 from sharifelgamal/arch-binary
add arch to binary and image cache paths
2 parents 10d2413 + a1e273e commit d11e45a

File tree

11 files changed

+37
-28
lines changed

11 files changed

+37
-28
lines changed

pkg/minikube/bootstrapper/kubeadm/kubeadm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
"k8s.io/minikube/pkg/minikube/config"
5454
"k8s.io/minikube/pkg/minikube/constants"
5555
"k8s.io/minikube/pkg/minikube/cruntime"
56+
"k8s.io/minikube/pkg/minikube/detect"
5657
"k8s.io/minikube/pkg/minikube/driver"
5758
"k8s.io/minikube/pkg/minikube/kubeconfig"
5859
"k8s.io/minikube/pkg/minikube/machine"
@@ -897,7 +898,7 @@ func (k *Bootstrapper) UpdateCluster(cfg config.ClusterConfig) error {
897898
}
898899

899900
if cfg.KubernetesConfig.ShouldLoadCachedImages {
900-
if err := machine.LoadCachedImages(&cfg, k.c, images, constants.ImageCacheDir, false); err != nil {
901+
if err := machine.LoadCachedImages(&cfg, k.c, images, detect.ImageCacheDir(), false); err != nil {
901902
out.FailureT("Unable to load cached images: {{.error}}", out.V{"error": err})
902903
}
903904
}

pkg/minikube/constants/constants.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"k8s.io/client-go/tools/clientcmd"
2525
"k8s.io/client-go/util/homedir"
26-
"k8s.io/minikube/pkg/minikube/localpath"
2726
)
2827

2928
var (
@@ -181,13 +180,6 @@ var (
181180
// kubeadm (kubelet, kubeadm) and the addon manager (kubectl)
182181
KubernetesReleaseBinaries = []string{"kubelet", "kubeadm", "kubectl"}
183182

184-
// ISOCacheDir is the path to the virtual machine image cache directory
185-
ISOCacheDir = localpath.MakeMiniPath("cache", "iso")
186-
// KICCacheDir is the path to the container node image cache directory
187-
KICCacheDir = localpath.MakeMiniPath("cache", "kic")
188-
// ImageCacheDir is the path to the container image cache directory
189-
ImageCacheDir = localpath.MakeMiniPath("cache", "images")
190-
191183
// DefaultNamespaces are Kubernetes namespaces used by minikube, including addons
192184
DefaultNamespaces = []string{
193185
"kube-system",

pkg/minikube/detect/detect.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/klauspost/cpuid"
2828
"golang.org/x/sys/cpu"
29+
"k8s.io/minikube/pkg/minikube/localpath"
2930
)
3031

3132
// RuntimeOS returns the runtime operating system
@@ -113,3 +114,18 @@ func GithubActionRunner() bool {
113114
// based on https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
114115
return os.Getenv("GITHUB_ACTIONS") == "true"
115116
}
117+
118+
// ImageCacheDir returns the path in the minikube home directory to the container image cache for the current architecture
119+
func ImageCacheDir() string {
120+
return filepath.Join(localpath.MakeMiniPath("cache", "images"), runtime.GOARCH)
121+
}
122+
123+
// KICCacheDir returns the path in the minikube home directory to the container node cache for the current architecture
124+
func KICCacheDir() string {
125+
return filepath.Join(localpath.MakeMiniPath("cache", "kic"), runtime.GOARCH)
126+
}
127+
128+
// ISOCacheDir returns the path in the minikube home directory to the virtual machine image cache for the current architecture
129+
func ISOCacheDir() string {
130+
return filepath.Join(localpath.MakeMiniPath("cache", "iso"), runtime.GOARCH)
131+
}

pkg/minikube/download/binary.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func binaryWithChecksumURL(binaryName, version, osName, archName, binaryURL stri
5555

5656
// Binary will download a binary onto the host
5757
func Binary(binary, version, osName, archName, binaryURL string) (string, error) {
58-
targetDir := localpath.MakeMiniPath("cache", osName, version)
58+
targetDir := localpath.MakeMiniPath("cache", osName, archName, version)
5959
targetFilepath := path.Join(targetDir, binary)
6060
targetLock := targetFilepath + ".lock"
6161

pkg/minikube/download/image.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/google/go-containerregistry/pkg/v1/tarball"
3434
"github.com/pkg/errors"
3535
"k8s.io/klog/v2"
36-
"k8s.io/minikube/pkg/minikube/constants"
36+
"k8s.io/minikube/pkg/minikube/detect"
3737
"k8s.io/minikube/pkg/minikube/localpath"
3838
)
3939

@@ -46,7 +46,7 @@ var (
4646

4747
// imagePathInCache returns path in local cache directory
4848
func imagePathInCache(img string) string {
49-
f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar")
49+
f := filepath.Join(detect.KICCacheDir(), path.Base(img)+".tar")
5050
f = localpath.SanitizeCacheDir(f)
5151
return f
5252
}
@@ -222,7 +222,7 @@ func CacheToDaemon(img string) error {
222222

223223
// ImageToDaemon downloads img (if not present in daemon) and writes it to the local docker daemon
224224
func ImageToDaemon(img string) error {
225-
fileLock := filepath.Join(constants.KICCacheDir, path.Base(img)+".d.lock")
225+
fileLock := filepath.Join(detect.KICCacheDir(), path.Base(img)+".d.lock")
226226
fileLock = localpath.SanitizeCacheDir(fileLock)
227227

228228
releaser, err := lockDownload(fileLock)

pkg/minikube/download/iso.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/juju/mutex"
2929
"github.com/pkg/errors"
3030
"k8s.io/klog/v2"
31-
"k8s.io/minikube/pkg/minikube/constants"
31+
"k8s.io/minikube/pkg/minikube/detect"
3232
"k8s.io/minikube/pkg/minikube/out"
3333
"k8s.io/minikube/pkg/minikube/style"
3434
"k8s.io/minikube/pkg/util/lock"
@@ -75,7 +75,7 @@ func localISOPath(u *url.URL) string {
7575
return u.String()
7676
}
7777

78-
return filepath.Join(constants.ISOCacheDir, path.Base(u.Path))
78+
return filepath.Join(detect.ISOCacheDir(), path.Base(u.Path))
7979
}
8080

8181
// ISO downloads and returns the path to the downloaded ISO

pkg/minikube/image/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/pkg/errors"
2929
"golang.org/x/sync/errgroup"
3030
"k8s.io/klog/v2"
31-
"k8s.io/minikube/pkg/minikube/constants"
31+
"k8s.io/minikube/pkg/minikube/detect"
3232
"k8s.io/minikube/pkg/minikube/localpath"
3333
"k8s.io/minikube/pkg/minikube/out"
3434
"k8s.io/minikube/pkg/util/lock"
@@ -48,7 +48,7 @@ var errCacheImageDoesntExist = &cacheError{errors.New("the image you are trying
4848
// DeleteFromCacheDir deletes tar files stored in cache dir
4949
func DeleteFromCacheDir(images []string) error {
5050
for _, image := range images {
51-
path := filepath.Join(constants.ImageCacheDir, image)
51+
path := filepath.Join(detect.ImageCacheDir(), image)
5252
path = localpath.SanitizeCacheDir(path)
5353
klog.Infoln("Deleting image in cache at ", path)
5454
if err := os.Remove(path); err != nil {

pkg/minikube/image/image.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
"github.com/pkg/errors"
3838
"k8s.io/klog/v2"
39-
"k8s.io/minikube/pkg/minikube/constants"
39+
"k8s.io/minikube/pkg/minikube/detect"
4040
"k8s.io/minikube/pkg/minikube/localpath"
4141
)
4242

@@ -198,7 +198,7 @@ func retrieveRemote(ref name.Reference, p v1.Platform) (v1.Image, error) {
198198

199199
// imagePathInCache returns path in local cache directory
200200
func imagePathInCache(img string) string {
201-
f := filepath.Join(constants.ImageCacheDir, img)
201+
f := filepath.Join(detect.ImageCacheDir(), img)
202202
f = localpath.SanitizeCacheDir(f)
203203
return f
204204
}
@@ -278,7 +278,7 @@ func fixPlatform(ref name.Reference, img v1.Image, p v1.Platform) (v1.Image, err
278278
}
279279

280280
func cleanImageCacheDir() error {
281-
err := filepath.Walk(constants.ImageCacheDir, func(path string, info os.FileInfo, err error) error {
281+
err := filepath.Walk(localpath.MakeMiniPath("cache", "images"), func(path string, info os.FileInfo, err error) error {
282282
// If error is not nil, it's because the path was already deleted and doesn't exist
283283
// Move on to next path
284284
if err != nil {

pkg/minikube/machine/cache_images.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import (
4141
"k8s.io/minikube/pkg/minikube/bootstrapper"
4242
"k8s.io/minikube/pkg/minikube/command"
4343
"k8s.io/minikube/pkg/minikube/config"
44-
"k8s.io/minikube/pkg/minikube/constants"
4544
"k8s.io/minikube/pkg/minikube/cruntime"
45+
"k8s.io/minikube/pkg/minikube/detect"
4646
"k8s.io/minikube/pkg/minikube/image"
4747
"k8s.io/minikube/pkg/minikube/localpath"
4848
"k8s.io/minikube/pkg/minikube/out"
@@ -65,7 +65,7 @@ func CacheImagesForBootstrapper(imageRepository string, version string, clusterB
6565
return errors.Wrap(err, "cached images list")
6666
}
6767

68-
if err := image.SaveToDir(images, constants.ImageCacheDir, false); err != nil {
68+
if err := image.SaveToDir(images, detect.ImageCacheDir(), false); err != nil {
6969
return errors.Wrapf(err, "Caching images for %s", clusterBootstrapper)
7070
}
7171

@@ -192,11 +192,11 @@ func CacheAndLoadImages(images []string, profiles []*config.Profile, overwrite b
192192
}
193193

194194
// This is the most important thing
195-
if err := image.SaveToDir(images, constants.ImageCacheDir, overwrite); err != nil {
195+
if err := image.SaveToDir(images, detect.ImageCacheDir(), overwrite); err != nil {
196196
return errors.Wrap(err, "save to dir")
197197
}
198198

199-
return DoLoadImages(images, profiles, constants.ImageCacheDir, overwrite)
199+
return DoLoadImages(images, profiles, detect.ImageCacheDir(), overwrite)
200200
}
201201

202202
// DoLoadImages loads images to all profiles
@@ -382,7 +382,7 @@ func SaveAndCacheImages(images []string, profiles []*config.Profile) error {
382382
return nil
383383
}
384384

385-
return DoSaveImages(images, "", profiles, constants.ImageCacheDir)
385+
return DoSaveImages(images, "", profiles, detect.ImageCacheDir())
386386
}
387387

388388
// DoSaveImages saves images from all profiles

pkg/minikube/node/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func saveImagesToTarFromConfig() error {
228228
if len(images) == 0 {
229229
return nil
230230
}
231-
return image.SaveToDir(images, constants.ImageCacheDir, false)
231+
return image.SaveToDir(images, detect.ImageCacheDir(), false)
232232
}
233233

234234
// CacheAndLoadImagesInConfig loads the images currently in the config file

0 commit comments

Comments
 (0)