diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5a8efe06aef9..cad8ba6db03e8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -773,6 +773,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 61540498c6eb5..1716f926d4863 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 b92edf65ffdda..2616826e868ad 100644 --- a/dev/breeze/doc/images/output_static-checks.svg +++ b/dev/breeze/doc/images/output_static-checks.svg @@ -344,7 +344,7 @@ create-missing-init-py-files-tests | debug-statements | detect-private-key |      doctoc | end-of-file-fixer | fix-encoding-pragma | flynt |                        generate-airflow-diagrams | generate-pypi-readme | identity | insert-license |    -lint-chart-schema | lint-css | lint-dockerfile | lint-helm-chart |                +kubeconform | lint-chart-schema | lint-css | lint-dockerfile | lint-helm-chart |  lint-json-schema | lint-markdown | lint-openapi | mixed-line-ending |             mypy-airflow | mypy-dev | mypy-docs | mypy-providers | pretty-format-json |       pylint | python-no-log-warn | replace-bad-characters | rst-backticks | ruff |     diff --git a/dev/breeze/doc/images/output_static-checks.txt b/dev/breeze/doc/images/output_static-checks.txt index d8f2721576a69..569bf82ff91d8 100644 --- a/dev/breeze/doc/images/output_static-checks.txt +++ b/dev/breeze/doc/images/output_static-checks.txt @@ -1 +1 @@ -37ca01711f349da3aba13f69eab8cd85 +ed139e06805c819eda4c4b510301ab47 diff --git a/dev/breeze/src/airflow_breeze/pre_commit_ids.py b/dev/breeze/src/airflow_breeze/pre_commit_ids.py index 99a967d463783..56f9fb6aa99a5 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 @@ "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 0000000000000..6e7c25834e7c5 --- /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)