Skip to content

Commit

Permalink
Add ability to deploy Kubernetes application to the specified namespa…
Browse files Browse the repository at this point in the history
…ce (#213)

**What this PR does / why we need it**:

**Which issue(s) this PR fixes**:

Fixes #

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
-->
```release-note
NONE
```

This PR was merged by Kapetanios.
  • Loading branch information
nghialv committed Jun 26, 2020
1 parent 34fb1c7 commit e218d6e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
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

0 comments on commit e218d6e

Please sign in to comment.