helm-charts icon indicating copy to clipboard operation
helm-charts copied to clipboard

add commonLabels and commonAnnotations

Open ecthelion77 opened this issue 4 years ago • 1 comments

Preflight Checklist

  • [X] I agree to follow the Code of Conduct that this project adheres to.
  • [X] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Problem Description

No possibilities to define labels and annotation for resources in chart.

Proposed Solution

Best practice for helm chart development consists to add following metadata definitions on each template :

  labels:
    app.kubernetes.io/name: {{ template "dex.name" . }}
    helm.sh/chart: {{ template "dex.chart" . }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  annotations:
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}

and following block in templates :

{{/* vim: set filetype=mustache: */}}
{{/*
Renders a value that contains template.
Usage:
{{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "common.tplvalues.render" -}}
    {{- if typeIs "string" .value }}
        {{- tpl .value .context }}
    {{- else }}
        {{- tpl (.value | toYaml) .context }}
    {{- end }}
{{- end -}}

(or integrate common helm chart from bitnami as dependency: https://artifacthub.io/packages/helm/bitnami/common)

Alternatives Considered

No response

Additional Information

No response

ecthelion77 avatar Nov 25 '21 08:11 ecthelion77

Pull request #67

ecthelion77 avatar Nov 25 '21 10:11 ecthelion77