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

feat: templatize values #112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion examples/app/templates/cron-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ spec:
name: hello
resources: {}
restartPolicy: OnFailure
schedule: {{ .Values.cronJob.schedule | quote }}
schedule: {{ tpl (.Values.cronJob.schedule) $ | quote }}
6 changes: 3 additions & 3 deletions examples/app/templates/my-config-props.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
{{- include "app.labels" . | nindent 4 }}
data:
my.prop1: {{ .Values.myConfigProps.myProp1 | quote }}
my.prop2: {{ .Values.myConfigProps.myProp2 | quote }}
my.prop3: {{ .Values.myConfigProps.myProp3 | quote }}
my.prop1: {{ tpl (.Values.myConfigProps.myProp1) $ | quote }}
my.prop2: {{ tpl (.Values.myConfigProps.myProp2) $ | quote }}
my.prop3: {{ tpl (.Values.myConfigProps.myProp3) $ | quote }}
myval.yaml: {{ .Values.myConfigProps.myvalYaml | toYaml | indent 1 }}
6 changes: 3 additions & 3 deletions examples/app/templates/my-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
{{- include "app.labels" . | nindent 4 }}
immutable: true
data:
dummyconfigmapkey: {{ .Values.myConfig.dummyconfigmapkey | quote }}
dummyconfigmapkey: {{ tpl (.Values.myConfig.dummyconfigmapkey) $ | quote }}
my_config.properties: |
health.healthProbeBindAddress={{ .Values.myConfig.myConfigProperties.health.healthProbeBindAddress | quote }}
metrics.bindAddress={{ .Values.myConfig.myConfigProperties.metrics.bindAddress | quote }}
health.healthProbeBindAddress={{ tpl (.Values.myConfig.myConfigProperties.health.healthProbeBindAddress) $ | quote }}
metrics.bindAddress={{ tpl (.Values.myConfig.myConfigProperties.metrics.bindAddress) $ | quote }}
6 changes: 3 additions & 3 deletions examples/app/templates/my-sample-pv-claim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
- ReadWriteOnce
resources:
limits:
storage: {{ .Values.pvc.mySamplePvClaim.storageLimit | quote }}
storage: {{ tpl (.Values.pvc.mySamplePvClaim.storageLimit) $ | quote }}
requests:
storage: {{ .Values.pvc.mySamplePvClaim.storageRequest | quote }}
storageClassName: {{ .Values.pvc.mySamplePvClaim.storageClass | quote }}
storage: {{ tpl (.Values.pvc.mySamplePvClaim.storageRequest) $ | quote }}
storageClassName: {{ tpl (.Values.pvc.mySamplePvClaim.storageClass) $ | quote }}
4 changes: 2 additions & 2 deletions examples/app/templates/my-secret-ca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ metadata:
labels:
{{- include "app.labels" . | nindent 4 }}
data:
ca.crt: {{ required "mySecretCa.caCrt is required" .Values.mySecretCa.caCrt | b64enc
| quote }}
ca.crt: {{ tpl (required "mySecretCa.caCrt is required" .Values.mySecretCa.caCrt)
$ | b64enc | quote }}
type: opaque
14 changes: 7 additions & 7 deletions examples/app/templates/my-secret-vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ metadata:
labels:
{{- include "app.labels" . | nindent 4 }}
data:
ELASTIC_FOOBAR_HUNTER123_MEOWTOWN_VERIFY: {{ required "mySecretVars.elasticFoobarHunter123MeowtownVerify is required" .Values.mySecretVars.elasticFoobarHunter123MeowtownVerify | b64enc
| quote }}
VAR1: {{ required "mySecretVars.var1 is required" .Values.mySecretVars.var1 | b64enc
| quote }}
VAR2: {{ required "mySecretVars.var2 is required" .Values.mySecretVars.var2 | b64enc
ELASTIC_FOOBAR_HUNTER123_MEOWTOWN_VERIFY: {{ tpl (required "mySecretVars.elasticFoobarHunter123MeowtownVerify is required" .Values.mySecretVars.elasticFoobarHunter123MeowtownVerify) $ | b64enc
| quote }}
VAR1: {{ tpl (required "mySecretVars.var1 is required" .Values.mySecretVars.var1)
$ | b64enc | quote }}
VAR2: {{ tpl (required "mySecretVars.var2 is required" .Values.mySecretVars.var2)
$ | b64enc | quote }}
stringData:
str: {{ required "mySecretVars.str is required" .Values.mySecretVars.str | quote
}}
str: {{ tpl (required "mySecretVars.str is required" .Values.mySecretVars.str)
$ | quote }}
type: opaque
2 changes: 1 addition & 1 deletion examples/operator/templates/configmap-vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ metadata:
labels:
{{- include "operator.labels" . | nindent 4 }}
data:
VAR4: {{ .Values.configmapVars.var4 | quote }}
VAR4: {{ tpl (.Values.configmapVars.var4) $ | quote }}
2 changes: 1 addition & 1 deletion examples/operator/templates/manager-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ metadata:
data:
controller_manager_config.yaml: {{ .Values.managerConfig.controllerManagerConfigYaml
| toYaml | indent 1 }}
dummyconfigmapkey: {{ .Values.managerConfig.dummyconfigmapkey | quote }}
dummyconfigmapkey: {{ tpl (.Values.managerConfig.dummyconfigmapkey) $ | quote }}
4 changes: 2 additions & 2 deletions examples/operator/templates/pvc-lim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.pvc.pvcLim.storageRequest | quote }}
storageClassName: {{ .Values.pvc.pvcLim.storageClass | quote }}
storage: {{ tpl (.Values.pvc.pvcLim.storageRequest) $ | quote }}
storageClassName: {{ tpl (.Values.pvc.pvcLim.storageClass) $ | quote }}
4 changes: 2 additions & 2 deletions examples/operator/templates/secret-ca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ metadata:
labels:
{{- include "operator.labels" . | nindent 4 }}
data:
ca.crt: {{ required "secretCa.caCrt is required" .Values.secretCa.caCrt | b64enc
| quote }}
ca.crt: {{ tpl (required "secretCa.caCrt is required" .Values.secretCa.caCrt) $
| b64enc | quote }}
type: opaque
4 changes: 2 additions & 2 deletions examples/operator/templates/secret-registry-credentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ metadata:
labels:
{{- include "operator.labels" . | nindent 4 }}
data:
.dockerconfigjson: {{ required "secretRegistryCredentials.dockerconfigjson is required"
.Values.secretRegistryCredentials.dockerconfigjson | b64enc | quote }}
.dockerconfigjson: {{ tpl (required "secretRegistryCredentials.dockerconfigjson is required" .Values.secretRegistryCredentials.dockerconfigjson) $ | b64enc |
quote }}
type: kubernetes.io/dockerconfigjson
8 changes: 4 additions & 4 deletions examples/operator/templates/secret-vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ metadata:
labels:
{{- include "operator.labels" . | nindent 4 }}
data:
VAR1: {{ required "secretVars.var1 is required" .Values.secretVars.var1 | b64enc
| quote }}
VAR2: {{ required "secretVars.var2 is required" .Values.secretVars.var2 | b64enc
| quote }}
VAR1: {{ tpl (required "secretVars.var1 is required" .Values.secretVars.var1) $
| b64enc | quote }}
VAR2: {{ tpl (required "secretVars.var2 is required" .Values.secretVars.var2) $
| b64enc | quote }}
type: opaque
4 changes: 2 additions & 2 deletions pkg/helmify/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (v *Values) Add(value interface{}, name ...string) (string, error) {
}
_, isString := value.(string)
if isString {
return "{{ .Values." + strings.Join(name, ".") + " | quote }}", nil
return "{{ tpl (.Values." + strings.Join(name, ".") + ") $ | quote }}", nil
}
_, isSlice := value.([]interface{})
if isSlice {
Expand Down Expand Up @@ -78,7 +78,7 @@ func (v *Values) AddSecret(toBase64 bool, name ...string) (string, error) {
if err != nil {
return "", errors.Wrapf(err, "unable to set value: %v", nameStr)
}
res := fmt.Sprintf(`{{ required "%[1]s is required" .Values.%[1]s`, nameStr)
res := fmt.Sprintf(`{{ tpl (required "%[1]s is required" .Values.%[1]s) $`, nameStr)
if toBase64 {
res += " | b64enc"
}
Expand Down