Skip to content

Commit

Permalink
add support for post_kustomize to modify deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
foosinn committed Jul 11, 2022
1 parent 635abf3 commit 62d0254
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .Dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Dockerfile
Dockerfile
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.1.27

- add `post_kustomize` support
- add kustomize binary v3.8.7

## v0.1.26

- update helm to v3.9.0
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ FROM busybox:glibc

COPY --from=downloader /usr/local/bin/helm /usr/local/bin/helm
COPY --from=downloader /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=k8s.gcr.io/kustomize/kustomize:v3.8.7 /app/kustomize /usr/local/bin/kustomize

COPY --from=builder /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /tmp/build/drone-helm3 /usr/local/bin/drone-helm3

ADD ./kustomize /kustomize

RUN mkdir /root/.kube

CMD /usr/local/bin/drone-helm3
18 changes: 18 additions & 0 deletions internal/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"os"
"strings"
"time"

Expand Down Expand Up @@ -138,6 +139,23 @@ func WithDisableOpenAPIValidation(disable bool) HelmOption {
}
}

func WithPostKustomization(kustomization string) HelmOption {
return func(c *HelmCmd) error {
if kustomization != "" {
f, err := os.OpenFile("/kustomize/kustomization.yaml", os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
return fmt.Errorf("unable to create kustomization file: %w", err)
}
_, err = f.WriteString(kustomization)
if err != nil {
return fmt.Errorf("unable to write to kustomization file: %w", err)
}
c.Args = append(c.Args, "--post-renderer", "/kustomize/kustomize.sh")
}
return nil
}
}

func WithTimeout(timeout time.Duration) HelmOption {
return func(c *HelmCmd) error {
c.Args = append(c.Args, "--timeout", timeout.String())
Expand Down
7 changes: 7 additions & 0 deletions kustomize/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

resources:
- all.yaml

# plugin configuration gets injected here:

6 changes: 6 additions & 0 deletions kustomize/kustomize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

umask 077
cat > /kustomize/all.yaml
kustomize build /kustomize
rm /kustomize/all.yaml
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ type (
Release string `envconfig:"RELEASE" required:"true"` // helm release name
Namespace string `envconfig:"NAMESPACE" required:"true"` // kubernets and helm namespace

Lint bool `envconfig:"LINT" default:"true"` // helm lint option
Atomic bool `envconfig:"ATOMIC" default:"true"` // helm atomic option
Wait bool `envconfig:"WAIT" default:"true"` // helm wait option
Force bool `envconfig:"FORCE" default:"false"` // helm force option
Cleanup bool `envconfig:"CLEANUP_ON_FAIL" default:"false"` // helm cleanup option
DryRun bool `envconfig:"DRY_RUN" default:"false"` // helm dryrun option
HelmDebug bool `envconfig:"HELM_DEBUG" default:"true"` // helm debug option
DisableOpenAPIValidation bool `envconfig:"DISABLE_OPENAPI_VALIDATION" default:"false"` // helm openapivalidation option
Lint bool `envconfig:"LINT" default:"true"` // helm lint option
Atomic bool `envconfig:"ATOMIC" default:"true"` // helm atomic option
Wait bool `envconfig:"WAIT" default:"true"` // helm wait option
Force bool `envconfig:"FORCE" default:"false"` // helm force option
Cleanup bool `envconfig:"CLEANUP_ON_FAIL" default:"false"` // helm cleanup option
DryRun bool `envconfig:"DRY_RUN" default:"false"` // helm dryrun option
HelmDebug bool `envconfig:"HELM_DEBUG" default:"true"` // helm debug option
DisableOpenAPIValidation bool `envconfig:"DISABLE_OPENAPI_VALIDATION" default:"false"` // helm openapivalidation option
PostKustomization string `envconfig:"POST_KUSTOMIZATION" default:""` // runs a customization of the generated output

HelmRepos []string `envconfig:"HELM_REPOS"` // additonal helm repos
BuildDependencies bool `envconfig:"BUILD_DEPENDENCIES" default:"true"` // helm dependency build option
Expand Down Expand Up @@ -172,6 +173,7 @@ func main() {
helm.WithDryRun(cfg.DryRun),
helm.WithDebug(cfg.HelmDebug),
helm.WithDisableOpenAPIValidation(cfg.DisableOpenAPIValidation),
helm.WithPostKustomization(cfg.PostKustomization),

helm.WithHelmRepos(cfg.HelmRepos),
helm.WithBuildDependencies(cfg.BuildDependencies, cfg.Chart),
Expand Down

0 comments on commit 62d0254

Please sign in to comment.