You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2024/03/06 14:48:13 UTC
(airflow) 31/31: Add Kubeconform pre-commit (#37920)
This is an automated email from the ASF dual-hosted git repository.
ephraimanierobi pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 761ba459e83363e53ef6a173f5d14934f4a9164c
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Wed Mar 6 01:26:12 2024 +0100
Add Kubeconform pre-commit (#37920)
Fixes: #37919
(cherry picked from commit 477085463204f4b3bc902e84160e9ec5eec53a4e)
---
.pre-commit-config.yaml | 8 ++++
contributing-docs/08_static_code_checks.rst | 2 +
dev/breeze/doc/images/output_static-checks.svg | 2 +-
dev/breeze/doc/images/output_static-checks.txt | 2 +-
dev/breeze/src/airflow_breeze/pre_commit_ids.py | 1 +
scripts/ci/pre_commit/pre_commit_kubeconform.py | 50 +++++++++++++++++++++++++
6 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 9bd7a2c8da..53dfd54722 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -780,6 +780,14 @@ repos:
files: ^chart
require_serial: true
additional_dependencies: ['rich>=12.4.4','requests']
+ - id: kubeconform
+ name: Kubeconform check on our helm chart
+ entry: ./scripts/ci/pre_commit/pre_commit_kubeconform.py
+ language: python
+ pass_filenames: false
+ files: ^chart
+ require_serial: true
+ additional_dependencies: ['rich>=12.4.4','requests']
- id: shellcheck
name: Check Shell scripts syntax correctness
language: docker_image
diff --git a/contributing-docs/08_static_code_checks.rst b/contributing-docs/08_static_code_checks.rst
index 8a34ce414c..385d38d2ea 100644
--- a/contributing-docs/08_static_code_checks.rst
+++ b/contributing-docs/08_static_code_checks.rst
@@ -271,6 +271,8 @@ require Breeze Docker image to be built locally.
| | * Add license for all Markdown files | |
| | * Add license for all other files | |
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
+| kubeconform | Kubeconform check on our helm chart | |
++-----------------------------------------------------------+--------------------------------------------------------------+---------+
| lint-chart-schema | Lint chart/values.schema.json file | |
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
| lint-css | stylelint | |
diff --git a/dev/breeze/doc/images/output_static-checks.svg b/dev/breeze/doc/images/output_static-checks.svg
index 60a2450ab1..36f31897b4 100644
--- a/dev/breeze/doc/images/output_static-checks.svg
+++ b/dev/breeze/doc/images/output_static-checks.svg
@@ -344,7 +344,7 @@
</text><text class="breeze-static-checks-r5" x="0" y="874" textLength="12.2" clip-path="url(#breeze-static-checks-line-35)">│</text><text class="breeze-static-checks-r7" x="451.4" y="874" textLength="988.2" clip-path="url(#breeze-static-checks-line-35)">compile-www-assets-dev | create-missing-init-py-files-tests | debug-statements | </text><text class="breeze-static-checks-r5" x="1451.8" y="874" textLength="12.2" clip-path="url(#breeze-static-checks-line-35) [...]
</text><text class="breeze-static-checks-r5" x="0" y="898.4" textLength="12.2" clip-path="url(#breeze-static-checks-line-36)">│</text><text class="breeze-static-checks-r7" x="451.4" y="898.4" textLength="988.2" clip-path="url(#breeze-static-checks-line-36)">detect-private-key | doctoc | end-of-file-fixer | fix-encoding-pragma | flynt |  </text><text class="breeze-static-checks-r5" x="1451.8" y="898.4" textLength="12.2" clip-path="url [...]
</text><text class="breeze-static-checks-r5" x="0" y="922.8" textLength="12.2" clip-path="url(#breeze-static-checks-line-37)">│</text><text class="breeze-static-checks-r7" x="451.4" y="922.8" textLength="988.2" clip-path="url(#breeze-static-checks-line-37)">generate-airflow-diagrams | generate-pypi-readme | identity | insert-license |   </text><text class="breeze-static-checks-r5" x="1451.8" y="922.8" textLength="12.2" clip-path="url(#bre [...]
-</text><text class="breeze-static-checks-r5" x="0" y="947.2" textLength="12.2" clip-path="url(#breeze-static-checks-line-38)">│</text><text class="breeze-static-checks-r7" x="451.4" y="947.2" textLength="988.2" clip-path="url(#breeze-static-checks-line-38)">lint-chart-schema | lint-css | lint-dockerfile | lint-helm-chart |               </text><text class="breeze-static-checks-r5 [...]
+</text><text class="breeze-static-checks-r5" x="0" y="947.2" textLength="12.2" clip-path="url(#breeze-static-checks-line-38)">│</text><text class="breeze-static-checks-r7" x="451.4" y="947.2" textLength="988.2" clip-path="url(#breeze-static-checks-line-38)">kubeconform | lint-chart-schema | lint-css | lint-dockerfile | lint-helm-chart | </text><text class="breeze-static-checks-r5" x="1451.8" y="947.2" textLength="12.2" clip-path="url(#bre [...]
</text><text class="breeze-static-checks-r5" x="0" y="971.6" textLength="12.2" clip-path="url(#breeze-static-checks-line-39)">│</text><text class="breeze-static-checks-r7" x="451.4" y="971.6" textLength="988.2" clip-path="url(#breeze-static-checks-line-39)">lint-json-schema | lint-markdown | lint-openapi | mixed-line-ending |            </text><text class="breeze-static-checks-r5" x="1451.8" y= [...]
</text><text class="breeze-static-checks-r5" x="0" y="996" textLength="12.2" clip-path="url(#breeze-static-checks-line-40)">│</text><text class="breeze-static-checks-r7" x="451.4" y="996" textLength="988.2" clip-path="url(#breeze-static-checks-line-40)">mypy-airflow | mypy-dev | mypy-docs | mypy-providers | pretty-format-json |      </text><text class="breeze-static-checks-r5" x="1451.8" y="996" textLength="12.2" [...]
</text><text class="breeze-static-checks-r5" x="0" y="1020.4" textLength="12.2" clip-path="url(#breeze-static-checks-line-41)">│</text><text class="breeze-static-checks-r7" x="451.4" y="1020.4" textLength="988.2" clip-path="url(#breeze-static-checks-line-41)">pylint | python-no-log-warn | replace-bad-characters | rst-backticks | ruff |    </text><text class="breeze-static-checks-r5" x="1451.8" y="1020.4" textLength="12.2" c [...]
diff --git a/dev/breeze/doc/images/output_static-checks.txt b/dev/breeze/doc/images/output_static-checks.txt
index 9d1c4d521b..1199b65de3 100644
--- a/dev/breeze/doc/images/output_static-checks.txt
+++ b/dev/breeze/doc/images/output_static-checks.txt
@@ -1 +1 @@
-082c822c385861b491cbc038bc2bb90c
+410be69b3f0b754adf6c2e6999e08b0d
diff --git a/dev/breeze/src/airflow_breeze/pre_commit_ids.py b/dev/breeze/src/airflow_breeze/pre_commit_ids.py
index 4b28bbbd9b..a27e149364 100644
--- a/dev/breeze/src/airflow_breeze/pre_commit_ids.py
+++ b/dev/breeze/src/airflow_breeze/pre_commit_ids.py
@@ -95,6 +95,7 @@ PRE_COMMIT_LIST = [
"generate-pypi-readme",
"identity",
"insert-license",
+ "kubeconform",
"lint-chart-schema",
"lint-css",
"lint-dockerfile",
diff --git a/scripts/ci/pre_commit/pre_commit_kubeconform.py b/scripts/ci/pre_commit/pre_commit_kubeconform.py
new file mode 100755
index 0000000000..6e7c25834e
--- /dev/null
+++ b/scripts/ci/pre_commit/pre_commit_kubeconform.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+# 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.
+from __future__ import annotations
+
+import os
+import subprocess
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).parent.resolve()))
+from common_precommit_utils import console, initialize_breeze_precommit
+
+initialize_breeze_precommit(__name__, __file__)
+
+res_setup = subprocess.run(["breeze", "k8s", "setup-env"], check=True)
+if res_setup.returncode != 0:
+ console.print("[red]\nError while setting up k8s environment.")
+ sys.exit(res_setup.returncode)
+
+AIRFLOW_SOURCES_DIR = Path(__file__).parents[3].resolve()
+HELM_BIN_PATH = AIRFLOW_SOURCES_DIR / ".build" / ".k8s-env" / "bin" / "helm"
+
+ps = subprocess.Popen(
+ [os.fspath(HELM_BIN_PATH), "template", ".", "-f", "values.yaml"],
+ cwd=AIRFLOW_SOURCES_DIR / "chart",
+ stdout=subprocess.PIPE,
+)
+result = subprocess.run(
+ ["docker", "run", "-i", "ghcr.io/yannh/kubeconform:latest-alpine", "--strict"],
+ stdin=ps.stdout,
+ check=False,
+)
+if result.returncode != 0:
+ console.print("[red]\nError while running kubeconform.")
+ sys.exit(result.returncode)