feat: add template common.hpa

This commit is contained in:
Chi-En Wu
2020-04-15 16:12:37 +08:00
parent 999118590b
commit 9b4cc30c89

43
templates/_hpa.yaml Normal file
View File

@ -0,0 +1,43 @@
{{/* vim: set filetype=mustache: */}}
{{- define "common.hpa.tpl" -}}
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
{{ include "common.metadata" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "common.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- with .Values.autoscaling.cpuUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.autoscaling.memoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ . }}
{{- end -}}
{{- end -}}
{{- define "common.hpa.if" -}}
{{- $top := first . -}}
{{- $autoscaling := $top.Values.autoscaling | default (dict) -}}
{{- if $autoscaling.enabled -}}
{{- include "common.utils.merge" (append . "common.hpa.tpl") -}}
{{- end -}}
{{- end -}}
{{- define "common.hpa" -}}
{{- include "common.utils.flattenCall" (list "common.hpa.if" .) -}}
{{- end -}}