Skip to content

Commit

Permalink
add 'labels' to the Helm chart to simplify the declaration of labels
Browse files Browse the repository at this point in the history
  • Loading branch information
sbilque committed May 28, 2024
1 parent 56df327 commit e4cabc7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .helm/starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ AWX:
| Value | Description | Default |
|---|---|---|
| `AWX.enabled` | Enable this AWX resource configuration | `false` |
| `AWX.labels` | Set AWX resource labels | - |
| `AWX.name` | The name of the AWX resource and default prefix for other resources | `"awx"` |
| `AWX.spec` | specs to directly configure the AWX resource | `{}` |
| `AWX.postgres` | configurations for the external postgres secret | - |
Expand Down
10 changes: 10 additions & 0 deletions .helm/starter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ Generate the name of the postgres secret, expects AWX context passed in
{{- define "postgres.secretName" -}}
{{ default (printf "%s-postgres-configuration" .Values.AWX.name) .Values.AWX.postgres.secretName }}
{{- end }}
{{/*
Generate liste of labels
*/}}
{{- define "awx.labels" }}
{{- if hasKey .Values.AWX "labels" -}}
{{- range $key, $value := .Values.AWX.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end -}}
{{- end }}
5 changes: 5 additions & 0 deletions .helm/starter/templates/awx-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ kind: AWX
metadata:
name: {{ .name }}
namespace: {{ $.Release.Namespace }}
{{- /* Provide labels if present */}}
{{- if hasKey . "labels" }}
labels:
{{- include "awx.labels" . | indent 4 }}
{{- end }}
spec:
{{- /* Provide custom persistent volumes configs if enabled */}}
{{- include "spec.storageClassNames" $ }}
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts
for file in $${cluster_scoped_files}; do\
$(YQ) -i '.metadata.name += "-{{ .Release.Name }}"' $${file};\
done
# Add labels to all deployment resources
for file in charts/$(CHART_NAME)/raw-files/deployment*.yaml; do\
$(YQ) -i '.metadata.labels += { "INCLUDE_ANCHOR": "INCLUDE_INDENT_4"}' $${file};\
$(YQ) -i '.spec.template.metadata.labels += { "INCLUDE_ANCHOR": "INCLUDE_INDENT_8"}' $${file};\
$(SED_I) 's/INCLUDE_ANCHOR: INCLUDE_INDENT_4/{{- include ""awx.labels"" . | indent 4 }}/g' $${file};\
$(SED_I) 's/INCLUDE_ANCHOR: INCLUDE_INDENT_8/{{- include ""awx.labels"" . | indent 8 }}/g' $${file};\
done

# Correct the reference for the clusterrolebinding
$(YQ) -i '.roleRef.name += "-{{ .Release.Name }}"' 'charts/$(CHART_NAME)/raw-files/clusterrolebinding-awx-operator-proxy-rolebinding.yaml'
Expand Down

0 comments on commit e4cabc7

Please sign in to comment.