Skip to content
Open
6 changes: 6 additions & 0 deletions pkg/minikube/download/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/blang/semver/v4"
"github.com/pkg/errors"
"github.com/spf13/viper"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/localpath"
)
Expand Down Expand Up @@ -53,6 +54,11 @@ 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) {
// Prevent Kubernetes binary downloads in --no-kubernetes mode
if viper.GetBool("no-kubernetes") {
klog.Infof("Skipping Kubernetes binary download due to --no-kubernetes flag")
return "", nil
}
targetDir := localpath.MakeMiniPath("cache", osName, archName, version)
targetFilepath := path.Join(targetDir, binary)
targetLock := targetFilepath + ".lock"
Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/download/preload.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ var checkRemotePreloadExists = func(k8sVersion, containerRuntime string) bool {

// PreloadExists returns true if there is a preloaded tarball that can be used
func PreloadExists(k8sVersion, containerRuntime, driverName string, forcePreload ...bool) bool {
// Prevent preload logic in --no-kubernetes mode
if viper.GetBool("no-kubernetes") {
klog.Infof("Skipping preload logic due to --no-kubernetes flag")
return false
}
// TODO (#8166): Get rid of the need for this and viper at all
force := false
if len(forcePreload) > 0 {
Expand Down
18 changes: 18 additions & 0 deletions test/integration/no_kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
Expand Down Expand Up @@ -50,6 +52,7 @@ func TestNoKubernetes(t *testing.T) {
{"StartWithK8s", validateStartWithK8S},
{"StartWithStopK8s", validateStartWithStopK8s},
{"Start", validateStartNoK8S},
{"VerifyNok8sNoK8sDownloads", VerifyNoK8sDownloadCache},
{"VerifyK8sNotRunning", validateK8SNotRunning},
{"ProfileList", validateProfileListNoK8S},
{"Stop", validateStopNoK8S},
Expand All @@ -74,6 +77,21 @@ func TestNoKubernetes(t *testing.T) {
})
}

// VerifyNoK8sDownloadCache verifies that starting minikube with --no-kubernetes does not create a download cache.
func VerifyNoK8sDownloadCache(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

// Reuse the minikube instance started by validateStartNoK8S.
homeDir := os.Getenv("HOME")
cachePath := filepath.Join(homeDir, ".minikube", "cache", "linux", "amd64", "v0.0.0")

if _, err := os.Stat(cachePath); err == nil {
t.Fatalf("Cache directory %s should not exist when using --no-kubernetes", cachePath)
} else if err != nil && !os.IsNotExist(err) {
t.Fatalf("Error checking cache directory %s: %v", cachePath, err)
}
}

// validateStartNoK8sWithVersion expect an error when starting a minikube cluster without kubernetes and with a kubernetes version.
func validateStartNoK8sWithVersion(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)
Expand Down