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

[common]: add tpl for labels and annotations #116

Merged
merged 1 commit into from
Sep 20, 2023
Merged
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
4 changes: 2 additions & 2 deletions charts/common/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: common
description: "Bedag's common Helm chart to use for creating other Helm charts"
version: 10.6.2
version: 10.7.0
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
Expand All @@ -27,4 +27,4 @@ annotations:
artifacthub.io/prerelease: "false"
artifacthub.io/license: Apache-2.0
artifacthub.io/changes: |
- "[Added]: support for envFrom"
- "[Changed]: extra annotations and labesl support sprig statements"
2 changes: 1 addition & 1 deletion charts/common/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# common

![Version: 10.6.2](https://img.shields.io/badge/Version-10.6.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![Version: 10.7.0](https://img.shields.io/badge/Version-10.7.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

Bedag's common Helm chart to use for creating other Helm charts

Expand Down
8 changes: 2 additions & 6 deletions charts/common/templates/_cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ spec:
labels:
{{ include "library.labels.stable" $root | indent 8 }}
app.kubernetes.io/component: {{ $name }}
{{- range $key, $value := $cronjob.extraLabels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "library.mapify" (dict "map" $cronjob.extraLabels "ctx" $root) | nindent 8 }}
{{- if $cronjob.gatherMetrics }}
gatherMetrics: "enabled"
{{- end }}
annotations:
{{- range $key, $value := $cronjob.extraAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "library.mapify" (dict "map" $cronjob.extraAnnotations "ctx" $root) | nindent 8 }}
spec:
{{- include "common.jobspec" (dict "root" $root "job" $cronjob "name" $name) | indent 6 }}
{{- end }}
Expand Down
8 changes: 2 additions & 6 deletions charts/common/templates/_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ spec:
labels:
{{ include "library.labels.stable" $root | indent 8 }}
app.kubernetes.io/component: {{ $name }}
{{- range $key, $value := $deployment.extraLabels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "library.mapify" (dict "map" $deployment.extraLabels "ctx" $root) | nindent 8 }}
{{- if $deployment.gatherMetrics }}
gatherMetrics: "enabled"
{{- end }}
Expand All @@ -51,9 +49,7 @@ spec:
# and thus re-pull the image even if the tag has not changed (if imagePullPolicy = Always)
timestamp: {{ now.Unix | quote }}
{{- end }}
{{- range $key, $value := $deployment.extraAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "library.mapify" (dict "map" $deployment.extraAnnotations "ctx" $root) | nindent 8 }}
{{- range $deployment.extraChecksumAnnotations }}
{{ .key }}: {{ include (print $.Template.BasePath .checksumFrom) $root | sha256sum }}
{{- end }}
Expand Down
8 changes: 2 additions & 6 deletions charts/common/templates/_statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ spec:
labels:
{{ include "library.labels.stable" $root | indent 8 }}
app.kubernetes.io/component: {{ $name }}
{{- range $key, $value := $statefulset.extraLabels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "library.mapify" (dict "map" $statefulset.extraLabels "ctx" $root) | nindent 8 }}
{{- if $statefulset.gatherMetrics }}
gatherMetrics: "enabled"
{{- end }}
Expand All @@ -41,9 +39,7 @@ spec:
# and thus re-pull the image even if the tag has not changed (if imagePullPolicy = Always)
timestamp: {{ now.Unix | quote}}
{{- end }}
{{- range $key, $value := $statefulset.extraAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "library.mapify" (dict "map" $statefulset.extraAnnotations "ctx" $root) | nindent 8 }}
{{- range $statefulset.extraChecksumAnnotations }}
{{ .key }}: {{ include (print $.Template.BasePath .checksumFrom) $root | sha256sum }}
{{- end }}
Expand Down
17 changes: 8 additions & 9 deletions charts/common/templates/helpers/_labels.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{{- /*
library.labelize takes a dict or map and generates labels.
Values will be quoted. Keys will not.
Example output:
first: "Matt"
last: "Butcher"
library.mapify is used to generate annotations and labels
where the value can be templated with the given context
*/ -}}
{{- define "library.labelize" -}}
{{- range $k, $v := . }}
{{ $k }}: {{ $v | quote }}
{{- end -}}
{{- define "library.mapify" -}}
{{- if $.map -}}
{{- range $k, $v := $.map -}}
{{- $k | nindent 0 }}: {{ (tpl $v $.ctx) | quote }}
{{- end -}}
{{- end -}}
{{- end -}}

{{- /*
Expand Down
Loading