Skip to content

Commit 439fea6

Browse files
committed
feat: push images if load is disabled for kind or k3d
1 parent 905e6bb commit 439fea6

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

pkg/skaffold/config/util.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,7 @@ func GetLocalCluster(configFile string, minikubeProfile string, detectMinikubeCl
183183
return *cfg.LocalCluster, nil
184184
}
185185

186-
config, err := kubectx.CurrentConfig()
187-
if err != nil {
188-
return true, err
189-
}
190-
return isDefaultLocal(config.CurrentContext, detectMinikubeCluster), nil
186+
return isDefaultLocal(configFile, detectMinikubeCluster)
191187
}
192188

193189
func GetInsecureRegistries(configFile string) ([]string, error) {
@@ -229,18 +225,31 @@ func IsImageLoadingRequired(configFile string) (bool, error) {
229225
(IsK3dCluster(kubeContext) && !k3dDisableLoad), nil
230226
}
231227

232-
func isDefaultLocal(kubeContext string, detectMinikubeCluster bool) bool {
228+
func isDefaultLocal(configFile string, detectMinikubeCluster bool) (bool, error) {
229+
cfg, err := GetConfigForCurrentKubectx(configFile)
230+
if err != nil {
231+
return false, err
232+
}
233+
234+
kubeContext := cfg.Kubecontext
235+
236+
imageLoadingRequired, err := IsImageLoadingRequired(configFile)
237+
if err != nil {
238+
return false, err
239+
}
240+
233241
if kubeContext == constants.DefaultMinikubeContext ||
234242
kubeContext == constants.DefaultDockerForDesktopContext ||
235243
kubeContext == constants.DefaultDockerDesktopContext ||
236-
IsKindCluster(kubeContext) ||
237-
IsK3dCluster(kubeContext) {
238-
return true
244+
imageLoadingRequired {
245+
return true, nil
239246
}
247+
240248
if detectMinikubeCluster {
241-
return cluster.GetClient().IsMinikube(kubeContext)
249+
return cluster.GetClient().IsMinikube(kubeContext), nil
242250
}
243-
return false
251+
252+
return false, nil
244253
}
245254

246255
// IsKindCluster checks that the given `kubeContext` is talking to `kind`.

pkg/skaffold/config/util_test.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -267,27 +267,30 @@ func TestIsUpdateCheckEnabled(t *testing.T) {
267267

268268
func TestIsDefaultLocal(t *testing.T) {
269269
tests := []struct {
270-
context string
270+
cfg *ContextConfig
271271
expectedLocal bool
272272
}{
273-
{context: "kind-other", expectedLocal: true},
274-
{context: "kind@kind", expectedLocal: true},
275-
{context: "k3d-k3s-default", expectedLocal: true},
276-
{context: "docker-for-desktop", expectedLocal: true},
277-
{context: "minikube", expectedLocal: true},
278-
{context: "docker-desktop", expectedLocal: true},
279-
{context: "anything-else", expectedLocal: false},
280-
{context: "kind@blah", expectedLocal: false},
281-
{context: "other-kind", expectedLocal: false},
282-
{context: "not-k3d", expectedLocal: false},
273+
{cfg: &ContextConfig{Kubecontext: "kind-other"}, expectedLocal: true},
274+
{cfg: &ContextConfig{Kubecontext: "kind-other", KindDisableLoad: util.BoolPtr(true)}, expectedLocal: false},
275+
{cfg: &ContextConfig{Kubecontext: "kind@kind"}, expectedLocal: true},
276+
{cfg: &ContextConfig{Kubecontext: "k3d-k3s-default"}, expectedLocal: true},
277+
{cfg: &ContextConfig{Kubecontext: "k3d-k3s-default", K3dDisableLoad: util.BoolPtr(true)}, expectedLocal: false},
278+
{cfg: &ContextConfig{Kubecontext: "docker-for-desktop"}, expectedLocal: true},
279+
{cfg: &ContextConfig{Kubecontext: "minikube"}, expectedLocal: true},
280+
{cfg: &ContextConfig{Kubecontext: "docker-desktop"}, expectedLocal: true},
281+
{cfg: &ContextConfig{Kubecontext: "anything-else"}, expectedLocal: false},
282+
{cfg: &ContextConfig{Kubecontext: "kind@blah"}, expectedLocal: false},
283+
{cfg: &ContextConfig{Kubecontext: "other-kind"}, expectedLocal: false},
284+
{cfg: &ContextConfig{Kubecontext: "not-k3d"}, expectedLocal: false},
283285
}
284286
for _, test := range tests {
285287
testutil.Run(t, "", func(t *testutil.T) {
288+
t.Override(&GetConfigForCurrentKubectx, func(string) (*ContextConfig, error) { return test.cfg, nil })
286289
t.Override(&cluster.GetClient, func() cluster.Client { return fakeClient{} })
287290

288-
local := isDefaultLocal(test.context, true)
291+
local, _ := isDefaultLocal("dummyname", true)
289292
t.CheckDeepEqual(test.expectedLocal, local)
290-
local = isDefaultLocal(test.context, false)
293+
local, _ = isDefaultLocal("dummyname", false)
291294
t.CheckDeepEqual(test.expectedLocal, local)
292295
})
293296
}

0 commit comments

Comments
 (0)