Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ testbin/*
dist/

vendor/

# Binary
helmify
4 changes: 3 additions & 1 deletion pkg/processor/rbac/clusterrolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func (r clusterRoleBinding) Process(appMeta helmify.AppMetadata, obj *unstructur
}

for i, s := range rb.Subjects {
s.Namespace = "{{ .Release.Namespace }}"
if !(appMeta.Config().PreserveNs && s.Namespace != "") {
s.Namespace = "{{ .Release.Namespace }}"
}
s.Name = fmt.Sprintf("{{ include \"%s.serviceAccountName\" . }}", appMeta.ChartName())
rb.Subjects[i] = s
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/processor/rbac/rolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func (r roleBinding) Process(appMeta helmify.AppMetadata, obj *unstructured.Unst
}

for i, s := range rb.Subjects {
s.Namespace = "{{ .Release.Namespace }}"
if !(appMeta.Config().PreserveNs && s.Namespace != "") {
s.Namespace = "{{ .Release.Namespace }}"
}
s.Name = fmt.Sprintf("{{ include \"%s.serviceAccountName\" . }}", appMeta.ChartName())
rb.Subjects[i] = s
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/processor/rbac/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ metadata:
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
%[2]s
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}`
)
Expand Down Expand Up @@ -56,7 +57,12 @@ func (sa serviceAccount) Process(appMeta helmify.AppMetadata, obj *unstructured.
return true, nil, err
}
tmpl := saTempl
meta := fmt.Sprintf(tmpl, appMeta.ChartName())
namespace := ""
if obj.GetNamespace() != "" && appMeta.Config().PreserveNs {
namespace = fmt.Sprintf("namespace: %s", obj.GetNamespace())
}

meta := fmt.Sprintf(tmpl, appMeta.ChartName(), namespace)

return true, &saResult{
data: []byte(meta),
Expand Down
39 changes: 16 additions & 23 deletions pkg/processor/webhook/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/arttor/helmify/pkg/cluster"
"github.com/arttor/helmify/pkg/helmify"
"github.com/arttor/helmify/pkg/processor"
yamlformat "github.com/arttor/helmify/pkg/yaml"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -17,25 +18,6 @@ import (
const (
WebhookHeader = `{{- if .Values.webhook.enabled }}`
WebhookFooter = `{{- end }}`
certTempl = `apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: {{ include "%[1]s.fullname" . }}-%[2]s
labels:
{{- include "%[1]s.labels" . | nindent 4 }}
spec:
%[3]s`
certTemplWithAnno = `apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: {{ include "%[1]s.fullname" . }}-%[2]s
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "2"
labels:
{{- include "%[1]s.labels" . | nindent 4 }}
spec:
%[3]s`
)

var certGVC = schema.GroupVersionKind{
Expand Down Expand Up @@ -89,19 +71,30 @@ func (c cert) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructure
spec = yamlformat.Indent(spec, 2)
spec = bytes.TrimRight(spec, "\n ")
tmpl := ""

if appMeta.Config().CertManagerAsSubchart {
tmpl = certTemplWithAnno
} else {
tmpl = certTempl
annotations := obj.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}
annotations["helm.sh/hook"] = "post-install,post-upgrade"
annotations["helm.sh/hook-weight"] = "2"
obj.SetAnnotations(annotations)
}

tmpl, err = processor.ProcessObjMeta(appMeta, obj)
if err != nil {
return true, nil, err
}

values := helmify.Values{}
if appMeta.Config().AddWebhookOption {
// Add webhook.enabled value to values.yaml
_, _ = values.Add(true, "webhook", "enabled")

tmpl = fmt.Sprintf("%s\n%s\n%s", WebhookHeader, tmpl, WebhookFooter)
}
res := fmt.Sprintf(tmpl, appMeta.ChartName(), name, string(spec))
res := tmpl + "\nspec:\n" + string(spec)
return true, &certResult{
name: name,
data: []byte(res),
Expand Down
39 changes: 13 additions & 26 deletions pkg/processor/webhook/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,13 @@ import (
"io"

"github.com/arttor/helmify/pkg/helmify"
"github.com/arttor/helmify/pkg/processor"
yamlformat "github.com/arttor/helmify/pkg/yaml"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/yaml"
)

const (
issuerTempl = `apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: {{ include "%[1]s.fullname" . }}-%[2]s
labels:
{{- include "%[1]s.labels" . | nindent 4 }}
spec:
%[3]s`
issuerTemplWithAnno = `apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: {{ include "%[1]s.fullname" . }}-%[2]s
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "1"
labels:
{{- include "%[1]s.labels" . | nindent 4 }}
spec:
%[3]s`
)

var issuerGVC = schema.GroupVersionKind{
Group: "cert-manager.io",
Version: "v1",
Expand All @@ -59,9 +38,17 @@ func (i issuer) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructu
spec = bytes.TrimRight(spec, "\n ")
tmpl := ""
if appMeta.Config().CertManagerAsSubchart {
tmpl = issuerTemplWithAnno
} else {
tmpl = issuerTempl
annotations := obj.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}
annotations["helm.sh/hook"] = "post-install,post-upgrade"
annotations["helm.sh/hook-weight"] = "1"
obj.SetAnnotations(annotations)
}
tmpl, err := processor.ProcessObjMeta(appMeta, obj)
if err != nil {
return true, nil, err
}
values := helmify.Values{}
if appMeta.Config().AddWebhookOption {
Expand All @@ -70,7 +57,7 @@ func (i issuer) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructu

tmpl = fmt.Sprintf("%s\n%s\n%s", WebhookHeader, tmpl, WebhookFooter)
}
res := fmt.Sprintf(tmpl, appMeta.ChartName(), name, string(spec))
res := tmpl + "\nspec:\n" + string(spec)
return true, &issResult{
name: name,
data: []byte(res),
Expand Down