From 507cca0fb9b3a796ff598d9b1c97c4af7e6e587c Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Tue, 7 Nov 2023 09:39:37 +0100 Subject: [PATCH] Added missing labels/annotations --- helm/cluster_setup/Chart.yaml | 6 +- helm/cluster_setup/templates/_helpers.tpl | 77 +++++++++++++++++++ .../templates/certificate-issuer.yaml | 4 + .../cluster_setup/templates/hcloud-token.yaml | 8 ++ .../templates/thanos-object-storage.yaml | 8 ++ .../templates/vault-service-principal.yaml | 4 + 6 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 helm/cluster_setup/templates/_helpers.tpl diff --git a/helm/cluster_setup/Chart.yaml b/helm/cluster_setup/Chart.yaml index 955bb1e..d19693f 100644 --- a/helm/cluster_setup/Chart.yaml +++ b/helm/cluster_setup/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: cluster_setup -version: 0.3.2 +version: 0.3.3 type: application description: "Initial cluster setup" maintainers: @@ -8,8 +8,8 @@ maintainers: url: https://2martens.de annotations: artifacthub.io/changes: | - - kind: changed - description: Create namespace if thanos is enabled + - kind: fixed + description: Added missing labels and annotations artifacthub.io/signKey: | fingerprint: F0F153B65BAD467201D7544E47393ABD1F96B7C8 url: https://mafiasi.de/pks/key/47393ABD1F96B7C8.asc diff --git a/helm/cluster_setup/templates/_helpers.tpl b/helm/cluster_setup/templates/_helpers.tpl new file mode 100644 index 0000000..8b8462b --- /dev/null +++ b/helm/cluster_setup/templates/_helpers.tpl @@ -0,0 +1,77 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "template.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "template.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "template.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "template.labels" -}} +helm.sh/chart: {{ include "template.chart" . }} +{{ include "template.selectorLabels" . }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} +{{- define "template.annotations" -}} +meta.helm.sh/release-name: {{ .Release.Name }} +meta.helm.sh/release-namespace: {{ .Release.Namespace }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "template.selectorLabels" -}} +app.kubernetes.io/name: {{ include "template.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "template.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "template.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{- /* +template.util.merge will merge two YAML templates and output the result. +This takes an array of three values: +- the top context +- the template name of the overrides (destination) +- the template name of the base (source) +*/}} +{{- define "template.util.merge" -}} +{{- $top := first . -}} +{{- $overrides := fromYaml (include (index . 1) $top) | default (dict ) -}} +{{- $tpl := fromYaml (include (index . 2) $top) | default (dict ) -}} +{{- toYaml (merge $overrides $tpl) -}} +{{- end -}} diff --git a/helm/cluster_setup/templates/certificate-issuer.yaml b/helm/cluster_setup/templates/certificate-issuer.yaml index b03cf39..d230139 100644 --- a/helm/cluster_setup/templates/certificate-issuer.yaml +++ b/helm/cluster_setup/templates/certificate-issuer.yaml @@ -2,6 +2,10 @@ apiVersion: cert-manager.io/v1 kind: ClusterIssuer metadata: name: lets-encrypt + labels: + {{- include "template.labels" . | nindent 4 }} + annotations: + {{- include "template.annotations" . | nindent 4 }} spec: acme: email: {{ .Values.email }} diff --git a/helm/cluster_setup/templates/hcloud-token.yaml b/helm/cluster_setup/templates/hcloud-token.yaml index e352da6..b800ba3 100644 --- a/helm/cluster_setup/templates/hcloud-token.yaml +++ b/helm/cluster_setup/templates/hcloud-token.yaml @@ -3,12 +3,20 @@ apiVersion: v1 kind: Namespace metadata: name: {{ .Values.hcloud.namespace | default "hcloud" }} + labels: + {{- include "template.labels" . | nindent 4 }} + annotations: + {{- include "template.annotations" . | nindent 4 }} --- apiVersion: v1 kind: Secret type: Opaque metadata: name: hcloud + labels: + {{- include "template.labels" . | nindent 4 }} + annotations: + {{- include "template.annotations" . | nindent 4 }} data: token: {{ .Values.hcloud.token | b64enc }} {{- end }} \ No newline at end of file diff --git a/helm/cluster_setup/templates/thanos-object-storage.yaml b/helm/cluster_setup/templates/thanos-object-storage.yaml index 7b3677e..04ae0a8 100644 --- a/helm/cluster_setup/templates/thanos-object-storage.yaml +++ b/helm/cluster_setup/templates/thanos-object-storage.yaml @@ -3,12 +3,20 @@ apiVersion: v1 kind: Namespace metadata: name: {{ .Values.thanos.namespace | default "observability" }} + labels: + {{- include "template.labels" . | nindent 4 }} + annotations: + {{- include "template.annotations" . | nindent 4 }} --- apiVersion: v1 kind: Secret metadata: namespace: {{ .Values.thanos.namespace | default "observability" }} name: thanos-object-storage-config + labels: + {{- include "template.labels" . | nindent 4 }} + annotations: + {{- include "template.annotations" . | nindent 4 }} data: thanos.yaml: |- {{ tpl (.Files.Get "thanos.yaml") . | b64enc }} diff --git a/helm/cluster_setup/templates/vault-service-principal.yaml b/helm/cluster_setup/templates/vault-service-principal.yaml index 7b811ba..d46de1b 100644 --- a/helm/cluster_setup/templates/vault-service-principal.yaml +++ b/helm/cluster_setup/templates/vault-service-principal.yaml @@ -5,6 +5,8 @@ apiVersion: v1 kind: Namespace metadata: name: {{ .name }} + labels: + {{- include "template.labels" . | nindent 4 }} --- apiVersion: v1 kind: Secret @@ -12,6 +14,8 @@ type: Opaque metadata: name: vault-service-principal namespace: {{ .name }} + labels: + {{- include "template.labels" . | nindent 4 }} data: clientID: {{ $.Values.vault.clientId | b64enc }} clientSecret: {{ $.Values.vault.clientSecret | b64enc }}