feat: allow common.metadata to be extended

This commit is contained in:
Chi-En Wu
2020-04-17 11:19:01 +08:00
parent 2d3734c769
commit 5fb7898e1b
9 changed files with 37 additions and 22 deletions

View File

@ -3,7 +3,8 @@
{{- define "common.configMap.tpl" -}} {{- define "common.configMap.tpl" -}}
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
{{ include "common.metadata" . }} metadata:
{{ include "common.metadata" . | nindent 2 }}
data: {} data: {}
{{- end -}} {{- end -}}

View File

@ -4,7 +4,8 @@
{{- $autoscaling := .Values.autoscaling | default (dict) -}} {{- $autoscaling := .Values.autoscaling | default (dict) -}}
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
{{ include "common.metadata" . }} metadata:
{{ include "common.metadata" . | nindent 2 }}
spec: spec:
{{- if not $autoscaling.enabled }} {{- if not $autoscaling.enabled }}
replicas: {{ .Values.replicaCount | default 1 }} replicas: {{ .Values.replicaCount | default 1 }}

View File

@ -3,7 +3,8 @@
{{- define "common.hpa.tpl" -}} {{- define "common.hpa.tpl" -}}
apiVersion: autoscaling/v2beta2 apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler kind: HorizontalPodAutoscaler
{{ include "common.metadata" . }} metadata:
{{ include "common.metadata" . | nindent 2 }}
spec: spec:
scaleTargetRef: scaleTargetRef:
apiVersion: apps/v1 apiVersion: apps/v1

View File

@ -1,5 +1,12 @@
{{/* vim: set filetype=mustache: */}} {{/* vim: set filetype=mustache: */}}
{{- define "common.ingress.metadata" -}}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end -}}
{{- define "common.ingress.tpl" -}} {{- define "common.ingress.tpl" -}}
{{- $fullName := include "common.fullname" . -}} {{- $fullName := include "common.fullname" . -}}
{{- $svcPort := .Values.service.port -}} {{- $svcPort := .Values.service.port -}}
@ -9,11 +16,8 @@ apiVersion: networking.k8s.io/v1beta1
apiVersion: extensions/v1beta1 apiVersion: extensions/v1beta1
{{- end }} {{- end }}
kind: Ingress kind: Ingress
{{ include "common.metadata" . }} metadata:
{{- with .Values.ingress.annotations }} {{ include "common.metadata" (list . "common.ingress.metadata") | nindent 2 }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec: spec:
{{- if .Values.ingress.tls }} {{- if .Values.ingress.tls }}
tls: tls:

View File

@ -20,12 +20,15 @@ app.kubernetes.io/name: {{ include "common.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}} {{- end -}}
{{ define "common.metadata.tpl" -}}
name: {{ include "common.fullname" . }}
labels:
{{- include "common.labels" . | nindent 2 -}}
{{- end -}}
{{- /* {{- /*
Create a standard metadata header Create a standard metadata header
*/ -}} */ -}}
{{ define "common.metadata" -}} {{ define "common.metadata" -}}
metadata: {{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.metadata.tpl") -}}
name: {{ include "common.fullname" . }}
labels:
{{- include "common.labels" . | nindent 4 -}}
{{- end -}} {{- end -}}

View File

@ -3,7 +3,8 @@
{{- define "common.pdb.tpl" -}} {{- define "common.pdb.tpl" -}}
apiVersion: policy/v1beta1 apiVersion: policy/v1beta1
kind: PodDisruptionBudget kind: PodDisruptionBudget
{{ include "common.metadata" . }} metadata:
{{ include "common.metadata" . | nindent 2 }}
spec: spec:
selector: selector:
matchLabels: matchLabels:

View File

@ -3,7 +3,8 @@
{{- define "common.secret.tpl" -}} {{- define "common.secret.tpl" -}}
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
{{ include "common.metadata" . }} metadata:
{{ include "common.metadata" . | nindent 2 }}
type: Opaque type: Opaque
data: {} data: {}
{{- end -}} {{- end -}}

View File

@ -3,7 +3,8 @@
{{- define "common.service.tpl" -}} {{- define "common.service.tpl" -}}
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
{{ include "common.metadata" . }} metadata:
{{ include "common.metadata" . | nindent 2 }}
spec: spec:
type: {{ .Values.service.type }} type: {{ .Values.service.type }}
ports: ports:

View File

@ -1,16 +1,18 @@
{{/* vim: set filetype=mustache: */}} {{/* vim: set filetype=mustache: */}}
{{- define "common.serviceAccount.metadata" -}}
name: {{ include "common.serviceAccountName" . }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end -}}
{{- define "common.serviceAccount.tpl" -}} {{- define "common.serviceAccount.tpl" -}}
apiVersion: v1 apiVersion: v1
kind: ServiceAccount kind: ServiceAccount
metadata: metadata:
name: {{ include "common.serviceAccountName" . }} {{ include "common.metadata" (list . "common.serviceAccount.metadata") | nindent 2 }}
labels:
{{- include "common.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}} {{- end -}}
{{- define "common.serviceAccount.if" -}} {{- define "common.serviceAccount.if" -}}