From 9b4cc30c892117c83fa90974bbeb0e463a84e0aa Mon Sep 17 00:00:00 2001 From: Chi-En Wu Date: Wed, 15 Apr 2020 16:12:37 +0800 Subject: [PATCH] feat: add template `common.hpa` --- templates/_hpa.yaml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 templates/_hpa.yaml diff --git a/templates/_hpa.yaml b/templates/_hpa.yaml new file mode 100644 index 0000000..b3b332a --- /dev/null +++ b/templates/_hpa.yaml @@ -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 -}}