Skip to content

Commit

Permalink
Avoid setting replicase while HPA is enabled (#181)
Browse files Browse the repository at this point in the history
* fix: avoid setting replicase while HPA is enabled

* fix: add tests
  • Loading branch information
mateimicu authored Jan 8, 2024
1 parent 5675e6d commit 4fc33d4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion charts/k8s-service/templates/_deployment_spec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ metadata:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
replicas: {{ if .isCanary }}{{ .Values.canary.replicaCount | default 1 }}{{ else }}{{ .Values.replicaCount }}{{ end }}
{{- if .isCanary }}
replicas: {{ .Values.canary.replicaCount | default 1 }}
{{ else }}
{{- if not .Values.horizontalPodAutoscaler.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
{{- end }}
{{- if .Values.deploymentStrategy.enabled }}
strategy:
type: {{ .Values.deploymentStrategy.type }}
Expand Down
30 changes: 30 additions & 0 deletions test/k8s_service_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,3 +1077,33 @@ func TestK8SServiceClusterIP(t *testing.T) {
})
}
}

// Test that setting horizontalPodAutoscaler.enabled = true will cause the helm template to not render replicas
func TestK8SServiceServiceHorizontalPodAutoscalerDoesNotConfigureReplicas(t *testing.T) {
t.Parallel()

deployment := renderK8SServiceDeploymentWithSetValues(
t,
map[string]string{
"horizontalPodAutoscaler.enabled": "true",
"replicaCount": "3",
},
)
assert.Equal(t, (*int32)(nil), deployment.Spec.Replicas)
}

// Test that setting horizontalPodAutoscaler = true will not affect the canary
func TestK8SServiceServiceHorizontalPodAutoscalerDoesNotAffectCanaryConfiguration(t *testing.T) {
t.Parallel()
deployment := renderK8SServiceCanaryDeploymentWithSetValues(
t,
map[string]string{
"canary.enabled": "true",
"canary.replicaCount": "6",
"canary.containerImage.repository": "nginx",
"canary.containerImage.tag": "1.16.0",
"horizontalPodAutoscaler.enabled": "true",
},
)
assert.EqualValues(t, 6, *deployment.Spec.Replicas)
}

0 comments on commit 4fc33d4

Please sign in to comment.