Skip to content

Commit

Permalink
Add horizontal pod autoscaler and pod disruption budgets (#656)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andytson-inviqa authored Jan 17, 2022
1 parent 9ae1fce commit 2564a05
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/_base/helm/app/templates/horizontal-pod-autoscaler.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
25 changes: 25 additions & 0 deletions src/_base/helm/app/templates/pod-disruption-budgets.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit 2564a05

Please sign in to comment.