Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ type fakeDockerConfig struct {

func (d fakeDockerConfig) GetKubeContext() string { return d.kubeContext }
func (d fakeDockerConfig) MinikubeProfile() string { return "" }
func (d fakeDockerConfig) DetectMinikube() bool { return true }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding true here for DetectMinikube means that integration tests using SetupDockerClient will always run with minikube detection enabled. This prevents testing the behavior when this flag is false. Consider making this configurable, for example by adding a field to fakeDockerConfig, to allow for more comprehensive testing.

func (d fakeDockerConfig) GlobalConfig() string { return "" }
func (d fakeDockerConfig) Prune() bool { return false }
func (d fakeDockerConfig) ContainerDebugging() bool { return false }
Expand Down
7 changes: 4 additions & 3 deletions pkg/skaffold/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ type Config interface {
GlobalConfig() string
GetKubeContext() string
MinikubeProfile() string
DetectMinikube() bool
GetInsecureRegistries() map[string]bool
Mode() config.RunMode
}

// NewAPIClientImpl guesses the docker client to use based on current Kubernetes context.
func NewAPIClientImpl(ctx context.Context, cfg Config) (LocalDaemon, error) {
dockerAPIClientOnce.Do(func() {
env, apiClient, err := newAPIClient(ctx, cfg.GetKubeContext(), cfg.MinikubeProfile())
env, apiClient, err := newAPIClient(ctx, cfg.GetKubeContext(), cfg.MinikubeProfile(), cfg.DetectMinikube())
dockerAPIClient = NewLocalDaemon(apiClient, env, cfg.Prune(), cfg)
dockerAPIClientErr = err
})
Expand All @@ -84,11 +85,11 @@ func NewAPIClientImpl(ctx context.Context, cfg Config) (LocalDaemon, error) {
// kubecontext API Server to minikube profiles

// newAPIClient guesses the docker client to use based on current Kubernetes context.
func newAPIClient(ctx context.Context, kubeContext string, minikubeProfile string) ([]string, client.CommonAPIClient, error) {
func newAPIClient(ctx context.Context, kubeContext string, minikubeProfile string, detectMinikube bool) ([]string, client.CommonAPIClient, error) {
if minikubeProfile != "" { // skip validation if explicitly specifying minikubeProfile.
return newMinikubeAPIClient(ctx, minikubeProfile)
}
if cluster.GetClient().IsMinikube(ctx, kubeContext) {
if detectMinikube && cluster.GetClient().IsMinikube(ctx, kubeContext) {
return newMinikubeAPIClient(ctx, kubeContext)
}
return newEnvAPIClient()
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/docker/dockertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (m configStub) ContainerDebugging() bool {
return false
}

func (m configStub) DetectMinikube() bool {
return true
}
Comment on lines +91 to +93
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While hardcoding true maintains the previous behavior for existing tests, it prevents testing scenarios where minikube detection is disabled (--detect-minikube=false). To improve testability of the new logic, consider making this value configurable. You could, for example, add a detectMinikube field to the configStub struct and initialize it in NewConfigStub.


func NewConfigStub(mode config.RunMode, prune bool) Config {
return &configStub{runMode: mode, prune: prune}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/runner/runcontext/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func (rc *RunContext) GlobalConfig() string { return rc
func (rc *RunContext) HydratedManifests() []string { return rc.Opts.HydratedManifests }
func (rc *RunContext) LoadImages() bool { return rc.Cluster.LoadImages }
func (rc *RunContext) ForceLoadImages() bool { return rc.Opts.ForceLoadImages }
func (rc *RunContext) DetectMinikube() bool { return rc.Opts.DetectMinikube }
func (rc *RunContext) MinikubeProfile() string { return rc.Opts.MinikubeProfile }
func (rc *RunContext) Muted() config.Muted { return rc.Opts.Muted }
func (rc *RunContext) NoPruneChildren() bool { return rc.Opts.NoPruneChildren }
Expand Down