Skip to content

Commit

Permalink
Ability to access http k8s via multiple hostnames
Browse files Browse the repository at this point in the history
Add support for accessing the airflow ui and the flower ui (if
applicable) from multiple hostnames when install via helm chart onto a
kubernetes cluster.

closes: apache#18216.
  • Loading branch information
fredthomsen committed Sep 17, 2021
1 parent 11621ce commit a1ff12a
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 25 deletions.
9 changes: 8 additions & 1 deletion chart/UPDATING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ Run ``helm repo update`` before upgrading the chart to the latest version.
Airflow Helm Chart 1.2.0 (dev)
------------------------------

Default Airflow version is updated to ``2.1.2``
``ingress.web.host`` and ``ingress.flower.host`` parameters have been renamed and data type changed
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

``ingress.web.host`` and ``ingress.flower.host`` parameters have been renamed to ``ingress.web.hosts`` and ``ingress.flower.hosts``, respectively. Their types have been changed from a string to an array of strings.

The old parameter names will continue to work, however support for them will be removed in a future release so please update your values file.

Default Airflow version is updated to ``2.1.3``
"""""""""""""""""""""""""""""""""""""""""""""""

The default Airflow version that is installed with the Chart is now ``2.1.3``, previously it was ``2.1.2``.
Expand Down
26 changes: 24 additions & 2 deletions chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,31 @@ Your release is named {{ .Release.Name }}.
{{- if .Values.ingress.enabled }}
You can now access your service(s) by following defined Ingress urls:

Airflow Webserver: http{{ if .Values.ingress.web.tls.enabled }}s{{ end }}://{{ .Values.ingress.web.host }}{{ .Values.ingress.web.path }}/
{{- if .Values.ingress.web.host }}

DEPRECATION WARNING:
`ingress.web.host` has been renamed to `ingress.web.hosts` and is now an array.
Please change your values as support for the old name will be dropped in a future release.

{{- end }}

{{- if .Values.ingress.flower.host }}

DEPRECATION WARNING:
`ingress.flower.host` has been renamed to `ingress.flower.hosts` and is now an array.
Please change your values as support for the old name will be dropped in a future release.

{{- end }}

Airflow Webserver:
{{- range .Values.ingress.web.hosts | default (list .Values.ingress.web.host) }}
http{{ if $.Values.ingress.web.tls.enabled }}s{{ end }}://{{ . }}{{ $.Values.ingress.web.path }}/
{{- end }}
{{- if or (eq .Values.executor "CeleryExecutor") (eq .Values.executor "CeleryKubernetesExecutor") }}
Flower dashboard: http{{ if .Values.ingress.flower.tls.enabled }}s{{ end }}://{{ .Values.ingress.flower.host }}{{ .Values.ingress.flower.path }}/
Flower dashboard:
{{- range .Values.ingress.flower.hosts }}
http{{ if $.Values.ingress.flower.tls.enabled }}s{{ end }}://{{ . }}{{ $.Values.ingress.flower.path }}/
{{- end }}
{{- end }}
{{- else }}
You can now access your dashboard(s) by executing the following command(s) and visiting the corresponding port at localhost in your browser:
Expand Down
20 changes: 12 additions & 8 deletions chart/templates/flower/flower-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,35 @@ spec:
{{- if .Values.ingress.flower.tls.enabled }}
tls:
- hosts:
- {{ .Values.ingress.flower.host }}
{{- if .Values.ingress.flower.tls.enabled }}
{{- .Values.ingress.flower.hosts | default (list .Values.ingress.flower.host) | toYaml | nindent 8 }}
{{- end }}
secretName: {{ .Values.ingress.flower.tls.secretName }}
{{- end }}
rules:
{{- range .Values.ingress.flower.hosts | default (list .Values.ingress.flower.host) }}
- http:
paths:
- backend:
{{- if $apiIsStable }}
service:
name: {{ .Release.Name }}-flower
name: {{ $.Release.Name }}-flower
port:
name: flower-ui
{{- else }}
serviceName: {{ .Release.Name }}-flower
serviceName: {{ $.Release.Name }}-flower
servicePort: flower-ui
{{- end }}
{{- if .Values.ingress.flower.path }}
path: {{ .Values.ingress.flower.path }}
{{- if $.Values.ingress.flower.path }}
path: {{ $.Values.ingress.flower.path }}
{{- if $apiIsStable }}
pathType: {{ .Values.ingress.flower.pathType }}
pathType: {{ $.Values.ingress.flower.pathType }}
{{- end }}
{{- end }}
{{- if .Values.ingress.flower.host }}
host: {{ .Values.ingress.flower.host }}
{{- if . }}
host: {{ . | quote }}
{{- end }}
{{- end }}
{{- if and .Values.ingress.flower.ingressClassName $apiIsStable }}
ingressClassName: {{ .Values.ingress.flower.ingressClassName }}
{{- end }}
Expand Down
24 changes: 14 additions & 10 deletions chart/templates/webserver/webserver-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ spec:
{{- if .Values.ingress.web.tls.enabled }}
tls:
- hosts:
- {{ .Values.ingress.web.host }}
{{- if .Values.ingress.web.tls.enabled }}
{{- .Values.ingress.web.hosts | default (list .Values.ingress.web.host) | toYaml | nindent 8 }}
{{- end }}
secretName: {{ .Values.ingress.web.tls.secretName }}
{{- end }}
rules:
{{- range .Values.ingress.web.hosts | default (list .Values.ingress.web.host) }}
- http:
paths:
{{- range .Values.ingress.web.precedingPaths }}
{{- range $.Values.ingress.web.precedingPaths }}
- path: {{ .path }}
{{- if $apiIsStable }}
pathType: {{ .pathType }}
Expand All @@ -67,20 +70,20 @@ spec:
- backend:
{{- if $apiIsStable }}
service:
name: {{ .Release.Name }}-webserver
name: {{ $.Release.Name }}-webserver
port:
name: airflow-ui
{{- else }}
serviceName: {{ .Release.Name }}-webserver
serviceName: {{ $.Release.Name }}-webserver
servicePort: airflow-ui
{{- end }}
{{- if .Values.ingress.web.path }}
path: {{ .Values.ingress.web.path }}
{{- if $.Values.ingress.web.path }}
path: {{ $.Values.ingress.web.path }}
{{- if $apiIsStable }}
pathType: {{ .Values.ingress.web.pathType }}
pathType: {{ $.Values.ingress.web.pathType }}
{{- end }}
{{- end }}
{{- range .Values.ingress.web.succeedingPaths }}
{{- range $.Values.ingress.web.succeedingPaths }}
- path: {{ .path }}
{{- if $apiIsStable }}
pathType: {{ .pathType }}
Expand All @@ -96,9 +99,10 @@ spec:
servicePort: {{ .servicePort }}
{{- end }}
{{- end }}
{{- if .Values.ingress.web.host }}
host: {{ .Values.ingress.web.host }}
{{- if . }}
host: {{ . | quote }}
{{- end }}
{{- end }}
{{- if and .Values.ingress.web.ingressClassName $apiIsStable }}
ingressClassName: {{ .Values.ingress.web.ingressClassName }}
{{- end }}
Expand Down
50 changes: 50 additions & 0 deletions chart/tests/test_ingress_flower.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,53 @@ def test_should_set_ingress_class_name(self):
show_only=["templates/flower/flower-ingress.yaml"],
)
assert "foo" == jmespath.search("spec.ingressClassName", docs[0])

def test_should_ingress_hosts_have_priority_over_host(self):
docs = render_chart(
values={
"ingress": {
"enabled": True,
"flower": {
"tls": {"enabled": True, "secretName": "supersecret"},
"hosts": ["*.a-host", "b-host"],
"host": "old-host",
},
}
},
show_only=["templates/flower/flower-ingress.yaml"],
)
assert (
["*.a-host", "b-host"]
== jmespath.search("spec.rules[*].host", docs[0])
== jmespath.search("spec.tls[0].hosts", docs[0])
)

def test_should_ingress_host_still_work(self):
docs = render_chart(
values={
"ingress": {
"enabled": True,
"flower": {
"tls": {"enabled": True, "secretName": "supersecret"},
"host": "old-host",
},
}
},
show_only=["templates/flower/flower-ingress.yaml"],
)
assert (
["old-host"]
== jmespath.search("spec.rules[*].host", docs[0])
== jmespath.search("spec.tls[0].hosts", docs[0])
)

def test_should_ingress_host_entry_not_exist(self):
docs = render_chart(
values={
"ingress": {
"enabled": True,
}
},
show_only=["templates/flower/flower-ingress.yaml"],
)
assert not jmespath.search("spec.rules[*].host", docs[0])
50 changes: 50 additions & 0 deletions chart/tests/test_ingress_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,53 @@ def test_should_set_ingress_class_name(self):
show_only=["templates/webserver/webserver-ingress.yaml"],
)
assert "foo" == jmespath.search("spec.ingressClassName", docs[0])

def test_should_ingress_hosts_have_priority_over_host(self):
docs = render_chart(
values={
"ingress": {
"enabled": True,
"web": {
"tls": {"enabled": True, "secretName": "supersecret"},
"hosts": ["*.a-host", "b-host"],
"host": "old-host",
},
}
},
show_only=["templates/webserver/webserver-ingress.yaml"],
)
assert (
["*.a-host", "b-host"]
== jmespath.search("spec.rules[*].host", docs[0])
== jmespath.search("spec.tls[0].hosts", docs[0])
)

def test_should_ingress_host_still_work(self):
docs = render_chart(
values={
"ingress": {
"enabled": True,
"web": {
"tls": {"enabled": True, "secretName": "supersecret"},
"host": "old-host",
},
}
},
show_only=["templates/webserver/webserver-ingress.yaml"],
)
assert (
["old-host"]
== jmespath.search("spec.rules[*].host", docs[0])
== jmespath.search("spec.tls[0].hosts", docs[0])
)

def test_should_ingress_host_entry_not_exist(self):
docs = render_chart(
values={
"ingress": {
"enabled": True,
}
},
show_only=["templates/webserver/webserver-ingress.yaml"],
)
assert not jmespath.search("spec.rules[*].host", docs[0])
20 changes: 18 additions & 2 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,18 @@
"default": "ImplementationSpecific"
},
"host": {
"description": "The hostname for the web Ingress.",
"description": "The hostname for the web Ingress. (Deprecated - renamed to `ingress.web.hosts`)",
"type": "string",
"default": ""
},
"hosts": {
"description": "The hostnames for the web Ingress.",
"type": "array",
"default": [],
"items": {
"type": "string"
}
},
"ingressClassName": {
"description": "The Ingress Class for the web Ingress.",
"type": "string",
Expand Down Expand Up @@ -196,10 +204,18 @@
"default": "ImplementationSpecific"
},
"host": {
"description": "The hostname for the flower Ingress.",
"description": "The hostname for the flower Ingress. (Deprecated - renamed to `ingress.flower.hosts`)",
"type": "string",
"default": ""
},
"hosts": {
"description": "The hostnames for the flower Ingress.",
"type": "array",
"default": [],
"items": {
"type": "string"
}
},
"ingressClassName": {
"description": "The Ingress Class for the flower Ingress.",
"type": "string",
Expand Down
10 changes: 8 additions & 2 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ ingress:
# The pathType for the above path (used only with Kubernetes v1.19 and above)
pathType: "ImplementationSpecific"

# The hostname for the web Ingress
# The hostname for the web Ingress (Deprecated - renamed to `ingress.web.hosts`)
host: ""

# The hostnames for the web Ingress
hosts: []

# The Ingress Class for the web Ingress (used only with Kubernetes v1.19 and above)
ingressClassName: ""

Expand Down Expand Up @@ -139,9 +142,12 @@ ingress:
# The pathType for the above path (used only with Kubernetes v1.19 and above)
pathType: "ImplementationSpecific"

# The hostname for the flower Ingress
# The hostname for the flower Ingress (Deprecated - renamed to `ingress.flower.hosts`)
host: ""

# The hostnames for the flower Ingress
hosts: []

# The Ingress Class for the flower Ingress (used only with Kubernetes v1.19 and above)
ingressClassName: ""

Expand Down

0 comments on commit a1ff12a

Please sign in to comment.