Skip to content

Commit

Permalink
feat(ingress): Extra paths to prepend to the ingress host configurati…
Browse files Browse the repository at this point in the history
…on for annotation based services (#460)

Refs #361
  • Loading branch information
samjmarshall authored Apr 8, 2021
1 parent 6e46bcf commit bfbeba2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions templates/server-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{ template "vault.mode" . }}
{{- if ne .mode "external" }}
{{- if .Values.server.ingress.enabled -}}
{{- $extraPaths := .Values.server.ingress.extraPaths -}}
{{- $serviceName := include "vault.fullname" . -}}
{{- if and (eq .mode "ha" ) (and (eq (.Values.server.service.enabled | toString) "true" ) (eq (.Values.global.enabled | toString) "true")) }}
{{- $serviceName = printf "%s-%s" $serviceName "active" -}}
Expand Down Expand Up @@ -41,6 +42,9 @@ spec:
- host: {{ .host | quote }}
http:
paths:
{{ if $extraPaths }}
{{ toYaml $extraPaths | indent 10 }}
{{- end }}
{{- range (.paths | default (list "/")) }}
- path: {{ . }}
backend:
Expand Down
37 changes: 37 additions & 0 deletions test/unit/server-ingress.bats
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,43 @@ load _helpers

}

@test "server/ingress: extra paths prepend host configuration" {
cd `chart_dir`

local actual=$(helm template \
--show-only templates/server-ingress.yaml \
--set 'server.ingress.enabled=true' \
--set 'server.ingress.hosts[0].host=test.com' \
--set 'server.ingress.hosts[0].paths[0]=/' \
--set 'server.ingress.extraPaths[0].path=/annotation-service' \
--set 'server.ingress.extraPaths[0].backend.serviceName=ssl-redirect' \
. | tee /dev/stderr |
yq -r '.spec.rules[0].http.paths[0].backend.serviceName' | tee /dev/stderr)
[ "${actual}" = 'ssl-redirect' ]

local actual=$(helm template \
--show-only templates/server-ingress.yaml \
--set 'server.ingress.enabled=true' \
--set 'server.ingress.hosts[0].host=test.com' \
--set 'server.ingress.hosts[0].paths[0]=/' \
--set 'server.ingress.extraPaths[0].path=/annotation-service' \
--set 'server.ingress.extraPaths[0].backend.serviceName=ssl-redirect' \
. | tee /dev/stderr |
yq -r '.spec.rules[0].http.paths[0].path' | tee /dev/stderr)
[ "${actual}" = '/annotation-service' ]

local actual=$(helm template \
--show-only templates/server-ingress.yaml \
--set 'server.ingress.enabled=true' \
--set 'server.ingress.hosts[0].host=test.com' \
--set 'server.ingress.hosts[0].paths[0]=/' \
--set 'server.ingress.extraPaths[0].path=/annotation-service' \
--set 'server.ingress.extraPaths[0].backend.serviceName=ssl-redirect' \
. | tee /dev/stderr |
yq -r '.spec.rules[0].http.paths[1].path' | tee /dev/stderr)
[ "${actual}" = '/' ]
}

@test "server/ingress: labels gets added to object" {
cd `chart_dir`

Expand Down
7 changes: 6 additions & 1 deletion values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ server:
hosts:
- host: chart-example.local
paths: []

## Extra paths to prepend to the host configuration. This is useful when working with annotation based services.
extraPaths: []
# - path: /*
# backend:
# serviceName: ssl-redirect
# servicePort: use-annotation
tls: []
# - secretName: chart-example-tls
# hosts:
Expand Down

0 comments on commit bfbeba2

Please sign in to comment.