From ad7ecb83fd71c3bf1ce49f6f0ad31809cd5b7a08 Mon Sep 17 00:00:00 2001 From: Vegard Hagen Date: Mon, 10 Apr 2023 21:14:07 +0200 Subject: [PATCH] feat(helm): Add labels and annotations to helm chart --- apps/arr/auth.yaml | 2 -- apps/arr/common-values.yaml | 2 ++ apps/arr/kustomization.yaml | 3 +++ apps/test/auth-values.yaml | 2 +- apps/test/kustomization.yaml | 17 +++-------------- helm/application/templates/_helpers.tpl | 19 +++++++++++++++++++ .../templates/application/deployment.yaml | 4 ++++ .../templates/application/service.yaml | 4 ++++ helm/application/templates/ingress-route.yaml | 2 +- .../traefik-forward-auth/config-map.yaml | 19 +++++++++++-------- .../traefik-forward-auth/deployment.yaml | 4 ++++ .../traefik-forward-auth/middleware.yaml | 4 ++++ .../traefik-forward-auth/service.yaml | 4 ++++ helm/application/values.yaml | 12 ++++++++---- 14 files changed, 68 insertions(+), 30 deletions(-) diff --git a/apps/arr/auth.yaml b/apps/arr/auth.yaml index f7ef582..9a9405b 100644 --- a/apps/arr/auth.yaml +++ b/apps/arr/auth.yaml @@ -16,9 +16,7 @@ spec: namespace: arr authOnly: true auth: - host: auth-arr cookieDomain: stonegarden.dev - cookieName: _arr_auth whitelist: - veghag@gmail.com destination: diff --git a/apps/arr/common-values.yaml b/apps/arr/common-values.yaml index b406e02..593fdbb 100644 --- a/apps/arr/common-values.yaml +++ b/apps/arr/common-values.yaml @@ -21,6 +21,8 @@ additionalVolumes: value: hostPath: path: /disk/data +additionalLabels: + app.kubernetes.io/part-of: arr auth: enabled: true create: false diff --git a/apps/arr/kustomization.yaml b/apps/arr/kustomization.yaml index dba2743..13be035 100644 --- a/apps/arr/kustomization.yaml +++ b/apps/arr/kustomization.yaml @@ -1,5 +1,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization +commonLabels: + app.kubernetes.io/part-of: arr + app.kubernetes.io/managed-by: argocd resources: - cm-common-env.yaml diff --git a/apps/test/auth-values.yaml b/apps/test/auth-values.yaml index 1db315c..ea51d63 100644 --- a/apps/test/auth-values.yaml +++ b/apps/test/auth-values.yaml @@ -2,7 +2,7 @@ name: auth namespace: test authOnly: true auth: - host: auth-test + cookieDomain: stonegarden.dev whitelist: - veghag@gmail.com - wiredmatrices@gmail.com diff --git a/apps/test/kustomization.yaml b/apps/test/kustomization.yaml index 3f686fc..8934948 100644 --- a/apps/test/kustomization.yaml +++ b/apps/test/kustomization.yaml @@ -1,21 +1,10 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization +commonLabels: + app.kubernetes.io/part-of: arr resources: - app1.yaml - app2.yaml - app3.yaml - - auth.yaml - -#helmGlobals: -# chartHome: ../../helm -# -#helmCharts: -# - name: application -# valuesFile: auth.yaml -# - name: application -# valuesFile: app1.yaml -# - name: application -# valuesFile: app2.yaml -# - name: application -# valuesFile: app3.yaml + - auth.yaml \ No newline at end of file diff --git a/helm/application/templates/_helpers.tpl b/helm/application/templates/_helpers.tpl index 92c2b9a..482b5eb 100644 --- a/helm/application/templates/_helpers.tpl +++ b/helm/application/templates/_helpers.tpl @@ -1,3 +1,22 @@ +{{/* +Common labels +*/}} +{{- define "common.labels" -}} +app.kubernetes.io/name: {{ .Values.name }} +{{- with .Values.additionalLabels }} +{{ toYaml . }} +{{- end }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "common.annotations" -}} +{{- with .Values.annotations }} +{{ toYaml . }} +{{- end }} +{{- end }} + {{/* Returns string "true" or empty which will be evaluated to boolean false */}} diff --git a/helm/application/templates/application/deployment.yaml b/helm/application/templates/application/deployment.yaml index 55c9593..5f3f915 100644 --- a/helm/application/templates/application/deployment.yaml +++ b/helm/application/templates/application/deployment.yaml @@ -4,6 +4,10 @@ kind: Deployment metadata: name: {{ .Values.name }} namespace: {{ .Values.namespace }} + labels: + {{- include "common.labels" . | nindent 4 }} + annotations: + {{- include "common.annotations" . | nindent 4 }} spec: replicas: {{ .Values.replicas }} selector: diff --git a/helm/application/templates/application/service.yaml b/helm/application/templates/application/service.yaml index 461ecfc..4b94e53 100644 --- a/helm/application/templates/application/service.yaml +++ b/helm/application/templates/application/service.yaml @@ -4,6 +4,10 @@ kind: Service metadata: name: {{ .Values.name }} namespace: {{ .Values.namespace }} + labels: + {{- include "common.labels" . | nindent 4 }} + annotations: + {{- include "common.annotations" . | nindent 4 }} spec: type: {{ .Values.service.type }} ports: diff --git a/helm/application/templates/ingress-route.yaml b/helm/application/templates/ingress-route.yaml index fab32ac..b20aa19 100644 --- a/helm/application/templates/ingress-route.yaml +++ b/helm/application/templates/ingress-route.yaml @@ -5,7 +5,7 @@ metadata: name: {{ .Values.name }} namespace: {{ .Values.namespace }} labels: - app: traefik + {{- include "common.labels" . | nindent 4 }} spec: entryPoints: - websecure diff --git a/helm/application/templates/traefik-forward-auth/config-map.yaml b/helm/application/templates/traefik-forward-auth/config-map.yaml index 9a35221..7115d95 100644 --- a/helm/application/templates/traefik-forward-auth/config-map.yaml +++ b/helm/application/templates/traefik-forward-auth/config-map.yaml @@ -6,19 +6,22 @@ metadata: namespace: {{ .Values.namespace }} labels: app: traefik-forward-auth + {{- include "common.labels" . | nindent 4 }} + annotations: + {{- include "common.annotations" . | nindent 4 }} data: traefik-forward-auth.ini: |- - cookie-name = "{{ .Values.auth.cookieName }}" - log-level = "{{ .Values.auth.logLevel }}" - cookie-domain = "{{ .Values.auth.cookieDomain }}" - auth-host = "{{ .Values.auth.host}}.{{ .Values.auth.cookieDomain }}" + cookie-name = {{ .Values.auth.cookieName | default (print "_" .Values.namespace "_auth") | quote }} + cookie-domain = {{ .Values.auth.cookieDomain | quote }} + auth-host = {{ .Values.auth.host | default (print "auth-" .Values.namespace "." .Values.auth.cookieDomain ) | quote}} + log-level = {{ .Values.auth.logLevel | quote}} {{- range .Values.auth.domains }} - domain = "{{ . }}" + domain = {{ . | quote }} {{- end }} {{- range .Values.auth.whitelist }} - whitelist = {{ . }} + whitelist = {{ . | quote }} {{- end }} - {{- with .Values.auth.extraConfig -}} - {{ . | nindent 4 }} + {{- range $key, $val := .Values.auth.extraConfig -}} + {{ $key | nindent 4 }} = {{ $val | quote }} {{- end }} {{- end }} \ No newline at end of file diff --git a/helm/application/templates/traefik-forward-auth/deployment.yaml b/helm/application/templates/traefik-forward-auth/deployment.yaml index b13e373..8ec2931 100644 --- a/helm/application/templates/traefik-forward-auth/deployment.yaml +++ b/helm/application/templates/traefik-forward-auth/deployment.yaml @@ -4,6 +4,10 @@ kind: Deployment metadata: name: traefik-forward-auth namespace: {{ .Values.namespace }} + labels: + {{- include "common.labels" . | nindent 4 }} + annotations: + {{- include "common.annotations" . | nindent 4 }} spec: replicas: 1 selector: diff --git a/helm/application/templates/traefik-forward-auth/middleware.yaml b/helm/application/templates/traefik-forward-auth/middleware.yaml index 3152612..ec92c4d 100644 --- a/helm/application/templates/traefik-forward-auth/middleware.yaml +++ b/helm/application/templates/traefik-forward-auth/middleware.yaml @@ -4,6 +4,10 @@ kind: Middleware metadata: name: traefik-forward-auth namespace: {{ .Values.namespace }} + labels: + {{- include "common.labels" . | nindent 4 }} + annotations: + {{- include "common.annotations" . | nindent 4 }} spec: forwardAuth: address: "http://traefik-forward-auth.{{ .Values.namespace }}.svc.cluster.local:{{ .Values.auth.port }}" diff --git a/helm/application/templates/traefik-forward-auth/service.yaml b/helm/application/templates/traefik-forward-auth/service.yaml index 567c7fa..3724acf 100644 --- a/helm/application/templates/traefik-forward-auth/service.yaml +++ b/helm/application/templates/traefik-forward-auth/service.yaml @@ -4,6 +4,10 @@ kind: Service metadata: name: traefik-forward-auth namespace: {{ .Values.namespace }} + labels: + {{- include "common.labels" . | nindent 4 }} + annotations: + {{- include "common.annotations" . | nindent 4 }} spec: type: ClusterIP selector: diff --git a/helm/application/values.yaml b/helm/application/values.yaml index 2dcd1b9..7c9d647 100644 --- a/helm/application/values.yaml +++ b/helm/application/values.yaml @@ -32,6 +32,10 @@ additionalVolumes: # mountPath: /container/path # value: {} +additionalLabels: {} + +annotations: {} + resources: {} # limits: # cpu: 100m @@ -47,10 +51,10 @@ auth: # Set to "false" to reuse a different deployment in the same namespace create: true port: 4181 - cookieName: _forward_auth - cookieDomain: stonegarden.dev - host: auth + cookieName: "" + cookieDomain: "" + host: "" domains: {} whitelist: {} logLevel: error - extraConfig: {} + extraConfig: {} \ No newline at end of file