Skip to content

Commit

Permalink
Merge pull request hashicorp#60 from hashicorp/bugfix/hashicorpgh-58
Browse files Browse the repository at this point in the history
Provide a valid maxUnavailable value when using a single replica
  • Loading branch information
Rebecca Zanzig authored Nov 12, 2018
2 parents 57b479e + cf76a2d commit 859d8ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
5 changes: 4 additions & 1 deletion templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ Expand the name of the chart.
{{/*
Compute the maximum number of unavailable replicas for the PodDisruptionBudget.
This defaults to (n/2)-1 where n is the number of members of the server cluster.
Add a special case for replicas=1, where it should default to 0 as well.
*/}}
{{- define "consul.pdb.maxUnavailable" -}}
{{- if .Values.server.disruptionBudget.maxUnavailable -}}
{{- if eq (int .Values.server.replicas) 1 -}}
{{ 0 }}
{{- else if .Values.server.disruptionBudget.maxUnavailable -}}
{{ .Values.server.disruptionBudget.maxUnavailable -}}
{{- else -}}
{{- ceil (sub (div (int .Values.server.replicas) 2) 1) -}}
Expand Down
28 changes: 23 additions & 5 deletions test/unit/server-disruptionbudget.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "server/DisruptionBudget: enable with global.enabled false" {
@test "server/DisruptionBudget: enabled with global.enabled=false" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-disruptionbudget.yaml \
Expand All @@ -22,7 +22,7 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "server/DisruptionBudget: disable with server.enabled" {
@test "server/DisruptionBudget: disabled with server.enabled=false" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-disruptionbudget.yaml \
Expand All @@ -32,7 +32,7 @@ load _helpers
[ "${actual}" = "false" ]
}

@test "server/DisruptionBudget: disable with server.disruptionBudget.enabled" {
@test "server/DisruptionBudget: disabled with server.disruptionBudget.enabled=false" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-disruptionbudget.yaml \
Expand All @@ -42,7 +42,7 @@ load _helpers
[ "${actual}" = "false" ]
}

@test "server/DisruptionBudget: disable with global.enabled" {
@test "server/DisruptionBudget: disabled with global.enabled=false" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-disruptionbudget.yaml \
Expand All @@ -52,7 +52,10 @@ load _helpers
[ "${actual}" = "false" ]
}

@test "server/DisruptionBudget: correct maxUnavailable with n=3" {
#--------------------------------------------------------------------
# maxUnavailable

@test "server/DisruptionBudget: correct maxUnavailable with replicas=3" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-disruptionbudget.yaml \
Expand All @@ -61,3 +64,18 @@ load _helpers
yq '.spec.maxUnavailable' | tee /dev/stderr)
[ "${actual}" = "0" ]
}

@test "server/DisruptionBudget: correct maxUnavailable with replicas=1" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-disruptionbudget.yaml \
--set 'server.replicas=1' \
. | tee /dev/stderr |
yq '.spec.maxUnavailable' | tee /dev/stderr)
[ "${actual}" = "0" ]
}

# Note: It is not possible to test anything but the default behavior of the
# maxUnavailable definition in the _helpers.tpl with the current test setup
# because the `--set` flag overrides values AFTER they're been run through
# the helper functions.

0 comments on commit 859d8ed

Please sign in to comment.