Skip to content

Commit

Permalink
✨ feat: worker and webhook autosacling
Browse files Browse the repository at this point in the history
closes 8gears#80, closes 8gears#87

Signed-off-by: Muhammed Hussein Karimi <[email protected]>
  • Loading branch information
mhkarimi1383 committed Aug 5, 2024
1 parent d10683b commit a5ca708
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/n8n/templates/deployment.webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion charts/n8n/templates/deployment.worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
51 changes: 51 additions & 0 deletions charts/n8n/templates/hpa.webhook.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
51 changes: 51 additions & 0 deletions charts/n8n/templates/hpa.worker.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
15 changes: 15 additions & 0 deletions charts/n8n/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5ca708

Please sign in to comment.