From 2564a05394a58a595e4c0b8d2dfe971daef47993 Mon Sep 17 00:00:00 2001 From: andytson-inviqa Date: Mon, 17 Jan 2022 12:25:03 +0000 Subject: [PATCH] Add horizontal pod autoscaler and pod disruption budgets (#656) autoscaler will be added based on .Values.services.*.autoscaling config, and pod disruption budgets default to minAvailable 1 only if minimum replicas is greater than 1 --- .../templates/horizontal-pod-autoscaler.yaml | 44 +++++++++++++++++++ .../app/templates/pod-disruption-budgets.yaml | 25 +++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/_base/helm/app/templates/horizontal-pod-autoscaler.yaml create mode 100644 src/_base/helm/app/templates/pod-disruption-budgets.yaml diff --git a/src/_base/helm/app/templates/horizontal-pod-autoscaler.yaml b/src/_base/helm/app/templates/horizontal-pod-autoscaler.yaml new file mode 100644 index 000000000..4643f30b2 --- /dev/null +++ b/src/_base/helm/app/templates/horizontal-pod-autoscaler.yaml @@ -0,0 +1,44 @@ +{{- range $serviceName, $service := .Values.services -}} +{{- with $service }} +{{- $autoscaling := .autoscaling | default (dict) -}} +{{- if and (not (hasPrefix "." $serviceName)) .enabled $autoscaling.enabled }} +--- +apiVersion: autoscaling/v2beta2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ print $.Release.Name "-" $serviceName }} + labels: + {{- include "chart.labels" $ | nindent 4 }} + app.kubernetes.io/component: {{ $serviceName }} + app.service: {{ print $.Release.Name "-" $serviceName }} + annotations: + argocd.argoproj.io/sync-wave: "15" +spec: + {{- with (omit $autoscaling "enabled" "metrics") }} + {{- . | toYaml | nindent 2 }} + {{- end }} + metrics: + {{- with $autoscaling.metrics }} + {{- . | toYaml | nindent 4 }} + {{- end }} + {{- with $autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ . }} + {{- end }} + {{- with $autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ . }} + {{- end }} + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ print $.Release.Name "-" $serviceName }} +{{- end }} +{{- end }} +{{- end }} diff --git a/src/_base/helm/app/templates/pod-disruption-budgets.yaml b/src/_base/helm/app/templates/pod-disruption-budgets.yaml new file mode 100644 index 000000000..95a22c67c --- /dev/null +++ b/src/_base/helm/app/templates/pod-disruption-budgets.yaml @@ -0,0 +1,25 @@ +{{- range $serviceName, $service := .Values.services -}} +{{- with $service }} +{{- if and (not (hasPrefix "." $serviceName)) .enabled }} +{{- $autoscaling := .autoscaling | default (dict "minReplicas" 0) -}} +{{- if or (gt (.replicas | default 1) 1) (and $autoscaling.enabled (gt $autoscaling.minReplicas 1)) }} +--- +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: {{ print $.Values.resourcePrefix $serviceName }} + labels: + {{- include "chart.labels" $ | nindent 4 }} + app.kubernetes.io/component: {{ $serviceName}} + app.service: {{ print $.Values.resourcePrefix $serviceName }} + annotations: + argocd.argoproj.io/sync-wave: "15" +spec: + minAvailable: {{- .minAvailable | default 1 }} + selector: + matchLabels: + app.service: {{ print $.Values.resourcePrefix $serviceName }} +{{- end }} +{{- end }} +{{- end }} +{{- end }}