From a5ca708f8245b03e260efc65ccb561538469a9b4 Mon Sep 17 00:00:00 2001 From: Muhammed Hussein Karimi Date: Mon, 5 Aug 2024 13:06:17 +0330 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20feat:=20worker=20and=20webhook?= =?UTF-8?q?=20autosacling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #80, closes #87 Signed-off-by: Muhammed Hussein Karimi --- charts/n8n/templates/deployment.webhooks.yaml | 2 +- charts/n8n/templates/deployment.worker.yaml | 2 +- charts/n8n/templates/hpa.webhook.yaml | 51 +++++++++++++++++++ charts/n8n/templates/hpa.worker.yaml | 51 +++++++++++++++++++ charts/n8n/values.yaml | 15 ++++++ 5 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 charts/n8n/templates/hpa.webhook.yaml create mode 100644 charts/n8n/templates/hpa.worker.yaml diff --git a/charts/n8n/templates/deployment.webhooks.yaml b/charts/n8n/templates/deployment.webhooks.yaml index 3b7f22e..6483845 100644 --- a/charts/n8n/templates/deployment.webhooks.yaml +++ b/charts/n8n/templates/deployment.webhooks.yaml @@ -6,7 +6,7 @@ metadata: labels: {{- include "n8n.labels" . | nindent 4 }} spec: - {{- if not .Values.autoscaling.enabled }} + {{- if not .Values.webhookAutoscaling.enabled }} replicas: {{ .Values.scaling.webhook.count }} {{- end }} strategy: diff --git a/charts/n8n/templates/deployment.worker.yaml b/charts/n8n/templates/deployment.worker.yaml index 0014d3e..61489cc 100644 --- a/charts/n8n/templates/deployment.worker.yaml +++ b/charts/n8n/templates/deployment.worker.yaml @@ -6,7 +6,7 @@ metadata: labels: {{- include "n8n.labels" . | nindent 4 }} spec: - {{- if not .Values.autoscaling.enabled }} + {{- if not .Values.workerAutoscaling.enabled }} replicas: {{ .Values.scaling.worker.count }} {{- end }} strategy: diff --git a/charts/n8n/templates/hpa.webhook.yaml b/charts/n8n/templates/hpa.webhook.yaml new file mode 100644 index 0000000..5411616 --- /dev/null +++ b/charts/n8n/templates/hpa.webhook.yaml @@ -0,0 +1,51 @@ +{{- if .Values.autoscaling.enabled }} +{{- if semverCompare ">=1.25-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: autoscaling/v2 +{{- else -}} +apiVersion: autoscaling/v2beta1 +{{- end }} +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "n8n.fullname" . }}-webhook + labels: + {{- include "n8n.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "n8n.fullname" . }}-webhook + minReplicas: {{ .Values.webhookAutoscaling.minReplicas }} + maxReplicas: {{ .Values.webhookAutoscaling.maxReplicas }} + metrics: +{{- if semverCompare ">=1.25-0" .Capabilities.KubeVersion.GitVersion -}} + {{- if .Values.webhookAutoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.webhookAutoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.webhookAutoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.webhookAutoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- else -}} + {{- if .Values.webhookAutoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.webhookAutoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.webhookAutoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.webhookAutoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/n8n/templates/hpa.worker.yaml b/charts/n8n/templates/hpa.worker.yaml new file mode 100644 index 0000000..2bb7f31 --- /dev/null +++ b/charts/n8n/templates/hpa.worker.yaml @@ -0,0 +1,51 @@ +{{- if .Values.autoscaling.enabled }} +{{- if semverCompare ">=1.25-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: autoscaling/v2 +{{- else -}} +apiVersion: autoscaling/v2beta1 +{{- end }} +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "n8n.fullname" . }}-worker + labels: + {{- include "n8n.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "n8n.fullname" . }}-worker + minReplicas: {{ .Values.workerAutoscaling.minReplicas }} + maxReplicas: {{ .Values.workerAutoscaling.maxReplicas }} + metrics: +{{- if semverCompare ">=1.25-0" .Capabilities.KubeVersion.GitVersion -}} + {{- if .Values.workerAutoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.workerAutoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.workerAutoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.workerAutoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- else -}} + {{- if .Values.workerAutoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.workerAutoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.workerAutoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.workerAutoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/n8n/values.yaml b/charts/n8n/values.yaml index 14e98b5..a44370d 100644 --- a/charts/n8n/values.yaml +++ b/charts/n8n/values.yaml @@ -277,9 +277,24 @@ ingress: workerResources: {} +workerAutoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + webhookResources: {} +webhookAutoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + resources: {} # We usually recommend not to specify default resources and to leave this as a conscious From 101e5686b0f5dded802cbe012c857bc1758e6635 Mon Sep 17 00:00:00 2001 From: Muhammed Hussein Karimi Date: Mon, 5 Aug 2024 13:15:29 +0330 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=20typo:=20also=20chec?= =?UTF-8?q?k=20if=20scaling=20is=20enabled=20in=20worker=20and=20webhook?= =?UTF-8?q?=20hpa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Muhammed Hussein Karimi --- charts/n8n/templates/hpa.webhook.yaml | 4 +++- charts/n8n/templates/hpa.worker.yaml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/charts/n8n/templates/hpa.webhook.yaml b/charts/n8n/templates/hpa.webhook.yaml index 5411616..c5d9372 100644 --- a/charts/n8n/templates/hpa.webhook.yaml +++ b/charts/n8n/templates/hpa.webhook.yaml @@ -1,4 +1,5 @@ -{{- if .Values.autoscaling.enabled }} +{{- if .Values.scaling.enabled }} +{{- if .Values.webhookAutoscaling.enabled }} {{- if semverCompare ">=1.25-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: autoscaling/v2 {{- else -}} @@ -49,3 +50,4 @@ spec: {{- end }} {{- end }} {{- end }} +{{- end }} diff --git a/charts/n8n/templates/hpa.worker.yaml b/charts/n8n/templates/hpa.worker.yaml index 2bb7f31..fe60fe7 100644 --- a/charts/n8n/templates/hpa.worker.yaml +++ b/charts/n8n/templates/hpa.worker.yaml @@ -1,4 +1,5 @@ -{{- if .Values.autoscaling.enabled }} +{{- if .Values.scaling.enabled }} +{{- if .Values.workerAutoscaling.enabled }} {{- if semverCompare ">=1.25-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: autoscaling/v2 {{- else -}} @@ -49,3 +50,4 @@ spec: {{- end }} {{- end }} {{- end }} +{{- end }}