helm rendering k8s resources like annotation or labels

 

I think the best way to handle annotations is to have the values files similiar to k8s API spec for example working with annotations data. Of course labels and annotations have different purposes.

What i am saying is the chart has to be close to k8s API spec to avoid confusion and duplication of charts - as someone might think service annotation does not exist but when it did, then it breaks your k8s deployment - not helm chart rendering but right till the very end - sometimes deployment does happen but the yaml looks corrupted and obviously your deployment will not work.

For example, if we needed annotation for a service, best to keep it like this on the template. And then the value files is given below:-

{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "simple.serviceAccountName" . }}
  labels:
    {{- include "simple.labels" . | nindent 4 }}
  {{- if .Values.serviceAccount.annotations }}
  {{- with .Values.serviceAccount.annotations }}
  annotations:
      {{- toYaml . | nindent 4 }}
  {{- end }}
  {{- if .Values.serviceAccount.onfeature }}
    nginx.org/proxy-exp-timeout: "30s"
  {{- end}}
  {{ else }}
  {{- if .Values.serviceAccount.onfeature }}
  annotations:
    nginx.org/proxy-exp-timeout: "30s"
  {{- end}}
  {{- end}}
{{- end }}


value files. 


serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
    #nginx.org/proxy-connect-timeout: "30s"
  onfeature: true
  # onFeature - toggle true or false to render annotation
  # If not set and create is true, a name is generated using the fullname template
  name: ""

Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm