Skip to content

Commit b91bfbe

Browse files
authored
Hide minikube detection behind flag (#4745)
* Hide minikube detection behind flag * Hide minikube detection behind flag
1 parent b642a69 commit b91bfbe

File tree

8 files changed

+42
-12
lines changed

8 files changed

+42
-12
lines changed

cmd/skaffold/app/cmd/flags.go

+8
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ var flagRegistry = []Flag{
398398
FlagAddMethod: "DurationVar",
399399
DefinedOn: []string{"deploy", "dev", "run", "debug"},
400400
},
401+
{
402+
Name: "detect-minikube",
403+
Usage: "Use heuristics to detect a minikube cluster",
404+
Value: &opts.DetectMinikube,
405+
DefValue: false,
406+
FlagAddMethod: "BoolVar",
407+
DefinedOn: []string{"build", "debug", "delete", "deploy", "dev", "run"},
408+
},
401409
}
402410

403411
func (fl *Flag) flag() *pflag.Flag {

docs/content/en/docs/references/cli/_index.md

+12
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Options:
134134
--cache-file='': Specify the location of the cache file (default $HOME/.skaffold/cache)
135135
-c, --config='': File for global configurations (defaults to $HOME/.skaffold/config)
136136
-d, --default-repo='': Default repository value (overrides global config)
137+
--detect-minikube=false: Use heuristics to detect a minikube cluster
137138
--dry-run=false: Don't build images, just compute the tag for each artifact.
138139
--enable-rpc=false: Enable gRPC for exposing Skaffold events (true by default for `skaffold dev`)
139140
--file-output='': Filename to write build images to
@@ -167,6 +168,7 @@ Env vars:
167168
* `SKAFFOLD_CACHE_FILE` (same as `--cache-file`)
168169
* `SKAFFOLD_CONFIG` (same as `--config`)
169170
* `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`)
171+
* `SKAFFOLD_DETECT_MINIKUBE` (same as `--detect-minikube`)
170172
* `SKAFFOLD_DRY_RUN` (same as `--dry-run`)
171173
* `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`)
172174
* `SKAFFOLD_FILE_OUTPUT` (same as `--file-output`)
@@ -341,6 +343,7 @@ Options:
341343
--cleanup=true: Delete deployments after dev or debug mode is interrupted
342344
-c, --config='': File for global configurations (defaults to $HOME/.skaffold/config)
343345
-d, --default-repo='': Default repository value (overrides global config)
346+
--detect-minikube=false: Use heuristics to detect a minikube cluster
344347
--enable-rpc=false: Enable gRPC for exposing Skaffold events (true by default for `skaffold dev`)
345348
-f, --filename='skaffold.yaml': Path or URL to the Skaffold config file
346349
--force=false: Recreate Kubernetes resources if necessary for deployment, warning: might cause downtime!
@@ -383,6 +386,7 @@ Env vars:
383386
* `SKAFFOLD_CLEANUP` (same as `--cleanup`)
384387
* `SKAFFOLD_CONFIG` (same as `--config`)
385388
* `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`)
389+
* `SKAFFOLD_DETECT_MINIKUBE` (same as `--detect-minikube`)
386390
* `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`)
387391
* `SKAFFOLD_FILENAME` (same as `--filename`)
388392
* `SKAFFOLD_FORCE` (same as `--force`)
@@ -421,6 +425,7 @@ Delete the deployed application
421425
Options:
422426
-c, --config='': File for global configurations (defaults to $HOME/.skaffold/config)
423427
-d, --default-repo='': Default repository value (overrides global config)
428+
--detect-minikube=false: Use heuristics to detect a minikube cluster
424429
-f, --filename='skaffold.yaml': Path or URL to the Skaffold config file
425430
--kube-context='': Deploy to this Kubernetes context
426431
--kubeconfig='': Path to the kubeconfig file to use for CLI requests.
@@ -439,6 +444,7 @@ Env vars:
439444

