-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[simple-app] Completely refactor the ingress/virtualService handling (#…
…11) **What did I want?** The existing `Ingress` and `VirtualService` handling was confusing and inconsistent. I wanted to simplify it - by making an opinionated decision about the "Standard" resource configuration that we should use. **What did I do?** 1. Refactored the `Ingress` template so that the HTTP rules were hard-coded rather than using big nested strings that are then run through `tpl`. The new opinionated framework more closely matches what we do in our normal ALBs. This also just makes the template _much_ easier to understand and document. If a user needs a custom Ingress, they can create it on their own. 2. Refactored the `VirtualService` template to also be highly opinionated and favor a very simple single-service routing model. Custom `VirtualService` resources can be defined by the user if they need one. 3. Renamed the `ingressGateway` top level values key to `virtualService` to more accurately reflect the resource that it is configuring. 4. Removed unnecessary `service.port` parameters because we use the `ports[]` list instead anyways. Even I forgot what that value was being used for (hint: it was just used for a test) so it was clearly confusing. 5. Improved the test-suite by adding in some handling of connection-refused errors - this is because the test-container starts up faster than the service container does, and we were seeing random race condition failures.
- Loading branch information
Showing
10 changed files
with
166 additions
and
107 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
NAMESPACE := simple-app | ||
|
||
include ../../contrib/Helm.mk | ||
include ../../contrib/Testing.mk |
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 |
---|---|---|
@@ -1,45 +1,49 @@ | ||
{{- if .Values.ingress.enabled -}} | ||
{{- $fullName := include "simple-app.fullname" . -}} | ||
{{- $svcPort := .Values.service.port -}} | ||
{{- $fullName := include "simple-app.fullname" . }} | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: | ||
{{- include "simple-app.labels" . | nindent 4 }} | ||
{{- with .Values.ingress.annotations }} | ||
annotations: | ||
{{- with .Values.ingress.annotations }} | ||
{{- toYaml . | nindent 4 }} | ||
{{- end }} | ||
{{- end }} | ||
{{- if .Values.ingress.sslRedirect }} | ||
alb.ingress.kubernetes.io/actions.ssl-redirect: >- | ||
{ | ||
"Type": "redirect", | ||
"RedirectConfig": { | ||
"Protocol": "HTTPS", | ||
"Port": "443", | ||
"StatusCode": "HTTP_301" | ||
} | ||
} | ||
{{- end }} | ||
spec: | ||
rules: | ||
{{- range .Values.ingress.hosts }} | ||
- host: {{ .host | quote }} | ||
- host: {{ tpl .Values.ingress.host . | quote }} | ||
http: | ||
paths: | ||
{{- /* | ||
|
||
The ssl-redirect action must be the first action in the list, if | ||
we're going to use it. It is combined with the the | ||
"alb.ingress.kubernetes.io/actions.ssl-redirect" annotation to do | ||
ALB-level HTTP->HTTPS routing. | ||
|
||
*/}} | ||
{{- if .sslRedirect }} | ||
- path: {{ .path }} | ||
pathType: {{ .pathType }} | ||
- path: {{ .Values.ingress.path }} | ||
pathType: {{ .Values.ingress.pathType }} | ||
backend: | ||
service: | ||
name: ssl-redirect | ||
name: {{ $fullName }} | ||
port: | ||
name: use-annotation | ||
{{- end }} | ||
- path: {{ .path }} | ||
pathType: {{ .pathType }} | ||
{{- if .Values.ingress.port }} | ||
number: {{ .Values.ingress.port }} | ||
{{- else }} | ||
name: {{ .Values.ingress.portName }} | ||
{{- end }} | ||
{{- if .Values.ingress.sslRedirect }} | ||
- path: {{ .Values.ingress.path }} | ||
pathType: {{ .Values.ingress.pathType }} | ||
backend: | ||
service: | ||
name: {{ $fullName }} | ||
name: ssl-redirect | ||
port: | ||
number: {{ $svcPort }} | ||
{{- end }} | ||
name: use-annotation | ||
{{- 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
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 |
---|---|---|
@@ -1,25 +1,36 @@ | ||
{{- if .Values.ingressGateway.enabled }} | ||
{{- if .Values.virtualService.enabled }} | ||
{{- $global := . }} | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: {{ include "simple-app.fullname" . }} | ||
labels: | ||
{{- include "simple-app.labels" . | nindent 4 }} | ||
{{- with .Values.ingressGateway.annotations }} | ||
{{- with .Values.virtualService.annotations }} | ||
annotations: | ||
{{- toYaml . | nindent 4 }} | ||
{{- end }} | ||
spec: | ||
hosts: | ||
{{- tpl .Values.ingressGateway.hosts . | nindent 4 }} | ||
gateways: | ||
- {{ .Values.ingressGateway.namespace }}/{{ .Values.ingressGateway.gateway }} | ||
{{- if .Values.ingressGateway.http }} | ||
- {{ .Values.virtualService.namespace }}/{{ .Values.virtualService.gateway }} | ||
hosts: | ||
{{- range .Values.virtualService.hosts }} | ||
- {{ tpl . $global | quote }} | ||
{{- end }} | ||
{{- /* https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRoute */}} | ||
http: | ||
{{- tpl .Values.ingressGateway.http . | nindent 4 }} | ||
{{- end }} | ||
{{- if .Values.ingressGateway.tls }} | ||
- match: | ||
{{- /* https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPMatchRequest */}} | ||
- uri: | ||
prefix: {{ .Values.virtualService.path }} | ||
{{- /* https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRouteDestination */}} | ||
route: | ||
- destination: | ||
host: {{ include "simple-app.fullname" . }} | ||
port: | ||
number: {{ .Values.virtualService.port }} | ||
{{- with .Values.virtualService.tls }} | ||
tls: | ||
{{- tpl .Values.ingressGateway.tls . | nindent 4 }} | ||
{{- tpl . $global | nindent 4 }} | ||
{{- 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
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,9 @@ | ||
# For local development, we turn on the Ingress controller and set up a simple | ||
# local ingress. | ||
ingress: | ||
# -- Enable local ingress for local development. | ||
enabled: true | ||
|
||
# -- Disable the SSL-Redirect explicitly because it only applies to | ||
# ALB-ingress controllers. | ||
sslRedirect: false |
Oops, something went wrong.