Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass namespace to kubectl build to fix incluster bug #2747

Closed
Closed
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
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
Loading