From 5061077dc31c967d2c1c6bcded626096f5b6e940 Mon Sep 17 00:00:00 2001 From: Jun Date: Sat, 20 Feb 2021 03:45:41 +0800 Subject: [PATCH] Helm Chart: Add option to enable/disable flower (#14011) --- chart/README.md | 1 + chart/templates/NOTES.txt | 2 ++ chart/templates/flower/flower-deployment.yaml | 2 ++ chart/templates/flower/flower-ingress.yaml | 2 ++ .../flower/flower-networkpolicy.yaml | 2 ++ chart/templates/flower/flower-service.yaml | 2 ++ ...flower_authorization.py => test_flower.py} | 27 ++++++++++++++++--- chart/values.schema.json | 4 +++ chart/values.yaml | 3 +++ 9 files changed, 42 insertions(+), 3 deletions(-) rename chart/tests/{test_flower_authorization.py => test_flower.py} (73%) diff --git a/chart/README.md b/chart/README.md index 2d0c166114934..995984d2d4736 100644 --- a/chart/README.md +++ b/chart/README.md @@ -275,6 +275,7 @@ The following tables lists the configurable parameters of the Airflow chart and | `webserver.nodeSelector` | Node labels for pod assignment | `{}` | | `webserver.affinity` | Affinity labels for pod assignment | `{}` | | `webserver.tolerations` | Toleration labels for pod assignment | `[]` | +| `flower.enabled` | Enable flower | `true` | | `flower.nodeSelector` | Node labels for pod assignment | `{}` | | `flower.affinity` | Affinity labels for pod assignment | `{}` | | `flower.tolerations` | Toleration labels for pod assignment | `[]` | diff --git a/chart/templates/NOTES.txt b/chart/templates/NOTES.txt index afca72a903e2a..189442193951a 100644 --- a/chart/templates/NOTES.txt +++ b/chart/templates/NOTES.txt @@ -31,7 +31,9 @@ Flower dashboard: http{{ if .Values.ingress.flower.tls.enabled }}s{{ end }} You can now access your dashboard(s) by executing the following command(s) and visiting the corresponding port at localhost in your browser: Airflow dashboard: kubectl port-forward svc/{{ .Release.Name }}-webserver {{ .Values.ports.airflowUI }}:{{ .Values.ports.airflowUI }} --namespace {{ .Release.Namespace }} +{{- if .Values.flower.enabled }} {{- if or (eq .Values.executor "CeleryExecutor") (eq .Values.executor "CeleryKubernetesExecutor")}} Flower dashboard: kubectl port-forward svc/{{ .Release.Name }}-flower {{ .Values.ports.flowerUI }}:{{ .Values.ports.flowerUI }} --namespace {{ .Release.Namespace }} {{- end }} {{- end }} +{{- end }} diff --git a/chart/templates/flower/flower-deployment.yaml b/chart/templates/flower/flower-deployment.yaml index 0697fdbf4be77..e346e730c29b4 100644 --- a/chart/templates/flower/flower-deployment.yaml +++ b/chart/templates/flower/flower-deployment.yaml @@ -18,6 +18,7 @@ ################################ ## Airflow Flower Deployment ################################# +{{- if .Values.flower.enabled }} {{- if or (eq .Values.executor "CeleryExecutor") (eq .Values.executor "CeleryKubernetesExecutor") }} {{- $nodeSelector := or .Values.flower.nodeSelector .Values.nodeSelector }} {{- $affinity := or .Values.flower.affinity .Values.affinity }} @@ -121,3 +122,4 @@ spec: configMap: name: {{ template "airflow_config" . }} {{- end }} +{{- end }} diff --git a/chart/templates/flower/flower-ingress.yaml b/chart/templates/flower/flower-ingress.yaml index 77bbeaa313dea..754494cf6b8a4 100644 --- a/chart/templates/flower/flower-ingress.yaml +++ b/chart/templates/flower/flower-ingress.yaml @@ -18,6 +18,7 @@ ################################ ## Airflow Flower Ingress ################################# +{{- if .Values.flower.enabled }} {{- if and .Values.ingress.enabled (or (eq .Values.executor "CeleryExecutor") (eq .Values.executor "CeleryKubernetesExecutor")) }} apiVersion: networking.k8s.io/v1beta1 kind: Ingress @@ -52,3 +53,4 @@ spec: host: {{ .Values.ingress.flower.host }} {{- end }} {{- end }} +{{- end }} diff --git a/chart/templates/flower/flower-networkpolicy.yaml b/chart/templates/flower/flower-networkpolicy.yaml index c5633962c113d..3518338c6d4c1 100644 --- a/chart/templates/flower/flower-networkpolicy.yaml +++ b/chart/templates/flower/flower-networkpolicy.yaml @@ -18,6 +18,7 @@ ################################ ## Airflow Flower NetworkPolicy ################################# +{{- if .Values.flower.enabled }} {{- $celery_executors := list "CeleryExecutor" "CeleryKubernetesExecutor"}} {{- if and .Values.networkPolicies.enabled (has .Values.executor $celery_executors) }} apiVersion: networking.k8s.io/v1 @@ -50,3 +51,4 @@ spec: port: {{ .Values.ports.flowerUI }} {{- end }} {{- end }} +{{- end }} diff --git a/chart/templates/flower/flower-service.yaml b/chart/templates/flower/flower-service.yaml index b723a122537bb..bdd7d62621007 100644 --- a/chart/templates/flower/flower-service.yaml +++ b/chart/templates/flower/flower-service.yaml @@ -18,6 +18,7 @@ ################################ ## Airflow Flower Service Component ################################# +{{- if .Values.flower.enabled }} {{- if or (eq .Values.executor "CeleryExecutor") (eq .Values.executor "CeleryKubernetesExecutor") }} kind: Service apiVersion: v1 @@ -44,3 +45,4 @@ spec: port: {{ .Values.ports.flowerUI }} targetPort: {{ .Values.ports.flowerUI }} {{- end }} +{{- end }} diff --git a/chart/tests/test_flower_authorization.py b/chart/tests/test_flower.py similarity index 73% rename from chart/tests/test_flower_authorization.py rename to chart/tests/test_flower.py index 4ef4db96f3427..1a10e10b951b7 100644 --- a/chart/tests/test_flower_authorization.py +++ b/chart/tests/test_flower.py @@ -15,14 +15,35 @@ # specific language governing permissions and limitations # under the License. -import unittest - import jmespath +import pytest from tests.helm_template_generator import render_chart -class FlowerAuthorizationTest(unittest.TestCase): +class TestFlower: + @pytest.mark.parametrize( + "executor,flower_enabled,created", + [ + ("CeleryExecutor", False, False), + ("CeleryKubernetesExecutor", False, False), + ("KubernetesExecutor", False, False), + ("CeleryExecutor", True, True), + ("CeleryKubernetesExecutor", True, True), + ("KubernetesExecutor", True, False), + ], + ) + def test_create_flower(self, executor, flower_enabled, created): + docs = render_chart( + values={"executor": executor, "flower": {"enabled": flower_enabled}}, + show_only=["templates/flower/flower-deployment.yaml"], + ) + + assert bool(docs) is created + if created: + assert "RELEASE-NAME-flower" == jmespath.search("metadata.name", docs[0]) + assert "flower" == jmespath.search("spec.template.spec.containers[0].name", docs[0]) + def test_should_create_flower_deployment_with_authorization(self): docs = render_chart( values={ diff --git a/chart/values.schema.json b/chart/values.schema.json index 3349c6a232baa..3544adb2331dc 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -884,6 +884,10 @@ "type": "object", "additionalProperties": false, "properties": { + "enabled": { + "description": "Enable flower.", + "type": "boolean" + }, "extraNetworkPolicies": { "description": "Additional network policies as needed.", "type": "array" diff --git a/chart/values.yaml b/chart/values.yaml index 764fdfd6abda0..ce567c1c60029 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -468,6 +468,9 @@ webserver: # Flower settings flower: + # Enable flower. + # If True, and using CeleryExecutor/CeleryKubernetesExecutor, will deploy flower app. + enabled: true # Additional network policies as needed extraNetworkPolicies: [] resources: {}