feat: allow arguments to be passed to templates
This commit is contained in:
@ -1,13 +1,14 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.configMap.tpl" -}}
|
{{- define "common.configMap.tpl" -}}
|
||||||
|
{{- $top := first . -}}
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" . | nindent 2 }}
|
{{ include "common.metadata" (list $top) | nindent 2 }}
|
||||||
data: {}
|
data: {}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.configMap" -}}
|
{{- define "common.configMap" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.configMap.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.configMap.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.container.tpl" -}}
|
{{- define "common.container.tpl" -}}
|
||||||
name: {{ .Chart.Name }}
|
{{- $top := first . -}}
|
||||||
|
{{- $container := index . 1 -}}
|
||||||
|
{{- $image := $container.image | default (dict) -}}
|
||||||
|
name: {{ $top.Chart.Name }}
|
||||||
securityContext:
|
securityContext:
|
||||||
{{- toYaml .Values.securityContext | nindent 4 }}
|
{{- toYaml $container.securityContext | nindent 4 }}
|
||||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
image: "{{ $image.repository }}:{{ $image.tag | default $top.Chart.AppVersion }}"
|
||||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
imagePullPolicy: {{ $container.image.pullPolicy }}
|
||||||
resources:
|
resources:
|
||||||
{{- toYaml .Values.resources | nindent 4 }}
|
{{- toYaml $container.resources | nindent 4 }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.container" -}}
|
{{- define "common.container" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.container.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.container.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -6,29 +6,32 @@ spec:
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.cronJob.tpl" -}}
|
{{- define "common.cronJob.tpl" -}}
|
||||||
|
{{- $top := first . -}}
|
||||||
|
{{- $cronJob := index . 1 -}}
|
||||||
|
{{- $pod := index . 2 -}}
|
||||||
apiVersion: batch/v1beta1
|
apiVersion: batch/v1beta1
|
||||||
kind: CronJob
|
kind: CronJob
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" . | nindent 2 }}
|
{{ include "common.metadata" (list $top) | nindent 2 }}
|
||||||
spec:
|
spec:
|
||||||
schedule: "{{ .Values.cronJob.schedule }}"
|
schedule: "{{ $cronJob.schedule }}"
|
||||||
{{- with .Values.cronJob.concurrencyPolicy }}
|
{{- with $cronJob.concurrencyPolicy }}
|
||||||
concurrencyPolicy: {{ . }}
|
concurrencyPolicy: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .Values.cronJob.failedJobsHistoryLimit }}
|
{{- with $cronJob.failedJobsHistoryLimit }}
|
||||||
failedJobsHistoryLimit: {{ . }}
|
failedJobsHistoryLimit: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .Values.cronJob.successfulJobsHistoryLimit }}
|
{{- with $cronJob.successfulJobsHistoryLimit }}
|
||||||
successfulJobsHistoryLimit: {{ . }}
|
successfulJobsHistoryLimit: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
jobTemplate:
|
jobTemplate:
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" . | nindent 6 }}
|
{{ include "common.metadata" (list $top) | nindent 6 }}
|
||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
{{ include "common.pod-template" (list . "common.cronJob.pod") | nindent 8 }}
|
{{ include "common.pod-template" (list $top $pod "common.cronJob.pod") | nindent 8 }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.cronJob" -}}
|
{{- define "common.cronJob" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.cronJob.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.cronJob.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,22 +1,24 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.deployment.tpl" -}}
|
{{- define "common.deployment.tpl" -}}
|
||||||
{{- $autoscaling := .Values.autoscaling | default (dict) -}}
|
{{- $top := first . -}}
|
||||||
|
{{- $deployment := index . 1 -}}
|
||||||
|
{{- $autoscaling := index . 2 -}}
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" . | nindent 2 }}
|
{{ include "common.metadata" (list $top) | nindent 2 }}
|
||||||
spec:
|
spec:
|
||||||
{{- if not $autoscaling.enabled }}
|
{{- if not $autoscaling.enabled }}
|
||||||
replicas: {{ .Values.replicaCount | default 1 }}
|
replicas: {{ $deployment.replicaCount | default 1 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
{{- include "common.selectorLabels" . | nindent 6 }}
|
{{ include "common.selectorLabels" $top | nindent 6 }}
|
||||||
template:
|
template:
|
||||||
{{- include "common.pod-template" . | nindent 4 }}
|
{{ include "common.pod-template" . | nindent 4 }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.deployment" -}}
|
{{- define "common.deployment" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.deployment.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.deployment.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.hpa.tpl" -}}
|
{{- define "common.hpa.tpl" -}}
|
||||||
|
{{- $top := first . -}}
|
||||||
|
{{- $autoscaling := index . 1 -}}
|
||||||
apiVersion: autoscaling/v2beta2
|
apiVersion: autoscaling/v2beta2
|
||||||
kind: HorizontalPodAutoscaler
|
kind: HorizontalPodAutoscaler
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" . | nindent 2 }}
|
{{ include "common.metadata" (list $top) | nindent 2 }}
|
||||||
spec:
|
spec:
|
||||||
scaleTargetRef:
|
scaleTargetRef:
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
name: {{ include "common.fullname" . }}
|
name: {{ include "common.fullname" $top }}
|
||||||
minReplicas: {{ .Values.autoscaling.minReplicas }}
|
minReplicas: {{ $autoscaling.minReplicas }}
|
||||||
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
|
maxReplicas: {{ $autoscaling.maxReplicas }}
|
||||||
metrics:
|
metrics:
|
||||||
{{- with .Values.autoscaling.cpuUtilizationPercentage }}
|
{{- with $autoscaling.cpuUtilizationPercentage }}
|
||||||
- type: Resource
|
- type: Resource
|
||||||
resource:
|
resource:
|
||||||
name: cpu
|
name: cpu
|
||||||
@ -21,7 +23,7 @@ spec:
|
|||||||
type: Utilization
|
type: Utilization
|
||||||
averageUtilization: {{ . }}
|
averageUtilization: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .Values.autoscaling.memoryUtilizationPercentage }}
|
{{- with $autoscaling.memoryUtilizationPercentage }}
|
||||||
- type: Resource
|
- type: Resource
|
||||||
resource:
|
resource:
|
||||||
name: memory
|
name: memory
|
||||||
@ -31,14 +33,9 @@ spec:
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.hpa.if" -}}
|
{{- define "common.hpa" -}}
|
||||||
{{- $top := first . -}}
|
{{- $autoscaling := index . 1 -}}
|
||||||
{{- $autoscaling := $top.Values.autoscaling | default (dict) -}}
|
|
||||||
{{- if $autoscaling.enabled -}}
|
{{- if $autoscaling.enabled -}}
|
||||||
{{- include "common.utils.merge" (append . "common.hpa.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.hpa.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.hpa" -}}
|
|
||||||
{{- include "common.utils.flattenCall" (list "common.hpa.if" .) -}}
|
|
||||||
{{- end -}}
|
|
||||||
|
@ -1,27 +1,31 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.ingress.metadata" -}}
|
{{- define "common.ingress.metadata" -}}
|
||||||
{{- with .Values.ingress.annotations }}
|
{{- $ingress := index . 1 -}}
|
||||||
|
{{- with $ingress.annotations }}
|
||||||
annotations:
|
annotations:
|
||||||
{{- toYaml . | nindent 2 }}
|
{{- toYaml . | nindent 2 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.ingress.tpl" -}}
|
{{- define "common.ingress.tpl" -}}
|
||||||
{{- $fullName := include "common.fullname" . -}}
|
{{- $top := first . -}}
|
||||||
{{- $svcPort := .Values.service.port -}}
|
{{- $ingress := index . 1 -}}
|
||||||
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
|
{{- $service := index . 2 -}}
|
||||||
|
{{- $fullName := include "common.fullname" $top -}}
|
||||||
|
{{- $svcPort := $service.port -}}
|
||||||
|
{{- if semverCompare ">=1.14-0" $top.Capabilities.KubeVersion.GitVersion -}}
|
||||||
apiVersion: networking.k8s.io/v1beta1
|
apiVersion: networking.k8s.io/v1beta1
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
apiVersion: extensions/v1beta1
|
apiVersion: extensions/v1beta1
|
||||||
{{- end }}
|
{{- end }}
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" (list . "common.ingress.metadata") | nindent 2 }}
|
{{ include "common.metadata" (append . "common.ingress.metadata") | nindent 2 }}
|
||||||
spec:
|
spec:
|
||||||
{{- if .Values.ingress.tls }}
|
{{- if $ingress.tls }}
|
||||||
tls:
|
tls:
|
||||||
{{- range .Values.ingress.tls }}
|
{{- range $ingress.tls }}
|
||||||
- hosts:
|
- hosts:
|
||||||
{{- range .hosts }}
|
{{- range .hosts }}
|
||||||
- {{ . | quote }}
|
- {{ . | quote }}
|
||||||
@ -30,7 +34,7 @@ spec:
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
rules:
|
rules:
|
||||||
{{- range .Values.ingress.hosts }}
|
{{- range $ingress.hosts }}
|
||||||
- host: {{ .host | quote }}
|
- host: {{ .host | quote }}
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
@ -43,13 +47,9 @@ spec:
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.ingress.if" -}}
|
{{- define "common.ingress" -}}
|
||||||
{{- $top := first . -}}
|
{{- $ingress := index . 1 -}}
|
||||||
{{- if $top.Values.ingress.enabled -}}
|
{{- if $ingress.enabled -}}
|
||||||
{{- include "common.utils.merge" (append . "common.ingress.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.ingress.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.ingress" -}}
|
|
||||||
{{- include "common.utils.flattenCall" (list "common.ingress.if" .) -}}
|
|
||||||
{{- end -}}
|
|
||||||
|
@ -21,14 +21,15 @@ app.kubernetes.io/instance: {{ .Release.Name }}
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{ define "common.metadata.tpl" -}}
|
{{ define "common.metadata.tpl" -}}
|
||||||
name: {{ include "common.fullname" . }}
|
{{- $top := first . -}}
|
||||||
|
name: {{ include "common.fullname" $top }}
|
||||||
labels:
|
labels:
|
||||||
{{- include "common.labels" . | nindent 2 -}}
|
{{- include "common.labels" $top | nindent 2 -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- /*
|
{{- /*
|
||||||
Create a standard metadata header
|
Create a standard metadata header
|
||||||
*/ -}}
|
*/ -}}
|
||||||
{{ define "common.metadata" -}}
|
{{ define "common.metadata" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.metadata.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.metadata.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,35 +1,32 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.pdb.tpl" -}}
|
{{- define "common.pdb.tpl" -}}
|
||||||
|
{{- $top := first . -}}
|
||||||
|
{{- $pdb := index . 1 -}}
|
||||||
apiVersion: policy/v1beta1
|
apiVersion: policy/v1beta1
|
||||||
kind: PodDisruptionBudget
|
kind: PodDisruptionBudget
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" . | nindent 2 }}
|
{{ include "common.metadata" (list $top) | nindent 2 }}
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
{{- include "common.selectorLabels" . | nindent 6 }}
|
{{- include "common.selectorLabels" $top | nindent 6 }}
|
||||||
{{- with .Values.podDisruptionBudget }}
|
{{- if not (or (empty $pdb.minAvailable) (empty $pdb.maxUnavailable)) -}}
|
||||||
{{- if not (or (empty .minAvailable) (empty .maxUnavailable)) -}}
|
{{- fail "minAvailable and maxUnavailable can not be set together" }}
|
||||||
{{- fail "podDisruptionBudget.minAvailable and podDisruptionBudget.maxUnavailable can not be set together" }}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- with .minAvailable }}
|
{{- with $pdb.minAvailable }}
|
||||||
minAvailable: {{ . }}
|
minAvailable: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .maxUnavailable }}
|
{{- with $pdb.maxUnavailable }}
|
||||||
maxUnavailable: {{ . }}
|
maxUnavailable: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
|
||||||
{{- end -}}
|
|
||||||
|
|
||||||
{{- define "common.pdb.if" -}}
|
|
||||||
{{- $top := first . -}}
|
|
||||||
{{- $autoscaling := $top.Values.autoscaling | default (dict) -}}
|
|
||||||
{{- if or (and $autoscaling.enabled (gt ($autoscaling.minReplicas | int) 1)) (gt ($top.Values.replicaCount | int) 1) }}
|
|
||||||
{{- include "common.utils.merge" (append . "common.pdb.tpl") -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.pdb" -}}
|
{{- define "common.pdb" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.pdb.if" .) -}}
|
{{- $top := first . -}}
|
||||||
|
{{- $pod := index . 2 -}}
|
||||||
|
{{- $autoscaling := index . 3 -}}
|
||||||
|
{{- if or (and $autoscaling.enabled (gt ($autoscaling.minReplicas | int) 1)) (gt ($pod.replicaCount | int) 1) }}
|
||||||
|
{{- include "common.utils.merge" (append . "common.pdb.tpl") -}}
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,33 +1,35 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.pod-template.tpl" -}}
|
{{- define "common.pod-template.tpl" -}}
|
||||||
|
{{- $top := first . -}}
|
||||||
|
{{- $values := index . 1 -}}
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
{{- include "common.selectorLabels" . | nindent 4 }}
|
{{- include "common.selectorLabels" $top | nindent 4 }}
|
||||||
spec:
|
spec:
|
||||||
{{- with .Values.imagePullSecrets }}
|
{{- with $values.imagePullSecrets }}
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
serviceAccountName: {{ include "common.serviceAccountName" . }}
|
serviceAccountName: {{ include "common.serviceAccountName" $top }}
|
||||||
securityContext:
|
securityContext:
|
||||||
{{- toYaml .Values.podSecurityContext | nindent 4 }}
|
{{- toYaml $values.podSecurityContext | nindent 4 }}
|
||||||
containers:
|
containers:
|
||||||
- {{- include "common.container" . | nindent 6 }}
|
- {{- include "common.container" . | nindent 6 }}
|
||||||
{{- with .Values.nodeSelector }}
|
{{- with $values.nodeSelector }}
|
||||||
nodeSelector:
|
nodeSelector:
|
||||||
{{- toYaml . | nindent 4 }}
|
{{- toYaml . | nindent 4 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .Values.affinity }}
|
{{- with $values.affinity }}
|
||||||
affinity:
|
affinity:
|
||||||
{{- toYaml . | nindent 4 }}
|
{{- toYaml . | nindent 4 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .Values.tolerations }}
|
{{- with $values.tolerations }}
|
||||||
tolerations:
|
tolerations:
|
||||||
{{- toYaml . | nindent 4 }}
|
{{- toYaml . | nindent 4 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.pod-template" -}}
|
{{- define "common.pod-template" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.pod-template.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.pod-template.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.secret.tpl" -}}
|
{{- define "common.secret.tpl" -}}
|
||||||
|
{{- $top := first . -}}
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Secret
|
kind: Secret
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" . | nindent 2 }}
|
{{ include "common.metadata" (list $top) | nindent 2 }}
|
||||||
type: Opaque
|
type: Opaque
|
||||||
data: {}
|
data: {}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.secret" -}}
|
{{- define "common.secret" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.secret.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.secret.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.service.tpl" -}}
|
{{- define "common.service.tpl" -}}
|
||||||
|
{{- $top := first . -}}
|
||||||
|
{{- $service := index . 1 -}}
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" . | nindent 2 }}
|
{{ include "common.metadata" (list $top) | nindent 2 }}
|
||||||
spec:
|
spec:
|
||||||
type: {{ .Values.service.type }}
|
type: {{ $service.type }}
|
||||||
ports:
|
ports:
|
||||||
- port: {{ .Values.service.port }}
|
- port: {{ $service.port }}
|
||||||
targetPort: http
|
targetPort: http
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
name: http
|
name: http
|
||||||
selector:
|
selector:
|
||||||
{{- include "common.selectorLabels" . | nindent 4 }}
|
{{- include "common.selectorLabels" $top | nindent 4 }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.service" -}}
|
{{- define "common.service" -}}
|
||||||
{{- include "common.utils.flattenCall" (list "common.utils.merge" . "common.service.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.service.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.serviceAccount.metadata" -}}
|
{{- define "common.serviceAccount.metadata" -}}
|
||||||
name: {{ include "common.serviceAccountName" . }}
|
{{- $top := first . -}}
|
||||||
{{- with .Values.serviceAccount.annotations }}
|
{{- $serviceAccount := index . 1 -}}
|
||||||
|
name: {{ include "common.serviceAccountName" $top }}
|
||||||
|
{{- with $serviceAccount.annotations }}
|
||||||
annotations:
|
annotations:
|
||||||
{{- toYaml . | nindent 2 }}
|
{{- toYaml . | nindent 2 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
@ -12,17 +14,13 @@ annotations:
|
|||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ServiceAccount
|
kind: ServiceAccount
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" (list . "common.serviceAccount.metadata") | nindent 2 }}
|
{{ include "common.metadata" (append . "common.serviceAccount.metadata") | nindent 2 }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.serviceAccount.if" -}}
|
{{- define "common.serviceAccount" -}}
|
||||||
{{- $top := first . -}}
|
{{- $top := first . -}}
|
||||||
{{- $serviceAccount := $top.Values.serviceAccount | default (dict) -}}
|
{{- $serviceAccount := index . 1 -}}
|
||||||
{{- if $serviceAccount.create -}}
|
{{- if $serviceAccount.create -}}
|
||||||
{{- include "common.utils.merge" (append . "common.serviceAccount.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.serviceAccount.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.serviceAccount" -}}
|
|
||||||
{{- include "common.utils.flattenCall" (list "common.serviceAccount.if" .) -}}
|
|
||||||
{{- end -}}
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.serviceMonitor.secret.tpl" -}}
|
{{- define "common.serviceMonitor.secret.tpl" -}}
|
||||||
{{- $basicAuth := .Values.serviceMonitor.basicAuth | default (dict) -}}
|
{{- $top := first . -}}
|
||||||
|
{{- $serviceMonitor := index . 1 -}}
|
||||||
|
{{- $basicAuth := $serviceMonitor.basicAuth | default (dict) -}}
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ $basicAuth.secretName | default (include "common.fullname" .) }}
|
name: {{ $basicAuth.secretName | default (include "common.fullname" $top) }}
|
||||||
{{- with .Values.serviceMonitor.namespace }}
|
{{- with $serviceMonitor.namespace }}
|
||||||
namespace: {{ . }}
|
namespace: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if $basicAuth.enabled }}
|
{{- if $basicAuth.enabled }}
|
||||||
@ -14,14 +16,10 @@ data:
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.serviceMonitor.secret.if" -}}
|
{{- define "common.serviceMonitor.secret" -}}
|
||||||
{{- $top := first . -}}
|
{{- $top := first . -}}
|
||||||
{{- $serviceMonitor := $top.Values.serviceMonitor | default (dict) -}}
|
{{- $serviceMonitor := index . 1 -}}
|
||||||
{{- if $serviceMonitor.enabled -}}
|
{{- if $serviceMonitor.enabled -}}
|
||||||
{{- include "common.secret" (append . "common.serviceMonitor.secret.tpl") -}}
|
{{- include "common.secret" (append . "common.serviceMonitor.secret.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.serviceMonitor.secret" -}}
|
|
||||||
{{- include "common.utils.flattenCall" (list "common.serviceMonitor.secret.if" .) -}}
|
|
||||||
{{- end -}}
|
|
||||||
|
@ -1,36 +1,39 @@
|
|||||||
{{/* vim: set filetype=mustache: */}}
|
{{/* vim: set filetype=mustache: */}}
|
||||||
|
|
||||||
{{- define "common.serviceMonitor.metadata" -}}
|
{{- define "common.serviceMonitor.metadata" -}}
|
||||||
{{- with .Values.serviceMonitor.namespace }}
|
{{- $serviceMonitor := index . 1 -}}
|
||||||
|
{{- with $serviceMonitor.namespace }}
|
||||||
namespace: {{ . }}
|
namespace: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.serviceMonitor.tpl" -}}
|
{{- define "common.serviceMonitor.tpl" -}}
|
||||||
|
{{- $top := first . -}}
|
||||||
|
{{- $serviceMonitor := index . 1 -}}
|
||||||
apiVersion: monitoring.coreos.com/v1
|
apiVersion: monitoring.coreos.com/v1
|
||||||
kind: ServiceMonitor
|
kind: ServiceMonitor
|
||||||
metadata:
|
metadata:
|
||||||
{{ include "common.metadata" (list . "common.serviceMonitor.metadata") | nindent 2 }}
|
{{ include "common.metadata" (append . "common.serviceMonitor.metadata") | nindent 2 }}
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
{{- include "common.selectorLabels" . | nindent 6 }}
|
{{- include "common.selectorLabels" $top | nindent 6 }}
|
||||||
namespaceSelector:
|
namespaceSelector:
|
||||||
matchNames:
|
matchNames:
|
||||||
- {{ .Release.Namespace | quote }}
|
- {{ $top.Release.Namespace | quote }}
|
||||||
endpoints:
|
endpoints:
|
||||||
- port: {{ .Values.serviceMonitor.port | default .Values.service.port }}
|
- port: {{ $serviceMonitor.port }}
|
||||||
{{- with .Values.serviceMonitor.path }}
|
{{- with $serviceMonitor.path }}
|
||||||
path: {{ . }}
|
path: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .Values.serviceMonitor.interval }}
|
{{- with $serviceMonitor.interval }}
|
||||||
interval: {{ . }}
|
interval: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .Values.serviceMonitor.scrapeTimeout }}
|
{{- with $serviceMonitor.scrapeTimeout }}
|
||||||
scrapeTimeout: {{ . }}
|
scrapeTimeout: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $basicAuth := .Values.serviceMonitor.basicAuth | default (dict) -}}
|
{{- $basicAuth := $serviceMonitor.basicAuth | default (dict) -}}
|
||||||
{{- $name := $basicAuth.secretName | default (include "common.fullname" .) -}}
|
{{- $name := $basicAuth.secretName | default (include "common.fullname" $top) -}}
|
||||||
{{- if $basicAuth.enabled }}
|
{{- if $basicAuth.enabled }}
|
||||||
basicAuth:
|
basicAuth:
|
||||||
username:
|
username:
|
||||||
@ -42,14 +45,10 @@ spec:
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.serviceMonitor.if" -}}
|
{{- define "common.serviceMonitor" -}}
|
||||||
{{- $top := first . -}}
|
{{- $top := first . -}}
|
||||||
{{- $serviceMonitor := $top.Values.serviceMonitor | default (dict) -}}
|
{{- $serviceMonitor := index . 1 -}}
|
||||||
{{- if $serviceMonitor.enabled -}}
|
{{- if $serviceMonitor.enabled -}}
|
||||||
{{- include "common.utils.merge" (append . "common.serviceMonitor.tpl") -}}
|
{{- include "common.utils.merge" (append . "common.serviceMonitor.tpl") -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "common.serviceMonitor" -}}
|
|
||||||
{{- include "common.utils.flattenCall" (list "common.serviceMonitor.if" .) -}}
|
|
||||||
{{- end -}}
|
|
||||||
|
@ -3,32 +3,22 @@
|
|||||||
{{- /*
|
{{- /*
|
||||||
Merge one or more YAML templates and output the result.
|
Merge one or more YAML templates and output the result.
|
||||||
This takes an list of values:
|
This takes an list of values:
|
||||||
- the first item is the top context
|
- the top context
|
||||||
- the rest items are template names of the templates, the former one will override the latter.
|
- [optional] zero or more template args
|
||||||
|
- [optional] the template name of the overrides (destination)
|
||||||
|
- the template name of the base (source)
|
||||||
*/ -}}
|
*/ -}}
|
||||||
{{- define "common.utils.merge" -}}
|
{{- define "common.utils.merge" -}}
|
||||||
{{- $top := first . -}}
|
{{- $top := first . -}}
|
||||||
{{- $dest := dict -}}
|
{{- $tplName := last . -}}
|
||||||
{{- range (rest .) -}}
|
{{- $args := initial . -}}
|
||||||
{{- $src := fromYaml (include . $top) | default (dict) -}}
|
{{- if typeIs "string" (last $args) -}}
|
||||||
{{- $dest = merge $dest $src -}}
|
{{- $overridesName := last $args -}}
|
||||||
|
{{- $args = initial $args -}}
|
||||||
|
{{- $tpl := fromYaml (include $tplName $args) | default (dict) -}}
|
||||||
|
{{- $overrides := fromYaml (include $overridesName $args) | default (dict) -}}
|
||||||
|
{{- toYaml (merge $overrides $tpl) -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- include $tplName $args -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- toYaml $dest -}}
|
|
||||||
{{- end -}}
|
|
||||||
|
|
||||||
{{- /*
|
|
||||||
Flatten list of arguments before rendering the given template.
|
|
||||||
This takes an list of values:
|
|
||||||
- the first item is the template name to be rendered
|
|
||||||
- the second item is either an list of arguments or a single argument
|
|
||||||
- the rest items are the appended arguments
|
|
||||||
*/ -}}
|
|
||||||
{{- define "common.utils.flattenCall" -}}
|
|
||||||
{{- $tpl := first . -}}
|
|
||||||
{{- $args := index . 1 -}}
|
|
||||||
{{- if not (typeIs "[]interface {}" $args) -}}
|
|
||||||
{{- $args = list $args -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- $args = concat $args (slice . 2) -}}
|
|
||||||
{{- include $tpl $args -}}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
Reference in New Issue
Block a user