From e276f1b84d4170fe6ff657fa40523dc879de1f9a Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Wed, 18 May 2022 15:34:00 +0200
Subject: [PATCH] Provide HorizontalPodAutoscaler

---
 chart/templates/celery-auto-scaling.yaml | 39 ++++++++++++++++++++++++
 chart/values.yaml                        |  2 ++
 2 files changed, 41 insertions(+)
 create mode 100644 chart/templates/celery-auto-scaling.yaml

diff --git a/chart/templates/celery-auto-scaling.yaml b/chart/templates/celery-auto-scaling.yaml
new file mode 100644
index 00000000..dd06fe74
--- /dev/null
+++ b/chart/templates/celery-auto-scaling.yaml
@@ -0,0 +1,39 @@
+{{- if .Values.celery.autoScaling}}
+#apiVersion: autoscaling/v1
+#kind: HorizontalPodAutoscaler
+#metadata:
+#  name: {{ printf "%s-%s" .Release.Name "hpa" }}
+#spec:
+#  scaleTargetRef:
+#    apiVersion: apps/v1
+#    kind: StatefulSet
+#    name: {{ printf "%s-%s" .Release.Name "celery" }}
+#  minReplicas: 1
+#  maxReplicas: 3
+#  targetCPUUtilizationPercentage: 50
+---
+apiVersion: autoscaling/v2beta2
+kind: HorizontalPodAutoscaler
+metadata:
+  name: {{ printf "%s-%s" .Release.Name "hpa" }}
+spec:
+  scaleTargetRef:
+    apiVersion: apps/v1
+    kind: StatefulSet
+    name: {{ printf "%s-%s" .Release.Name "celery" }}
+  minReplicas: 1
+  maxReplicas: 3
+  metrics:
+  - type: Resource
+    resource:
+      name: cpu
+      target:
+        type: Utilization
+        averageUtilization: 50
+  behavior:
+    scaleDown:
+      stabilizationWindowSeconds: 120
+    scaleUp:
+      stabilizationWindowSeconds: 10
+---
+{{- end }}
\ No newline at end of file
diff --git a/chart/values.yaml b/chart/values.yaml
index e9fce4ce..7fcb111d 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -50,7 +50,9 @@ ingress:
     name: chart-example.local
 
 celery:
+  # should not be enabled as long as project are not stored in a db
   autoScaling: false # optional, default: false
+  # should stay to 1 replicat as long as project are not stored in a db
   replicas: 1 # optional, default: 1
   resources:
     requests:
-- 
GitLab