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

Add ability to deploy Kubernetes application to the specified namespace #213

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/app/piped/cloudprovider/kubernetes/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewKubectl(version, path string) *Kubectl {
}
}

func (c *Kubectl) Apply(ctx context.Context, manifest Manifest) (err error) {
func (c *Kubectl) Apply(ctx context.Context, namespace string, manifest Manifest) (err error) {
defer func() {
metricsKubectlCalled(c.version, "apply", err == nil)
}()
Expand All @@ -46,7 +46,14 @@ func (c *Kubectl) Apply(ctx context.Context, manifest Manifest) (err error) {
if err != nil {
return err
}
cmd := exec.CommandContext(ctx, c.execPath, "apply", "-f", "-")

args := make([]string, 0, 5)
if namespace != "" {
args = append(args, "-n", namespace)
}
args = append(args, "apply", "-f", "-")

cmd := exec.CommandContext(ctx, c.execPath, args...)
r := bytes.NewReader(data)
cmd.Stdin = r

Expand All @@ -62,10 +69,12 @@ func (c *Kubectl) Delete(ctx context.Context, r ResourceKey) (err error) {
metricsKubectlCalled(c.version, "delete", err == nil)
}()

args := []string{"delete", r.Kind, r.Name}
args := make([]string, 0, 5)
if r.Namespace != "" {
args = append(args, "-n", r.Namespace)
}
args = append(args, "delete", r.Kind, r.Name)

cmd := exec.CommandContext(ctx, c.execPath, args...)
out, err := cmd.CombinedOutput()

Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/cloudprovider/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (p *provider) ApplyManifest(ctx context.Context, manifest Manifest) error {
return p.initErr
}

return p.kubectl.Apply(ctx, manifest)
return p.kubectl.Apply(ctx, p.input.Namespace, manifest)
}

// Delete deletes the given resource from Kubernetes cluster.
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/executor/kubernetes/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (e *Executor) ensureCanaryClean(ctx context.Context) model.StageStatus {
return model.StageStatus_STAGE_SUCCESS
}

// TODO: Add namespace for generated resources.
func (e *Executor) generateCanaryManifests(ctx context.Context, manifests []provider.Manifest, opts config.K8sCanaryRolloutStageOptions) ([]provider.Manifest, error) {
// List of default configurations.
var (
Expand Down
1 change: 1 addition & 0 deletions pkg/config/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ type KubernetesDeploymentInput struct {
HelmOptions *InputHelmOptions `json:"helmOptions"`
HelmVersion string `json:"helmVersion"`

// The namespace where manifests will be applied.
Namespace string `json:"namespace"`
// Automatically reverts all changes from all stages when one of them failed.
AutoRollback bool `json:"autoRollback"`
Expand Down