diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index 23e5ab5..68ac6bf 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: common description: "Bedag's common Helm chart to use for creating other Helm charts" -version: 12.10.0 +version: 12.11.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 @@ -27,6 +27,11 @@ annotations: artifacthub.io/prerelease: "false" artifacthub.io/license: Apache-2.0 artifacthub.io/changes: | + - kind: added + description: Added annotations field to components..controller and components..services. to set metadata.annotations on the generated Job/CronJob/Deployment/StatefulSet/Service resource itself (e.g. for helm.sh/hook* annotations), distinct from the Pod-template-scoped extraAnnotations + links: + - name: GitHub Issue + url: https://github.com/bedag/helm-charts/issues/189 - kind: added description: Added components..services..ports list to allow defining multiple ports on a single Service (e.g. for a StatefulSet's governing/headless service) links: diff --git a/charts/common/README.md b/charts/common/README.md index fde61f0..b0e4fea 100644 --- a/charts/common/README.md +++ b/charts/common/README.md @@ -1,6 +1,6 @@ # common -![Version: 12.10.0](https://img.shields.io/badge/Version-12.10.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) +![Version: 12.11.0](https://img.shields.io/badge/Version-12.11.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 diff --git a/charts/common/ci/values.test.yaml b/charts/common/ci/values.test.yaml index 7e2e104..5c258e7 100644 --- a/charts/common/ci/values.test.yaml +++ b/charts/common/ci/values.test.yaml @@ -57,6 +57,8 @@ components: loadBalancerClass: test loadBalancerSourceRanges: - 10.0.0.0/8 + annotations: + example.com/owner: platform-team # end common.service # start common.networkpolicy networkpolicies: @@ -80,6 +82,8 @@ components: controller: deploy: true type: "Deployment" + annotations: + example.com/owner: platform-team hostAliases: - ip: "127.0.0.1" hostnames: @@ -304,6 +308,10 @@ components: ttlSecondsAfterFinished: 0 automountServiceAccountToken: false restartPolicy: "Never" + annotations: + helm.sh/hook: test + helm.sh/hook-weight: "-5" + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded,hook-failed # podSecurityContext holds pod-level security attributes and common container settings. # Some fields are also present in container.securityContext. Field values of containerSecurityContext take precedence over field values of podSecurityContext. diff --git a/charts/common/templates/_cronjob.yaml b/charts/common/templates/_cronjob.yaml index 2e2e30e..7de5409 100644 --- a/charts/common/templates/_cronjob.yaml +++ b/charts/common/templates/_cronjob.yaml @@ -13,6 +13,7 @@ metadata: labels: {{ include "library.labels.standard" $root | indent 4 }} app.kubernetes.io/component: {{ $name }} + {{- include "library.annotations" (dict "map" $cronjob.annotations "ctx" $root) | nindent 2 }} spec: schedule: {{ $cronjob.schedule | default "* * * * *" | quote }} {{- if $cronjob.concurrencyPolicy }} diff --git a/charts/common/templates/_deployment.yaml b/charts/common/templates/_deployment.yaml index 24de138..cb83d3f 100644 --- a/charts/common/templates/_deployment.yaml +++ b/charts/common/templates/_deployment.yaml @@ -13,6 +13,7 @@ metadata: labels: {{ include "library.labels.standard" $root | indent 4 }} app.kubernetes.io/component: {{ $name }} + {{- include "library.annotations" (dict "map" $deployment.annotations "ctx" $root) | nindent 2 }} spec: replicas: {{ if kindIs "float64" $deployment.replicas }}{{ $deployment.replicas }}{{ else }}{{ 1 }}{{ end }} revisionHistoryLimit: {{ $deployment.revisionHistoryLimit | default 3 }} diff --git a/charts/common/templates/_job.yaml b/charts/common/templates/_job.yaml index 29f8d9d..89af9c5 100644 --- a/charts/common/templates/_job.yaml +++ b/charts/common/templates/_job.yaml @@ -13,6 +13,7 @@ metadata: labels: {{ include "library.labels.standard" $root | indent 4 }} app.kubernetes.io/component: {{ $name }} + {{- include "library.annotations" (dict "map" $job.annotations "ctx" $root) | nindent 2 }} spec: {{- include "common.jobspec" (dict "root" $root "job" $job "name" $name) | indent 2 }} {{- end }} diff --git a/charts/common/templates/_service.yaml b/charts/common/templates/_service.yaml index 005187b..754f618 100644 --- a/charts/common/templates/_service.yaml +++ b/charts/common/templates/_service.yaml @@ -12,6 +12,7 @@ metadata: labels: {{ include "library.labels.standard" $root | indent 4 }} app.kubernetes.io/component: {{ $componentname }} + {{- include "library.annotations" (dict "map" $service.annotations "ctx" $root) | nindent 2 }} spec: type: {{ $service.type | default "ClusterIP" }} {{- if eq $service.type "LoadBalancer" }} diff --git a/charts/common/templates/_statefulset.yaml b/charts/common/templates/_statefulset.yaml index da7b413..6b86e8b 100644 --- a/charts/common/templates/_statefulset.yaml +++ b/charts/common/templates/_statefulset.yaml @@ -13,6 +13,7 @@ metadata: labels: {{ include "library.labels.standard" $root | indent 4 }} app.kubernetes.io/component: {{ $name }} + {{- include "library.annotations" (dict "map" $statefulset.annotations "ctx" $root) | nindent 2 }} spec: replicas: {{ $statefulset.replicas | default 1 }} revisionHistoryLimit: {{ $statefulset.revisionHistoryLimit | default 3 }} diff --git a/charts/common/templates/helpers/_labels.tpl b/charts/common/templates/helpers/_labels.tpl index 7eaf7d1..d9662d3 100644 --- a/charts/common/templates/helpers/_labels.tpl +++ b/charts/common/templates/helpers/_labels.tpl @@ -10,6 +10,21 @@ where the value can be templated with the given context {{- end -}} {{- end -}} +{{- /* +library.annotations renders a metadata "annotations:" block for a given +map of annotations, with each value templated via "library.mapify" (i.e. +"tpl" against the given context). It is meant to be included directly +under a resource's own "metadata:" block, e.g. to set resource-level +annotations such as "helm.sh/hook", as opposed to annotations set on a +Pod template (see e.g. controller.extraAnnotations). +*/ -}} +{{- define "library.annotations" -}} + {{- if $.map }} +annotations: + {{- include "library.mapify" (dict "map" $.map "ctx" $.ctx) | nindent 2 }} + {{- end }} +{{- end -}} + {{- /* library.labels.standard prints the standard Helm labels. The standard labels are frequently used in metadata. diff --git a/charts/common/values.schema.json b/charts/common/values.schema.json index ae052bb..b61daef 100644 --- a/charts/common/values.schema.json +++ b/charts/common/values.schema.json @@ -825,6 +825,9 @@ "deploy": { "type": "boolean", "default": false + }, + "annotations": { + "type": "object" } } } @@ -883,6 +886,9 @@ "extraAnnotations": { "type": "object" }, + "annotations": { + "type": "object" + }, "extraLabels": { "type": "object" }, diff --git a/charts/common/values.yaml b/charts/common/values.yaml index fd2e865..a1a83e7 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -265,6 +265,9 @@ components: # port: 9300 # targetPort: 9300 # protocol: TCP + # annotations is optional and sets annotations on the Service's own metadata.annotations + # annotations: + # foo: bar # end common.service # start common.networkpolicy # networkpolicy allows access from outside of the namespace or from other pods @@ -338,12 +341,23 @@ components: # Extra annotations on all Pods # We use this for example to set the prometheus annotations. + # Note: this sets annotations on the Pod template (spec.template.metadata.annotations), + # NOT on this resource itself. See "annotations" below for resource-level annotations. extraAnnotations: {} # foo: bar # prometheus.io/path: /metrics # prometheus.io/port: "8080" # prometheus.io/scrape: "true" + # annotations sets annotations on the generated resource itself + # (Job/CronJob/Deployment/StatefulSet metadata.annotations), as opposed to + # extraAnnotations above which sets annotations on the Pod template. This is + # used e.g. to control Helm's execution order/hooks for a Job: + annotations: {} + # helm.sh/hook: test + # helm.sh/hook-weight: "-5" + # helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded,hook-failed + # Extra labels on all Pods extraLabels: {} # foo: bar