Separate cached kubernetes binaries by OS on host machine (#6586)
* Separate cached kubernetes binaries by OS on host machine This way, all kubernetes binaries stored in ~/.minikube/cache/linux will be copied over to the VM and used for `minikube kubectl` on linux machines. kubectl will be stored in `~/.minikube/cache/{windows or darwin}` on windows/darwin so that `minikube kubectl` still works. * Review comment * Update integration test * Make sure --download-only includes OS specific kubectl Update integration test to make sure we download OS specific kubectl on darwin/windows when using --download-only flagpull/6588/head
parent
b0edc720b4
commit
af353314e0
|
@ -28,7 +28,6 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/exit"
|
||||
"k8s.io/minikube/pkg/minikube/machine"
|
||||
"k8s.io/minikube/pkg/minikube/out"
|
||||
)
|
||||
|
@ -55,19 +54,14 @@ minikube kubectl -- get pods --namespace kube-system`,
|
|||
out.ErrLn("Error loading profile config: %v", err)
|
||||
}
|
||||
|
||||
binary := "kubectl"
|
||||
if runtime.GOOS == "windows" {
|
||||
binary = "kubectl.exe"
|
||||
}
|
||||
|
||||
version := constants.DefaultKubernetesVersion
|
||||
if cc != nil {
|
||||
version = cc.KubernetesConfig.KubernetesVersion
|
||||
}
|
||||
|
||||
path, err := machine.CacheBinary(binary, version, runtime.GOOS, runtime.GOARCH)
|
||||
path, err := cacheKubectlBinary(version)
|
||||
if err != nil {
|
||||
exit.WithError("Failed to download kubectl", err)
|
||||
out.ErrLn("Error caching kubectl: %v", err)
|
||||
}
|
||||
|
||||
glog.Infof("Running %s %v", path, args)
|
||||
|
@ -88,3 +82,12 @@ minikube kubectl -- get pods --namespace kube-system`,
|
|||
}
|
||||
},
|
||||
}
|
||||
|
||||
func cacheKubectlBinary(k8sVerison string) (string, error) {
|
||||
binary := "kubectl"
|
||||
if runtime.GOOS == "windows" {
|
||||
binary = "kubectl.exe"
|
||||
}
|
||||
|
||||
return machine.CacheBinary(binary, k8sVerison, runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
|
|
@ -484,6 +484,9 @@ func handleDownloadOnly(cacheGroup *errgroup.Group, k8sVersion string) {
|
|||
if err := doCacheBinaries(k8sVersion); err != nil {
|
||||
exit.WithError("Failed to cache binaries", err)
|
||||
}
|
||||
if _, err := cacheKubectlBinary(k8sVersion); err != nil {
|
||||
exit.WithError("Failed to cache kubectl", err)
|
||||
}
|
||||
waitCacheRequiredImages(cacheGroup)
|
||||
if err := saveImagesToTarFromConfig(); err != nil {
|
||||
exit.WithError("Failed to cache images to tar", err)
|
||||
|
|
|
@ -63,7 +63,7 @@ func KubernetesReleaseURLSHA1(binaryName, version, osName, archName string) stri
|
|||
|
||||
// CacheBinary will cache a binary on the host
|
||||
func CacheBinary(binary, version, osName, archName string) (string, error) {
|
||||
targetDir := localpath.MakeMiniPath("cache", version)
|
||||
targetDir := localpath.MakeMiniPath("cache", osName, version)
|
||||
targetFilepath := path.Join(targetDir, binary)
|
||||
|
||||
url := KubernetesReleaseURL(binary, version, osName, archName)
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -83,12 +84,26 @@ func TestDownloadOnly(t *testing.T) {
|
|||
|
||||
// checking binaries downloaded (kubelet,kubeadm)
|
||||
for _, bin := range constants.KubernetesReleaseBinaries {
|
||||
fp := filepath.Join(localpath.MiniPath(), "cache", v, bin)
|
||||
fp := filepath.Join(localpath.MiniPath(), "cache", "linux", 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)
|
||||
}
|
||||
}
|
||||
|
||||
// If we are on darwin/windows, check to make sure OS specific kubectl has been downloaded
|
||||
// as well for the `minikube kubectl` command
|
||||
if runtime.GOOS == "linux" {
|
||||
return
|
||||
}
|
||||
binary := "kubectl"
|
||||
if runtime.GOOS == "windows" {
|
||||
binary = "kubectl.exe"
|
||||
}
|
||||
fp := filepath.Join(localpath.MiniPath(), "cache", runtime.GOOS, 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue