From b887b70d809e085fb06fb46cc7f9d6ecaa850fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alby=20Hern=C3=A1ndez?= Date: Wed, 11 Sep 2024 09:01:16 +0100 Subject: [PATCH] feat: Add autoscaling and PDB templates to Helm chart --- charts/doorkeeper/Chart.yaml | 2 +- charts/doorkeeper/templates/hpa.yaml | 62 ++++++++++++++++++++++++++++ charts/doorkeeper/templates/pdb.yaml | 35 ++++++++++++++++ charts/doorkeeper/values.yaml | 22 ++++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 charts/doorkeeper/templates/hpa.yaml create mode 100644 charts/doorkeeper/templates/pdb.yaml diff --git a/charts/doorkeeper/Chart.yaml b/charts/doorkeeper/Chart.yaml index 1e553dd..aaedbf4 100644 --- a/charts/doorkeeper/Chart.yaml +++ b/charts/doorkeeper/Chart.yaml @@ -4,7 +4,7 @@ type: application description: >- A Helm chart for Doorkeeper, a tiny HTTP server to be used as external authentication service for Envoy -version: &chartVersion 0.1.6 +version: &chartVersion 0.2.0 appVersion: *chartVersion kubeVersion: ">=1.22.0-0" home: https://github.com/freepik-company/doorkeeper diff --git a/charts/doorkeeper/templates/hpa.yaml b/charts/doorkeeper/templates/hpa.yaml new file mode 100644 index 0000000..07cdad0 --- /dev/null +++ b/charts/doorkeeper/templates/hpa.yaml @@ -0,0 +1,62 @@ +{{- if .Values.server.autoscaling }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "doorkeeper.fullname" . }} + labels: + {{- include "doorkeeper.labels" . | nindent 4 }} + {{- with .Values.server.extraLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + + {{- with .Values.server.autoscaling.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + +spec: + {{- if .Values.server.autoscaling.behavior }} + behavior: + {{- toYaml .Values.server.autoscaling.behavior | nindent 4 }} + {{- end }} + + # Match the generated Deployment by reference + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "doorkeeper.fullname" . }} + + {{- with .Values.server.autoscaling }} + minReplicas: {{ .minReplicas }} + maxReplicas: {{ .maxReplicas }} + + metrics: + # Changing the order of the metrics will cause ArgoCD + # to go into a sync loop memory needs to be first. + # More info in: https://github.com/argoproj/argo-cd/issues/1079 + {{- with .targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ . }} + {{- end }} + + {{- with .targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ . }} + {{- end }} + + {{- if .customRules -}} + {{- toYaml .customRules | nindent 4}} + {{- end }} + + {{- end }} + +--- +{{- end }} diff --git a/charts/doorkeeper/templates/pdb.yaml b/charts/doorkeeper/templates/pdb.yaml new file mode 100644 index 0000000..1fd382d --- /dev/null +++ b/charts/doorkeeper/templates/pdb.yaml @@ -0,0 +1,35 @@ + +{{- if .Values.server.disruption }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "doorkeeper.fullname" . }} + labels: + {{- include "doorkeeper.labels" . | nindent 4 }} + {{- with .Values.server.extraLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + + {{- with .Values.server.disruption.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + + +spec: + {{- with .Values.server.disruption.minAvailable }} + minAvailable: {{ . }} + {{- end }} + + {{- with .Values.server.disruption.maxUnavailable }} + maxUnavailable: {{ . }} + {{- end }} + + selector: + matchLabels: + {{- include "doorkeeper.selectorLabels" . | nindent 4 }} + {{- with .Values.server.extraLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} +--- +{{- end }} diff --git a/charts/doorkeeper/values.yaml b/charts/doorkeeper/values.yaml index 43339c9..3299b92 100644 --- a/charts/doorkeeper/values.yaml +++ b/charts/doorkeeper/values.yaml @@ -141,6 +141,28 @@ server: affinity: {} + # Pod Disruption Budget configurations + disruption: + annotations: {} + minAvailable: 2 + #maxUnavailable: 1 + + # Horizontal Pod Autoscaling configurations + autoscaling: + annotations: {} + minReplicas: 1 + maxReplicas: 5 + + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + ## see https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics-and-custom-metrics + customRules: [] + + ## see https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior + behavior: {} + + # Define some extra resources to be created # This section is useful when you need ExternalResource or Secrets, etc. extraResources: []