Skip to content

Commit

Permalink
Adding check for duplicate terminating gateways and ingress gateway n…
Browse files Browse the repository at this point in the history
…ames
  • Loading branch information
jmurret committed Mar 25, 2022
1 parent 8c2bbd3 commit e9da9f1
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions charts/consul/templates/ingress-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
{{- $defaults := .Values.ingressGateways.defaults }}
{{- $names := dict }}

{{- $gateways := .Values.ingressGateways.gateways }}
{{- range $outerIngressIndex, $outerIngressVal := $gateways }}

{{- range $innerIngressIndex, $innerIngressVal := $gateways }}
{{- if (and (ne $outerIngressIndex $innerIngressIndex) (eq $outerIngressVal.name $innerIngressVal.name)) }}
{{ fail "ingress gateways must have unique names" }}
{{ end -}}
{{ end -}}
{{ end -}}

{{- range .Values.ingressGateways.gateways }}

{{- $service := .service }}
Expand Down
16 changes: 16 additions & 0 deletions charts/consul/templates/terminating-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
{{- $defaults := .Values.terminatingGateways.defaults }}
{{- $names := dict }}

{{- $gateways := .Values.terminatingGateways.gateways }}
{{- range $outerTerminatingIndex, $outerTerminatingVal := $gateways }}

{{- range $innerTerminatingIndex, $innerTerminatingVal := $gateways }}
{{- if (and (ne $outerTerminatingIndex $innerTerminatingIndex) (eq $outerTerminatingVal.name $innerTerminatingVal.name)) }}
{{ fail "terminating gateways must have unique names" }}
{{ end -}}
{{ end -}}

{{- range $outerIngressIndex, $outerIngressVal := $root.Values.ingressGateways.gateways }}
{{- if (eq $outerTerminatingVal.name $outerIngressVal.name) }}
{{ fail "terminating gateways cannot have duplicate names of any ingress gateways" }}
{{ end -}}
{{ end -}}
{{ end -}}

{{- range .Values.terminatingGateways.gateways }}

{{- if empty .name }}
Expand Down
30 changes: 30 additions & 0 deletions charts/consul/test/unit/ingress-gateways-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ load _helpers
[[ "$output" =~ "clients must be enabled" ]]
}

@test "ingressGateways/Deployment: fails if there are duplicate gateway names" {
cd `chart_dir`
run helm template \
-s templates/ingress-gateways-deployment.yaml \
--set 'ingressGateways.enabled=true' \
--set 'ingressGateways.gateways[0].name=foo' \
--set 'ingressGateways.gateways[1].name=foo' \
--set 'connectInject.enabled=true' \
--set 'global.enabled=true' \
--set 'client.enabled=true' .
echo "status: $output"
[ "$status" -eq 1 ]
[[ "$output" =~ "ingress gateways must have unique names" ]]
}

@test "ingressGateways/Deployment: fails if a terminating gateway has the same name as an ingress gateway" {
cd `chart_dir`
run helm template \
-s templates/ingress-gateways-deployment.yaml \
--set 'terminatingGateways.enabled=true' \
--set 'ingressGateways.enabled=true' \
--set 'terminatingGateways.gateways[0].name=foo' \
--set 'ingressGateways.gateways[0].name=foo' \
--set 'connectInject.enabled=true' \
--set 'global.enabled=true' \
--set 'client.enabled=true' .
echo "status: $output"
[ "$status" -eq 1 ]
[[ "$output" =~ "terminating gateways cannot have duplicate names of any ingress gateways" ]]
}
#--------------------------------------------------------------------
# envoyImage

Expand Down
31 changes: 31 additions & 0 deletions charts/consul/test/unit/terminating-gateways-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,37 @@ load _helpers
[[ "$output" =~ "clients must be enabled" ]]
}

@test "terminatingGateways/Deployment: fails if there are duplicate gateway names" {
cd `chart_dir`
run helm template \
-s templates/terminating-gateways-deployment.yaml \
--set 'terminatingGateways.enabled=true' \
--set 'terminatingGateways.gateways[0].name=foo' \
--set 'terminatingGateways.gateways[1].name=foo' \
--set 'connectInject.enabled=true' \
--set 'global.enabled=true' \
--set 'client.enabled=true' .
echo "status: $output"
[ "$status" -eq 1 ]
[[ "$output" =~ "terminating gateways must have unique names" ]]
}

@test "terminatingGateways/Deployment: fails if a terminating gateway has the same name as an ingress gateway" {
cd `chart_dir`
run helm template \
-s templates/terminating-gateways-deployment.yaml \
--set 'terminatingGateways.enabled=true' \
--set 'ingressGateways.enabled=true' \
--set 'terminatingGateways.gateways[0].name=foo' \
--set 'ingressGateways.gateways[0].name=foo' \
--set 'connectInject.enabled=true' \
--set 'global.enabled=true' \
--set 'client.enabled=true' .
echo "status: $output"
[ "$status" -eq 1 ]
[[ "$output" =~ "terminating gateways cannot have duplicate names of any ingress gateways" ]]
}

#--------------------------------------------------------------------
# envoyImage

Expand Down

0 comments on commit e9da9f1

Please sign in to comment.