Skip to content

Commit 8da76ac

Browse files
authored
Merge pull request #2157 from FabianKramm/print-feat
refactor: add support for named kind clusters
2 parents 1b91eb8 + 6f570d3 commit 8da76ac

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

pkg/devspace/build/builder/buildkit/buildkit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ func buildWithCLI(ctx context.Context, dir string, context io.Reader, writer io.
209209
return err
210210
}
211211
//load image if it is a kind-context
212-
if skipPush && kubeClient != nil && kubectl.IsKindContext(kubeClient.CurrentContext()) {
212+
if skipPush && kubeClient != nil && kubectl.GetKindContext(kubeClient.CurrentContext()) != "" {
213213
if len(options.Tags) > 0 {
214214
for _, tag := range options.Tags {
215-
command := []string{"kind", "load", "docker-image", tag}
215+
command := []string{"kind", "load", "docker-image", "--name", kubectl.GetKindContext(kubeClient.CurrentContext()), tag}
216216
completeArgs := []string{}
217217
completeArgs = append(completeArgs, command[1:]...)
218218
err = command2.CommandWithEnv(ctx, dir, writer, writer, nil, minikubeEnv, command[0], completeArgs...)

pkg/devspace/build/builder/docker/docker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ func (b *Builder) BuildImage(ctx devspacecontext.Context, contextPath, dockerfil
184184
} else {
185185
ctx.Log().Infof("Skip image push for %s", b.helper.ImageName)
186186
//load image if it is a kind-context
187-
if ctx.KubeClient() != nil && kubectl.IsKindContext(ctx.KubeClient().CurrentContext()) {
187+
if ctx.KubeClient() != nil && kubectl.GetKindContext(ctx.KubeClient().CurrentContext()) != "" {
188188
for _, tag := range buildOptions.Tags {
189-
command := []string{"kind", "load", "docker-image", tag}
189+
command := []string{"kind", "load", "docker-image", "--name", kubectl.GetKindContext(ctx.KubeClient().CurrentContext()), tag}
190190
completeArgs := []string{}
191191
completeArgs = append(completeArgs, command[1:]...)
192192
// Determine output writer

pkg/devspace/kubectl/util.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
)
1818

1919
const minikubeContext = "minikube"
20-
const kindContext = "kind-kind"
2120
const dockerDesktopContext = "docker-desktop"
2221
const dockerForDesktopContext = "docker-for-desktop"
2322

@@ -203,7 +202,7 @@ func NewPortForwarder(client Client, pod *corev1.Pod, ports []string, addresses
203202
// IsLocalKubernetes returns true if the context belongs to a local Kubernetes cluster
204203
func IsLocalKubernetes(context string) bool {
205204
if context == minikubeContext ||
206-
context == kindContext ||
205+
strings.HasPrefix(context, "kind-") ||
207206
context == dockerDesktopContext ||
208207
context == dockerForDesktopContext {
209208
return true
@@ -214,7 +213,11 @@ func IsLocalKubernetes(context string) bool {
214213
return false
215214
}
216215

217-
// IsKindContext returns true if the context is a kind Kubernetes cluster
218-
func IsKindContext(context string) bool {
219-
return context == kindContext
216+
// GetKindContext returns the kind cluster name
217+
func GetKindContext(context string) string {
218+
if !strings.HasPrefix(context, "kind-") {
219+
return ""
220+
}
221+
222+
return strings.TrimPrefix(context, "kind-")
220223
}

0 commit comments

Comments
 (0)