Skip to content

Commit 2f26193

Browse files
authored
Merge pull request #21139 from divysinghvi/no-kubernetes-skip-downloads
Skip Kubernetes preloads and binary downloads when --no-kubernetes is… #21107
2 parents 02ccb7c + c4345f2 commit 2f26193

File tree

5 files changed

+56
-5
lines changed

5 files changed

+56
-5
lines changed

pkg/minikube/bootstrapper/bsutil/binaries.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strings"
2626

2727
"github.com/pkg/errors"
28+
"github.com/spf13/viper"
2829
"golang.org/x/sync/errgroup"
2930

3031
"k8s.io/klog/v2"
@@ -39,6 +40,12 @@ import (
3940

4041
// TransferBinaries transfers all required Kubernetes binaries
4142
func TransferBinaries(cfg config.KubernetesConfig, c command.Runner, sm sysinit.Manager, binariesURL string) error {
43+
// Skip binary transfer in --no-kubernetes mode
44+
if viper.GetBool("no-kubernetes") {
45+
klog.Info("Skipping Kubernetes binary transfer due to --no-kubernetes flag")
46+
return nil
47+
}
48+
4249
ok, err := binariesExist(cfg, c)
4350
if err == nil && ok {
4451
klog.Info("Found k8s binaries, skipping transfer")

pkg/minikube/download/binary.go

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

2525
"github.com/blang/semver/v4"
2626
"github.com/pkg/errors"
27+
"github.com/spf13/viper"
2728
"k8s.io/klog/v2"
2829
"k8s.io/minikube/pkg/minikube/localpath"
2930
)
@@ -53,6 +54,11 @@ func binaryWithChecksumURL(binaryName, version, osName, archName, binaryURL stri
5354

5455
// Binary will download a binary onto the host
5556
func Binary(binary, version, osName, archName, binaryURL string) (string, error) {
57+
// Prevent Kubernetes binary downloads in --no-kubernetes mode
58+
if viper.GetBool("no-kubernetes") {
59+
klog.Infof("Skipping Kubernetes binary download due to --no-kubernetes flag")
60+
return "", nil
61+
}
5662
targetDir := localpath.MakeMiniPath("cache", osName, archName, version)
5763
targetFilepath := path.Join(targetDir, binary)
5864
targetLock := targetFilepath + ".lock"

pkg/minikube/download/preload.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ func PreloadExistsGH(k8sVersion, containerRuntime string) bool {
173173

174174
// PreloadExists returns true if there is a preloaded tarball that can be used
175175
func PreloadExists(k8sVersion, containerRuntime, driverName string, forcePreload ...bool) bool {
176+
// Prevent preload logic in --no-kubernetes mode
177+
if viper.GetBool("no-kubernetes") {
178+
klog.Infof("Skipping preload logic due to --no-kubernetes flag")
179+
return false
180+
}
176181
// TODO (#8166): Get rid of the need for this and viper at all
177182
force := false
178183
if len(forcePreload) > 0 {

pkg/minikube/node/cache.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const (
5454

5555
// BeginCacheKubernetesImages caches images required for Kubernetes version in the background
5656
func beginCacheKubernetesImages(g *errgroup.Group, imageRepository string, k8sVersion string, cRuntime string, driverName string) {
57+
// Skip all caching operations in --no-kubernetes mode
58+
if viper.GetBool("no-kubernetes") {
59+
klog.Infof("Skipping Kubernetes image caching due to --no-kubernetes flag")
60+
return
61+
}
62+
5763
// TODO: remove imageRepository check once #7695 is fixed
5864
if imageRepository == "" && download.PreloadExists(k8sVersion, cRuntime, driverName) {
5965
klog.Info("Caching tarball of preloaded images")
@@ -82,11 +88,15 @@ func handleDownloadOnly(cacheGroup, kicGroup *errgroup.Group, k8sVersion, contai
8288
}
8389

8490
binariesURL := viper.GetString("binary-mirror")
85-
if err := doCacheBinaries(k8sVersion, containerRuntime, driverName, binariesURL); err != nil {
86-
exit.Error(reason.InetCacheBinaries, "Failed to cache binaries", err)
87-
}
88-
if _, err := CacheKubectlBinary(k8sVersion, binariesURL); err != nil {
89-
exit.Error(reason.InetCacheKubectl, "Failed to cache kubectl", err)
91+
92+
// Skip binary downloads in --no-kubernetes mode
93+
if !viper.GetBool("no-kubernetes") {
94+
if err := doCacheBinaries(k8sVersion, containerRuntime, driverName, binariesURL); err != nil {
95+
exit.Error(reason.InetCacheBinaries, "Failed to cache binaries", err)
96+
}
97+
if _, err := CacheKubectlBinary(k8sVersion, binariesURL); err != nil {
98+
exit.Error(reason.InetCacheKubectl, "Failed to cache kubectl", err)
99+
}
90100
}
91101
waitCacheRequiredImages(cacheGroup)
92102
if driver.IsKIC(driverName) {

test/integration/no_kubernetes_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ import (
2323
"encoding/json"
2424
"fmt"
2525
"os/exec"
26+
"path/filepath"
27+
"runtime"
2628
"strings"
2729
"testing"
2830

2931
"k8s.io/minikube/pkg/minikube/constants"
32+
"k8s.io/minikube/pkg/minikube/localpath"
3033
)
3134

3235
// TestNoKubernetes tests starting minikube without Kubernetes,
@@ -52,6 +55,7 @@ func TestNoKubernetes(t *testing.T) {
5255
{"StartWithK8s", validateStartWithK8S},
5356
{"StartWithStopK8s", validateStartWithStopK8s},
5457
{"Start", validateStartNoK8S},
58+
{"VerifyNok8sNoK8sDownloads", VerifyNoK8sDownloadCache},
5559
{"VerifyK8sNotRunning", validateK8SNotRunning},
5660
{"ProfileList", validateProfileListNoK8S},
5761
{"Stop", validateStopNoK8S},
@@ -76,6 +80,25 @@ func TestNoKubernetes(t *testing.T) {
7680
})
7781
}
7882

83+
// VerifyNoK8sDownloadCache verifies that starting minikube with --no-kubernetes does not create a download cache.
84+
func VerifyNoK8sDownloadCache(ctx context.Context, t *testing.T, profile string) {
85+
defer PostMortemLogs(t, profile)
86+
87+
cachePath := filepath.Join(localpath.MiniPath(), "cache", runtime.GOOS, runtime.GOARCH, constants.NoKubernetesVersion)
88+
89+
t.Logf("Checking cache directory: %s", cachePath)
90+
files, err := filepath.Glob(filepath.Join(cachePath, "*"))
91+
if err != nil {
92+
t.Errorf("Error reading cache directory: %v", err)
93+
return
94+
}
95+
96+
if len(files) > 0 {
97+
t.Logf("Files found in cache directory: %v", files)
98+
t.Errorf("Cache directory should not contain files when using --no-kubernetes")
99+
}
100+
}
101+
79102
// validateStartNoK8sWithVersion expect an error when starting a minikube cluster without kubernetes and with a kubernetes version.
80103
func validateStartNoK8sWithVersion(ctx context.Context, t *testing.T, profile string) {
81104
defer PostMortemLogs(t, profile)

0 commit comments

Comments
 (0)