440445
* `SKAFFOLD_CONFIG` (same as `--config`)
441446
* `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`)
447+
* `SKAFFOLD_DETECT_MINIKUBE` (same as `--detect-minikube`)
442448
* `SKAFFOLD_FILENAME` (same as `--filename`)
443449
* `SKAFFOLD_KUBE_CONTEXT` (same as `--kube-context`)
444450
* `SKAFFOLD_KUBECONFIG` (same as `--kubeconfig`)
@@ -470,6 +476,7 @@ Options:
470476
-a, --build-artifacts=: File containing build result from a previous 'skaffold build --file-output'
471477
-c, --config='': File for global configurations (defaults to $HOME/.skaffold/config)
472478
-d, --default-repo='': Default repository value (overrides global config)
479+
--detect-minikube=false: Use heuristics to detect a minikube cluster
473480
--enable-rpc=false: Enable gRPC for exposing Skaffold events (true by default for `skaffold dev`)
474481
-f, --filename='skaffold.yaml': Path or URL to the Skaffold config file
475482
--force=false: Recreate Kubernetes resources if necessary for deployment, warning: might cause downtime!
@@ -504,6 +511,7 @@ Env vars:
504511
* `SKAFFOLD_BUILD_ARTIFACTS` (same as `--build-artifacts`)
505512
* `SKAFFOLD_CONFIG` (same as `--config`)
506513
* `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`)
514+
* `SKAFFOLD_DETECT_MINIKUBE` (same as `--detect-minikube`)
507515
* `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`)
508516
* `SKAFFOLD_FILENAME` (same as `--filename`)
509517
* `SKAFFOLD_FORCE` (same as `--force`)
@@ -539,6 +547,7 @@ Options:
539547
--cleanup=true: Delete deployments after dev or debug mode is interrupted
540548
-c, --config='': File for global configurations (defaults to $HOME/.skaffold/config)
541549
-d, --default-repo='': Default repository value (overrides global config)
550+
--detect-minikube=false: Use heuristics to detect a minikube cluster
542551
--enable-rpc=false: Enable gRPC for exposing Skaffold events (true by default for `skaffold dev`)
543552
-f, --filename='skaffold.yaml': Path or URL to the Skaffold config file
544553
--force=false: Recreate Kubernetes resources if necessary for deployment, warning: might cause downtime!
@@ -582,6 +591,7 @@ Env vars:
582591
* `SKAFFOLD_CLEANUP` (same as `--cleanup`)
583592
* `SKAFFOLD_CONFIG` (same as `--config`)
584593
* `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`)
594+
* `SKAFFOLD_DETECT_MINIKUBE` (same as `--detect-minikube`)
585595
* `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`)
586596
* `SKAFFOLD_FILENAME` (same as `--filename`)
587597
* `SKAFFOLD_FORCE` (same as `--force`)
@@ -797,6 +807,7 @@ Options:
797807
--cleanup=true: Delete deployments after dev or debug mode is interrupted
798808
-c, --config='': File for global configurations (defaults to $HOME/.skaffold/config)
799809
-d, --default-repo='': Default repository value (overrides global config)
810+
--detect-minikube=false: Use heuristics to detect a minikube cluster
800811
--enable-rpc=false: Enable gRPC for exposing Skaffold events (true by default for `skaffold dev`)
801812
-f, --filename='skaffold.yaml': Path or URL to the Skaffold config file
802813
--force=false: Recreate Kubernetes resources if necessary for deployment, warning: might cause downtime!
@@ -838,6 +849,7 @@ Env vars:
838849
* `SKAFFOLD_CLEANUP` (same as `--cleanup`)
839850
* `SKAFFOLD_CONFIG` (same as `--config`)
840851
* `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`)
852+
* `SKAFFOLD_DETECT_MINIKUBE` (same as `--detect-minikube`)
841853
* `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`)
842854
* `SKAFFOLD_FILENAME` (same as `--filename`)
843855
* `SKAFFOLD_FORCE` (same as `--force`)

