Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

feat: optional HPA #64

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion traefik-hub/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ metadata:
labels:
{{- include "traefik-hub.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicas }}
{{- with .Values.replicas }}
replicas: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "traefik-hub.labelselector" . | nindent 6 }}
Expand Down
28 changes: 28 additions & 0 deletions traefik-hub/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.maxReplicas }}
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "traefik-hub.name" . }}
namespace: {{ .Release.Namespace }}
labels: {{ include "traefik-hub.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: traefik
{{- with .Values.autoscaling }}
{{- with .minReplicas }}
minReplicas: {{ . }}
{{- end }}
{{- with .maxReplicas }}
maxReplicas: {{ . }}
{{- end }}
{{- with .metrics }}
metrics: {{ toYaml . | nindent 4 }}
{{- end }}
{{- with .behavior }}
behavior: {{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
86 changes: 86 additions & 0 deletions traefik-hub/tests/hpa_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
suite: HPA tests
release:
name: traefik-hub
namespace: traefik
templates:
- hpa.yaml
tests:
- it: should not render HPA by default
asserts:
- hasDocuments:
count: 0
- it: should render HPA with only maxReplicas set
set:
autoscaling:
maxReplicas: 5
asserts:
- isKind:
of: HorizontalPodAutoscaler
- isAPIVersion:
of: autoscaling/v2
- isNull:
path: spec.metrics
- isNull:
path: spec.behavior
- isNull:
path: spec.minReplicas
- it: should set the namespace
release:
namespace: test
set:
autoscaling:
maxReplicas: 5
asserts:
- equal:
path: metadata.namespace
value: test
- it: hpa should be customizable
set:
autoscaling:
minReplicas: 2
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 60
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 1
periodSeconds: 60
asserts:
- equal:
path: spec.minReplicas
value: 2
- equal:
path: spec.maxReplicas
value: 5
- contains:
path: spec.metrics
content:
type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 60
- isSubset:
path: spec.behavior
content:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 1
periodSeconds: 60
13 changes: 12 additions & 1 deletion traefik-hub/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
replicas: 1
## Can be used to set number of Traefik Hub instances
## When using HPA, keep it empty in order to avoid conflicts
## between this value and HPA.
replicas:
maxSurge: 1

## On production system, you may want to set it to "system-cluster-critical"
Expand Down Expand Up @@ -60,6 +63,14 @@ service:
name: websecure
targetPort: websecure

## Optional HPA on Traefik Hub. Created when required `maxReplicas` is set.
## See https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
autoscaling:
minReplicas:
maxReplicas:
metrics:
behavior:

## use it to load plugins
plugins: []
# - name: crowdsec-bouncer-traefik-plugin
Expand Down