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

Add 'labels' to the Helm chart to simplify the declaration of labels #1876

Open
wants to merge 7 commits into
base: devel
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
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 list 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
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts
git checkout -f config/.

@echo "== Build Templates and CRDS =="
# Add labels anchor to all deployment resources
for file in charts/$(CHART_NAME)/raw-files/deployment-*-controller-manager.yaml; do\
$(YQ) -i '.metadata.labels += { "INCLUDE_ANCHOR": "INCLUDE_INDENT_4"}' $${file};\
$(YQ) -i '.spec.template.metadata.labels += { "INCLUDE_ANCHOR": "INCLUDE_INDENT_8"}' $${file};\
done
# Delete metadata.namespace, release namespace will be automatically inserted by helm
for file in charts/$(CHART_NAME)/raw-files/*; do\
$(YQ) -i 'del(.metadata.namespace)' $${file};\
Expand All @@ -381,6 +386,11 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts
done
# Correct the reference for the clusterrolebinding
$(YQ) -i '.roleRef.name += "-{{ .Release.Name }}"' 'charts/$(CHART_NAME)/raw-files/clusterrolebinding-awx-operator-proxy-rolebinding.yaml'
# Corrects labels to all deployment resources
for file in charts/$(CHART_NAME)/raw-files/deployment-*-controller-manager.yaml; do\
$(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 .spec.replicas type for the controller-manager deployment
for file in charts/$(CHART_NAME)/raw-files/deployment-*-controller-manager.yaml; do\
$(SED_I) "s/'{{ (.Values.Operator).replicas | default 1 }}'/{{ (.Values.Operator).replicas | default 1 }}/g" $${file};\
Expand Down
Loading