Skip to content

Commit 4fc33d4

Browse files
authored
Avoid setting replicase while HPA is enabled (#181)
* fix: avoid setting replicase while HPA is enabled * fix: add tests
1 parent 5675e6d commit 4fc33d4

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

charts/k8s-service/templates/_deployment_spec.tpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ metadata:
9696
{{ toYaml . | indent 4 }}
9797
{{- end }}
9898
spec:
99-
replicas: {{ if .isCanary }}{{ .Values.canary.replicaCount | default 1 }}{{ else }}{{ .Values.replicaCount }}{{ end }}
99+
{{- if .isCanary }}
100+
replicas: {{ .Values.canary.replicaCount | default 1 }}
101+
{{ else }}
102+
{{- if not .Values.horizontalPodAutoscaler.enabled }}
103+
replicas: {{ .Values.replicaCount }}
104+
{{- end }}
105+
{{- end }}
100106
{{- if .Values.deploymentStrategy.enabled }}
101107
strategy:
102108
type: {{ .Values.deploymentStrategy.type }}

test/k8s_service_template_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,3 +1077,33 @@ func TestK8SServiceClusterIP(t *testing.T) {
10771077
})
10781078
}
10791079
}
1080+
1081+
// Test that setting horizontalPodAutoscaler.enabled = true will cause the helm template to not render replicas
1082+
func TestK8SServiceServiceHorizontalPodAutoscalerDoesNotConfigureReplicas(t *testing.T) {
1083+
t.Parallel()
1084+
1085+
deployment := renderK8SServiceDeploymentWithSetValues(
1086+
t,
1087+
map[string]string{
1088+
"horizontalPodAutoscaler.enabled": "true",
1089+
"replicaCount": "3",
1090+
},
1091+
)
1092+
assert.Equal(t, (*int32)(nil), deployment.Spec.Replicas)
1093+
}
1094+
1095+
// Test that setting horizontalPodAutoscaler = true will not affect the canary
1096+
func TestK8SServiceServiceHorizontalPodAutoscalerDoesNotAffectCanaryConfiguration(t *testing.T) {
1097+
t.Parallel()
1098+
deployment := renderK8SServiceCanaryDeploymentWithSetValues(
1099+
t,
1100+
map[string]string{
1101+
"canary.enabled": "true",
1102+
"canary.replicaCount": "6",
1103+
"canary.containerImage.repository": "nginx",
1104+
"canary.containerImage.tag": "1.16.0",
1105+
"horizontalPodAutoscaler.enabled": "true",
1106+
},
1107+
)
1108+
assert.EqualValues(t, 6, *deployment.Spec.Replicas)
1109+
}

0 commit comments

Comments
 (0)