This is an automated email from the ASF dual-hosted git repository. kaxilnaik pushed a commit to branch v1-10-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 753f79d11343815876546edf06775b7b24a72c0d Author: Daniel Imberman <[email protected]> AuthorDate: Tue Nov 24 15:13:23 2020 -0800 Allow webserver to read pod logs directly (#12598) * Allow webserver to read pod logs directly For users who are testing the KubernetesExecutor, allows users to read pod logs via the Kubernetes API. Worth noting that these logs will only be accessible while the worker is running. * fix tests (cherry picked from commit 9f28e416dbc6374dc9c7115304731a7bc0b4bfa9) --- chart/templates/rbac/pod-log-reader-role.yaml | 56 ++++++++++++++++++++++ .../templates/rbac/pod-log-reader-rolebinding.yaml | 53 ++++++++++++++++++++ chart/tests/test_basic_helm_chart.py | 4 +- chart/values.schema.json | 4 ++ chart/values.yaml | 1 + 5 files changed, 117 insertions(+), 1 deletion(-) diff --git a/chart/templates/rbac/pod-log-reader-role.yaml b/chart/templates/rbac/pod-log-reader-role.yaml new file mode 100644 index 0000000..72f5e35 --- /dev/null +++ b/chart/templates/rbac/pod-log-reader-role.yaml @@ -0,0 +1,56 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +################################ +## Airflow Pod Reader Role +################################# +{{- if and .Values.rbacEnabled .Values.webserver.allowPodLogReading }} +{{- if .Values.multiNamespaceMode }} +kind: ClusterRole +{{- else }} +kind: Role +{{- end }} +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ .Release.Name }}-pod-log-reader-role +{{- if not .Values.multiNamespaceMode }} + namespace: {{ .Release.Namespace }} +{{- end }} + labels: + tier: airflow + release: {{ .Release.Name }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + heritage: {{ .Release.Service }} +{{- with .Values.labels }} +{{ toYaml . | indent 4 }} +{{- end }} +rules: + - apiGroups: + - "" + resources: + - "pods" + verbs: + - "list" + - "get" + - "watch" + - apiGroups: + - "" + resources: + - "pods/log" + verbs: + - "get" +{{- end }} diff --git a/chart/templates/rbac/pod-log-reader-rolebinding.yaml b/chart/templates/rbac/pod-log-reader-rolebinding.yaml new file mode 100644 index 0000000..25371eb --- /dev/null +++ b/chart/templates/rbac/pod-log-reader-rolebinding.yaml @@ -0,0 +1,53 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +################################ +## Airflow Pod Reader Role Binding +################################# +{{- if and .Values.rbacEnabled .Values.webserver.allowPodLogReading }} +{{- if .Values.multiNamespaceMode }} +kind: ClusterRoleBinding +{{- else }} +kind: RoleBinding +{{- end }} +apiVersion: rbac.authorization.k8s.io/v1 +metadata: +{{- if not .Values.multiNamespaceMode }} + namespace: {{ .Release.Namespace }} +{{- end }} + name: {{ .Release.Name }}-pod-log-reader-rolebinding + labels: + tier: airflow + release: {{ .Release.Name }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + heritage: {{ .Release.Service }} +{{- with .Values.labels }} +{{ toYaml . | indent 4 }} +{{- end }} +roleRef: + apiGroup: rbac.authorization.k8s.io +{{- if .Values.multiNamespaceMode }} + kind: ClusterRole +{{- else }} + kind: Role +{{- end }} + name: {{ .Release.Name }}-pod-log-reader-role +subjects: + - kind: ServiceAccount + name: {{ .Release.Name }}-webserver + namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/chart/tests/test_basic_helm_chart.py b/chart/tests/test_basic_helm_chart.py index 26ea1c1..af66267 100644 --- a/chart/tests/test_basic_helm_chart.py +++ b/chart/tests/test_basic_helm_chart.py @@ -22,7 +22,7 @@ import jmespath from tests.helm_template_generator import render_chart -OBJECT_COUNT_IN_BASIC_DEPLOYMENT = 22 +OBJECT_COUNT_IN_BASIC_DEPLOYMENT = 24 class TestBaseChartTest(unittest.TestCase): @@ -50,7 +50,9 @@ class TestBaseChartTest(unittest.TestCase): ('Secret', 'TEST-BASIC-airflow-result-backend'), ('ConfigMap', 'TEST-BASIC-airflow-config'), ('Role', 'TEST-BASIC-pod-launcher-role'), + ('Role', 'TEST-BASIC-pod-log-reader-role'), ('RoleBinding', 'TEST-BASIC-pod-launcher-rolebinding'), + ('RoleBinding', 'TEST-BASIC-pod-log-reader-rolebinding'), ('Service', 'TEST-BASIC-postgresql-headless'), ('Service', 'TEST-BASIC-postgresql'), ('Service', 'TEST-BASIC-statsd'), diff --git a/chart/values.schema.json b/chart/values.schema.json index f1d8271..3248b66 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -688,6 +688,10 @@ "type": "object", "additionalProperties": false, "properties": { + "allowPodLogReading": { + "description": "Allow webserver to read k8s pod logs. Useful when you don't have an external log store.", + "type": "boolean" + }, "livenessProbe": { "description": "Liveness probe configuration.", "type": "object", diff --git a/chart/values.yaml b/chart/values.yaml index d84a785..38f26e5 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -387,6 +387,7 @@ scheduler: # Airflow webserver settings webserver: + allowPodLogReading: true livenessProbe: initialDelaySeconds: 15 timeoutSeconds: 30