pkg/skaffold/build/local/local_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func TestNewBuilder(t *testing.T) {
273273
shouldErr bool
274274
localBuild latest.LocalBuild
275275
expectedBuilder *Builder
276-
localClusterFn func(string, string) (bool, error)
276+
localClusterFn func(string, string, bool) (bool, error)
277277
localDockerFn func(docker.Config) (docker.LocalDaemon, error)
278278
}{
279279
{
@@ -288,7 +288,7 @@ func TestNewBuilder(t *testing.T) {
288288
localDockerFn: func(docker.Config) (docker.LocalDaemon, error) {
289289
return dummyDaemon, nil
290290
},
291-
localClusterFn: func(string, string) (b bool, e error) {
291+
localClusterFn: func(string, string, bool) (b bool, e error) {
292292
b = false //because this is false and localBuild.push is nil
293293
return
294294
},
@@ -311,7 +311,7 @@ func TestNewBuilder(t *testing.T) {
311311
localDockerFn: func(docker.Config) (docker.LocalDaemon, error) {
312312
return dummyDaemon, nil
313313
},
314-
localClusterFn: func(string, string) (b bool, e error) {
314+
localClusterFn: func(string, string, bool) (b bool, e error) {
315315
b = false
316316
return
317317
},

pkg/skaffold/build/local/types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type Config interface {
5757
Pipeline() latest.Pipeline
5858
GlobalConfig() string
5959
GetKubeContext() string
60+
DetectMinikube() bool
6061
SkipTests() bool
6162
Mode() config.RunMode
6263
NoPruneChildren() bool
@@ -74,7 +75,7 @@ func NewBuilder(cfg Config) (*Builder, error) {
7475
// remove minikubeProfile from here and instead detect it by matching the
7576
// kubecontext API Server to minikube profiles
7677

77-
localCluster, err := getLocalCluster(cfg.GlobalConfig(), cfg.MinikubeProfile())
78+
localCluster, err := getLocalCluster(cfg.GlobalConfig(), cfg.MinikubeProfile(), cfg.DetectMinikube())
7879
if err != nil {
7980
return nil, fmt.Errorf("getting localCluster: %w", err)
8081
}

pkg/skaffold/config/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type SkaffoldOptions struct {
6666
// commands which don't deploy (e.g. `skaffold render`) since the runID
6767
// label isn't available.
6868
AddSkaffoldLabels bool
69+
DetectMinikube bool
6970

7071
PortForward PortForwardOptions
7172
CustomTag string

pkg/skaffold/config/util.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func GetDefaultRepo(configFile string, cliValue *string) (string, error) {
171171
return cfg.DefaultRepo, nil
172172
}
173173

174-
func GetLocalCluster(configFile string, minikubeProfile string) (bool, error) {
174+
func GetLocalCluster(configFile string, minikubeProfile string, detectMinikubeCluster bool) (bool, error) {
175175
if minikubeProfile != "" {
176176
return true, nil
177177
}
@@ -189,7 +189,7 @@ func GetLocalCluster(configFile string, minikubeProfile string) (bool, error) {
189189
if err != nil {
190190
return true, err
191191
}
192-
return isDefaultLocal(config.CurrentContext), nil
192+
return isDefaultLocal(config.CurrentContext, detectMinikubeCluster), nil
193193
}
194194

195195
func GetInsecureRegistries(configFile string) ([]string, error) {
@@ -216,12 +216,18 @@ func GetDebugHelpersRegistry(configFile string) (string, error) {
216216
return constants.DefaultDebugHelpersRegistry, nil
217217
}
218218

219-
func isDefaultLocal(kubeContext string) bool {
220-
return kubeContext == constants.DefaultDockerForDesktopContext ||
219+
func isDefaultLocal(kubeContext string, detectMinikubeCluster bool) bool {
220+
if kubeContext == constants.DefaultMinikubeContext ||
221+
kubeContext == constants.DefaultDockerForDesktopContext ||
221222
kubeContext == constants.DefaultDockerDesktopContext ||
222223
IsKindCluster(kubeContext) ||
223-
IsK3dCluster(kubeContext) ||
224-
cluster.GetClient().IsMinikube(kubeContext)
224+
IsK3dCluster(kubeContext) {
225+
return true
226+
}
227+
if detectMinikubeCluster {
228+
return cluster.GetClient().IsMinikube(kubeContext)
229+
}
230+
return false
225231
}
226232

227233
// IsImageLoadingRequired checks if the cluster requires loading images into it

pkg/skaffold/config/util_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ func TestIsDefaultLocal(t *testing.T) {
285285
testutil.Run(t, "", func(t *testutil.T) {
286286
t.Override(&cluster.GetClient, func() cluster.Client { return fakeClient{} })
287287

288-
local := isDefaultLocal(test.context)
289-
288+
local := isDefaultLocal(test.context, true)
289+
t.CheckDeepEqual(test.expectedLocal, local)
290+
local = isDefaultLocal(test.context, false)
290291
t.CheckDeepEqual(test.expectedLocal, local)
291292
})
292293
}

pkg/skaffold/runner/runcontext/context.go

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (rc *RunContext) GetKubeConfig() string { return rc.Opt
6767
func (rc *RunContext) GetKubeNamespace() string { return rc.Opts.Namespace }
6868
func (rc *RunContext) GlobalConfig() string { return rc.Opts.GlobalConfig }
6969
func (rc *RunContext) MinikubeProfile() string { return rc.Opts.MinikubeProfile }
70+
func (rc *RunContext) DetectMinikube() bool { return rc.Opts.DetectMinikube }
7071
func (rc *RunContext) Muted() config.Muted { return rc.Opts.Muted }
7172
func (rc *RunContext) NoPruneChildren() bool { return rc.Opts.NoPruneChildren }
7273
func (rc *RunContext) Notification() bool { return rc.Opts.Notification }

0 commit comments

Comments
 (0)