Skip to content

Commit 62d0254

Browse files
committed
add support for post_kustomize to modify deployments
1 parent 635abf3 commit 62d0254

File tree

7 files changed

+50
-9
lines changed

7 files changed

+50
-9
lines changed

.Dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Dockerfile
1+
Dockerfile

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v0.1.27
4+
5+
- add `post_kustomize` support
6+
- add kustomize binary v3.8.7
7+
38
## v0.1.26
49

510
- update helm to v3.9.0

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ FROM busybox:glibc
2828

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

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

36+
ADD ./kustomize /kustomize
37+
3538
RUN mkdir /root/.kube
3639

3740
CMD /usr/local/bin/drone-helm3

internal/helm/helm.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"os"
78
"strings"
89
"time"
910

@@ -138,6 +139,23 @@ func WithDisableOpenAPIValidation(disable bool) HelmOption {
138139
}
139140
}
140141

142+
func WithPostKustomization(kustomization string) HelmOption {
143+
return func(c *HelmCmd) error {
144+
if kustomization != "" {
145+
f, err := os.OpenFile("/kustomize/kustomization.yaml", os.O_APPEND|os.O_WRONLY, 0600)
146+
if err != nil {
147+
return fmt.Errorf("unable to create kustomization file: %w", err)
148+
}
149+
_, err = f.WriteString(kustomization)
150+
if err != nil {
151+
return fmt.Errorf("unable to write to kustomization file: %w", err)
152+
}
153+
c.Args = append(c.Args, "--post-renderer", "/kustomize/kustomize.sh")
154+
}
155+
return nil
156+
}
157+
}
158+
141159
func WithTimeout(timeout time.Duration) HelmOption {
142160
return func(c *HelmCmd) error {
143161
c.Args = append(c.Args, "--timeout", timeout.String())

kustomize/kustomization.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
resources:
4+
- all.yaml
5+
6+
# plugin configuration gets injected here:
7+

kustomize/kustomize.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
umask 077
4+
cat > /kustomize/all.yaml
5+
kustomize build /kustomize
6+
rm /kustomize/all.yaml

main.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ type (
3535
Release string `envconfig:"RELEASE" required:"true"` // helm release name
3636
Namespace string `envconfig:"NAMESPACE" required:"true"` // kubernets and helm namespace
3737

38-
Lint bool `envconfig:"LINT" default:"true"` // helm lint option
39-
Atomic bool `envconfig:"ATOMIC" default:"true"` // helm atomic option
40-
Wait bool `envconfig:"WAIT" default:"true"` // helm wait option
41-
Force bool `envconfig:"FORCE" default:"false"` // helm force option
42-
Cleanup bool `envconfig:"CLEANUP_ON_FAIL" default:"false"` // helm cleanup option
43-
DryRun bool `envconfig:"DRY_RUN" default:"false"` // helm dryrun option
44-
HelmDebug bool `envconfig:"HELM_DEBUG" default:"true"` // helm debug option
45-
DisableOpenAPIValidation bool `envconfig:"DISABLE_OPENAPI_VALIDATION" default:"false"` // helm openapivalidation option
38+
Lint bool `envconfig:"LINT" default:"true"` // helm lint option
39+
Atomic bool `envconfig:"ATOMIC" default:"true"` // helm atomic option
40+
Wait bool `envconfig:"WAIT" default:"true"` // helm wait option
41+
Force bool `envconfig:"FORCE" default:"false"` // helm force option
42+
Cleanup bool `envconfig:"CLEANUP_ON_FAIL" default:"false"` // helm cleanup option
43+
DryRun bool `envconfig:"DRY_RUN" default:"false"` // helm dryrun option
44+
HelmDebug bool `envconfig:"HELM_DEBUG" default:"true"` // helm debug option
45+
DisableOpenAPIValidation bool `envconfig:"DISABLE_OPENAPI_VALIDATION" default:"false"` // helm openapivalidation option
46+
PostKustomization string `envconfig:"POST_KUSTOMIZATION" default:""` // runs a customization of the generated output
4647

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

176178
helm.WithHelmRepos(cfg.HelmRepos),
177179
helm.WithBuildDependencies(cfg.BuildDependencies, cfg.Chart),

0 commit comments

Comments
 (0)