Skip to content
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
7 changes: 4 additions & 3 deletions templates/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ metadata:
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
spec:
{{ if .Values.horizontalAutoscaler.enabled }}
replicas: {{ .Values.horizontalAutoscaler.minReplicas }}
{{ end }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
{{- if not .Values.horizontalAutoscaler.enabled }}
replicas: {{ .Values.replicas }}
{{- end }}
selector:
matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
strategy: {{- include "common.tplvalues.render" (dict "value" .Values.updateStrategy "context" $ ) | nindent 4 }}
Expand Down
47 changes: 47 additions & 0 deletions tests/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: deployment scaling
templates:
- deployment.yml
- hpa.yml
tests:
- it: should render deployment replicas from replicas when autoscaling is disabled
template: deployment.yml
set:
replicas: 4
horizontalAutoscaler.enabled: false
horizontalAutoscaler.minReplicas: 2
asserts:
- isKind:
of: Deployment
- equal:
path: spec.replicas
value: 4

- it: should omit deployment replicas and keep hpa minReplicas when autoscaling is enabled
set:
replicas: 4
horizontalAutoscaler.enabled: true
horizontalAutoscaler.minReplicas: 2
horizontalAutoscaler.maxReplicas: 5
template: deployment.yml
asserts:
- isKind:
of: Deployment
- notExists:
path: spec.replicas

- it: should render hpa minReplicas when autoscaling is enabled
set:
horizontalAutoscaler.enabled: true
horizontalAutoscaler.minReplicas: 2
horizontalAutoscaler.maxReplicas: 5
template: hpa.yml
asserts:
- isKind:
of: HorizontalPodAutoscaler
- equal:
path: spec.minReplicas
value: 2
- equal:
path: spec.maxReplicas
value: 5
4 changes: 4 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ nodeAffinityPreset:
## - e2e-az2
##
values: []
## @param revisionHistoryLimit Number of controller revisions to keep
revisionHistoryLimit: 3
## @param replicas Replica count when no autoscaler is configured
replicas: 1
## @param affinity Affinity for pod assignment
## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
## NOTE: podAffinityPreset, podAntiAffinityPreset, and nodeAffinityPreset will be ignored when it's set
Expand Down
Loading