This repository was archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 385
Add ingress option #774
Merged
Merged
Add ingress option #774
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
31139b2
Add ingress option to UI service.
zinref 4cda884
Remove combination of enabling ingress.
zinref 0684f9e
Add changes to support https traffic to UI
a93a27d
Add annotations for new fields
79ff8a0
Update CHANGELOG
2ddc2fd
Code review suggestions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{{- if (and (or (and (ne (.Values.server.enabled | toString) "-") .Values.server.enabled) (and (eq (.Values.server.enabled | toString) "-") .Values.global.enabled)) (or (and (ne (.Values.ui.enabled | toString) "-") .Values.ui.enabled) (and (eq (.Values.ui.enabled | toString) "-") .Values.global.enabled)) (or (and (ne (.Values.ui.service.enabled | toString) "-") .Values.ui.service.enabled) (and (eq (.Values.ui.service.enabled | toString) "-") .Values.global.enabled))) }} | ||
{{- if (and (ne (.Values.ui.ingress.enabled | toString) "-") .Values.ui.ingress.enabled) }} | ||
{{- $serviceName := printf "%s-%s" (include "consul.fullname" .) "ui" -}} | ||
apiVersion: extensions/v1 | ||
kind: Ingress | ||
metadata: | ||
name: {{ template "consul.fullname" . }}-ingress | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
component: ui | ||
{{- if .Values.ui.ingress.annotations }} | ||
annotations: | ||
{{ tpl .Values.ui.ingress.annotations . | nindent 4 | trim }} | ||
{{- end}} | ||
spec: | ||
rules: | ||
{{ $global := .Values.global }} | ||
{{- range .Values.ui.ingress.hosts }} | ||
- host: {{ .host | quote }} | ||
http: | ||
paths: | ||
{{- range (.paths | default (list "/")) }} | ||
{{- if (or (not $global.tls.enabled) (not $global.tls.httpsOnly)) }} | ||
- backend: | ||
serviceName: {{ $serviceName }} | ||
servicePort: 80 | ||
path: {{ . }} | ||
{{- end }} | ||
{{- if $global.tls.enabled }} | ||
- backend: | ||
serviceName: {{ $serviceName }} | ||
servicePort: 443 | ||
path: {{ . }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end -}} | ||
{{- if .Values.ui.ingress.tls }} | ||
tls: | ||
{{- toYaml .Values.ui.ingress.tls | nindent 4 }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "ui/Ingress: disabled by default" { | ||
cd `chart_dir` | ||
assert_empty helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
. | ||
} | ||
|
||
@test "ui/Ingress: enable with ui.ingress.enabled" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "ui/Ingress: disable with ui.ingress.enabled" { | ||
cd `chart_dir` | ||
assert_empty helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=false' \ | ||
. | ||
} | ||
|
||
@test "ui/Ingress: disable with ui.ingress.enabled dash string" { | ||
cd `chart_dir` | ||
assert_empty helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=-' \ | ||
. | ||
} | ||
|
||
#-------------------------------------------------------------------- | ||
# hosts | ||
|
||
@test "ui/Ingress: no hosts by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.rules' | tee /dev/stderr) | ||
[ "${actual}" = "null" ] | ||
} | ||
|
||
@test "ui/Ingress: hosts can be set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
--set 'ui.ingress.hosts[0].host=foo.com' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.rules[0].host' | tee /dev/stderr) | ||
[ "${actual}" = "foo.com" ] | ||
} | ||
|
||
@test "ui/Ingress: exposes single port 80 when global.tls.enabled=false" { | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
--set 'global.tls.enabled=false' \ | ||
--set 'ui.ingress.hosts[0].host=foo.com' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.rules[0].http.paths[0].backend.servicePort' | tee /dev/stderr) | ||
[ "${actual}" = "80" ] | ||
} | ||
|
||
@test "ui/Ingress: exposes single port 443 when global.tls.enabled=true and global.tls.httpsOnly=true" { | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
--set 'global.tls.enabled=true' \ | ||
--set 'ui.ingress.hosts[0].host=foo.com' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.rules[0].http.paths[0].backend.servicePort' | tee /dev/stderr) | ||
[ "${actual}" = "443" ] | ||
} | ||
|
||
@test "ui/Ingress: exposes the port 80 when global.tls.enabled=true and global.tls.httpsOnly=false" { | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
--set 'global.tls.enabled=true' \ | ||
--set 'global.tls.httpsOnly=false' \ | ||
--set 'ui.ingress.hosts[0].host=foo.com' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.rules[0].http.paths[0].backend.servicePort' | tee /dev/stderr) | ||
[ "${actual}" = "80" ] | ||
} | ||
|
||
@test "ui/Ingress: exposes the port 443 when global.tls.enabled=true and global.tls.httpsOnly=false" { | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
--set 'global.tls.enabled=true' \ | ||
--set 'global.tls.httpsOnly=false' \ | ||
--set 'ui.ingress.hosts[0].host=foo.com' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.rules[0].http.paths[1].backend.servicePort' | tee /dev/stderr) | ||
[ "${actual}" = "443" ] | ||
} | ||
|
||
#-------------------------------------------------------------------- | ||
# tls | ||
|
||
@test "ui/Ingress: no tls by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.tls' | tee /dev/stderr) | ||
[ "${actual}" = "null" ] | ||
} | ||
|
||
@test "ui/Ingress: tls can be set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
--set 'ui.ingress.tls[0].hosts[0]=foo.com' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.tls[0].hosts[0]' | tee /dev/stderr) | ||
[ "${actual}" = "foo.com" ] | ||
} | ||
|
||
@test "ui/Ingress: tls with secret name can be set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
--set 'ui.ingress.tls[0].hosts[0]=sslexample.foo.com' \ | ||
--set 'ui.ingress.tls[0].secretName=testsecret-tls' \ | ||
. | tee /dev/stderr | | ||
yq -r '.spec.tls[0].secretName' | tee /dev/stderr) | ||
[ "${actual}" = "testsecret-tls" ] | ||
} | ||
|
||
#-------------------------------------------------------------------- | ||
# annotations | ||
|
||
@test "ui/Ingress: no annotations by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.annotations' | tee /dev/stderr) | ||
[ "${actual}" = "null" ] | ||
} | ||
|
||
@test "ui/Ingress: annotations can be set" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/ui-ingress.yaml \ | ||
--set 'ui.ingress.enabled=true' \ | ||
--set 'ui.ingress.annotations=foo: bar' \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.annotations.foo' | tee /dev/stderr) | ||
[ "${actual}" = "bar" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we tell them what secret to use? Do they need to use passthrough TLS if consul tls is enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So i realized in my tinkering that i hadn't tested the only TLS (https only enabled) options. ie, the 80 port was always open on the service. the ingress resource always performs TLS termination so we cant point traffic to 443 as the request that reached the service will always be HTTP. I guess it doesnt make sense for this PR to support port 443 in that case, and ill make the requisite changes.