diff --git a/templates/gitea/_deployments.tpl b/templates/gitea/_deployments.tpl new file mode 100644 index 0000000..5089518 --- /dev/null +++ b/templates/gitea/_deployments.tpl @@ -0,0 +1,16 @@ +{{/* annotations */}} + +{{- define "gitea.deployment.annotations" -}} +{{- with .Values.deployment.annotations }} +{{- toYaml . -}} +{{- end }} +{{- end }} + +{{/* labels */}} + +{{- define "gitea.deployment.labels" -}} +{{ include "gitea.labels" . }} +{{- with .Values.deployment.labels }} +{{ toYaml . }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/templates/gitea/deployment.yaml b/templates/gitea/deployment.yaml index 58af957..5a04098 100644 --- a/templates/gitea/deployment.yaml +++ b/templates/gitea/deployment.yaml @@ -2,17 +2,16 @@ apiVersion: apps/v1 kind: Deployment metadata: + {{- with (include "gitea.deployment.annotations" . | fromYaml) }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (include "gitea.deployment.labels" . | fromYaml) }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} name: {{ include "gitea.fullname" . }} namespace: {{ .Values.namespace | default .Release.Namespace }} - annotations: - {{- if .Values.deployment.annotations }} - {{- toYaml .Values.deployment.annotations | nindent 4 }} - {{- end }} - labels: - {{- include "gitea.labels" . | nindent 4 }} - {{- if .Values.deployment.labels }} - {{- toYaml .Values.deployment.labels | nindent 4 }} - {{- end }} spec: replicas: {{ .Values.deployment.replicas }} strategy: diff --git a/unittests/helm/deployment/basic.yaml b/unittests/helm/deployment/basic.yaml index 76cc0bf..c1a28dc 100644 --- a/unittests/helm/deployment/basic.yaml +++ b/unittests/helm/deployment/basic.yaml @@ -57,6 +57,31 @@ tests: value: app.kubernetes.io/name: gitea app.kubernetes.io/instance: gitea-unittests + - it: deployment labels are always rendered + template: templates/gitea/deployment.yaml + asserts: + - isSubset: + path: metadata.labels + content: + app: gitea + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: gitea-unittests + app.kubernetes.io/managed-by: Helm + - it: deployment annotations are undefined + template: templates/gitea/deployment.yaml + asserts: + - notExists: + path: metadata.annotations + - it: deployment annotations are set + template: templates/gitea/deployment.yaml + set: + deployment.annotations: + hello: world + asserts: + - equal: + path: metadata.annotations + value: + hello: world - it: nodeSelector is undefined asserts: - notExists: