From b73330d058cc80535d5899587d5d8caa8c58084f Mon Sep 17 00:00:00 2001 From: antoninguyot Date: Tue, 17 Mar 2026 09:34:35 +0100 Subject: [PATCH] fix: do not render replicas when autoscaling is enabled --- templates/deployment.yml | 7 +++--- tests/deployment_test.yaml | 47 ++++++++++++++++++++++++++++++++++++++ values.yaml | 4 ++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 tests/deployment_test.yaml diff --git a/templates/deployment.yml b/templates/deployment.yml index 1e8c9ef..bcf182a 100644 --- a/templates/deployment.yml +++ b/templates/deployment.yml @@ -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 }} diff --git a/tests/deployment_test.yaml b/tests/deployment_test.yaml new file mode 100644 index 0000000..def1485 --- /dev/null +++ b/tests/deployment_test.yaml @@ -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 diff --git a/values.yaml b/values.yaml index c00c4bd..83c98c1 100644 --- a/values.yaml +++ b/values.yaml @@ -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