Skip to content

Commit

Permalink
pass namespace to kubectl build command to avoid incluster bug
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Garcia <alexandre.garcia@prodigygame.com>
Co-authored-by: Noel Chin <noel.chin@prodigygame.com>
  • Loading branch information
kuuji and nachin committed Oct 26, 2023
1 parent 69e7df3 commit 51a98e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/devspace/deploy/deployer/kubectl/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

// Builder is the manifest builder interface
type Builder interface {
Build(ctx context.Context, environ expand.Environ, dir, manifest string) ([]*unstructured.Unstructured, error)
Build(ctx context.Context, environ expand.Environ, dir, namespace string, manifest string) ([]*unstructured.Unstructured, error)
}

type kustomizeBuilder struct {
Expand All @@ -42,7 +42,7 @@ func NewKustomizeBuilder(path string, config *latest.DeploymentConfig, log log.L
}
}

func (k *kustomizeBuilder) Build(ctx context.Context, environ expand.Environ, dir, manifest string) ([]*unstructured.Unstructured, error) {
func (k *kustomizeBuilder) Build(ctx context.Context, environ expand.Environ, dir, namespace string, manifest string) ([]*unstructured.Unstructured, error) {
args := []string{"build", manifest}
args = append(args, k.config.Kubectl.KustomizeArgs...)

Expand Down Expand Up @@ -108,7 +108,7 @@ var useOldDryRun = func(ctx context.Context, environ expand.Environ, dir, path s
return false, nil
}

func (k *kubectlBuilder) Build(ctx context.Context, environ expand.Environ, dir, manifest string) ([]*unstructured.Unstructured, error) {
func (k *kubectlBuilder) Build(ctx context.Context, environ expand.Environ, dir, namespace string, manifest string) ([]*unstructured.Unstructured, error) {
tempFile, err := os.CreateTemp("", "")
if err != nil {
return nil, err
Expand All @@ -135,9 +135,9 @@ func (k *kubectlBuilder) Build(ctx context.Context, environ expand.Environ, dir,
}

if uodr {
args = append(args, "--dry-run", "--output", "yaml", "--validate=false")
args = append(args, "--dry-run", "--output", "yaml", "--validate=false", "-n", namespace)
} else {
args = append(args, "--dry-run=client", "--output", "yaml", "--validate=false")
args = append(args, "--dry-run=client", "--output", "yaml", "--validate=false", "-n", namespace)
}

if k.config.Kubectl.Kustomize != nil && *k.config.Kubectl.Kustomize {
Expand Down
4 changes: 2 additions & 2 deletions pkg/devspace/deploy/deployer/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (d *DeployConfig) buildManifests(ctx devspacecontext.Context, manifest stri
}

if d.DeploymentConfig.Kubectl.Kustomize != nil && *d.DeploymentConfig.Kubectl.Kustomize && d.isKustomizeInstalled(ctx.Context(), ctx.WorkingDir(), kustomizePath) {
return NewKustomizeBuilder(kustomizePath, d.DeploymentConfig, ctx.Log()).Build(ctx.Context(), ctx.Environ(), ctx.WorkingDir(), manifest)
return NewKustomizeBuilder(kustomizePath, d.DeploymentConfig, ctx.Log()).Build(ctx.Context(), ctx.Environ(), ctx.WorkingDir(), ctx.KubeClient().Namespace(), manifest)
}

raw, err := ctx.KubeClient().KubeConfigLoader().LoadRawConfig()
Expand All @@ -334,7 +334,7 @@ func (d *DeployConfig) buildManifests(ctx devspacecontext.Context, manifest stri
}

// Build with kubectl
return NewKubectlBuilder(d.CmdPath, d.DeploymentConfig, *copied).Build(ctx.Context(), ctx.Environ(), ctx.WorkingDir(), manifest)
return NewKubectlBuilder(d.CmdPath, d.DeploymentConfig, *copied).Build(ctx.Context(), ctx.Environ(), ctx.WorkingDir(), ctx.KubeClient().Namespace(), manifest)
}

func (d *DeployConfig) isKustomizeInstalled(ctx context.Context, dir, path string) bool {
Expand Down

0 comments on commit 51a98e6

Please sign in to comment.