Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kubeconform pre-commit #37920

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions contributing-docs/08_static_code_checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_static-checks.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_static-checks.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37ca01711f349da3aba13f69eab8cd85
ed139e06805c819eda4c4b510301ab47
1 change: 1 addition & 0 deletions dev/breeze/src/airflow_breeze/pre_commit_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"generate-pypi-readme",
"identity",
"insert-license",
"kubeconform",
"lint-chart-schema",
"lint-css",
"lint-dockerfile",
Expand Down
50 changes: 50 additions & 0 deletions scripts/ci/pre_commit/pre_commit_kubeconform.py
Original file line number Diff line number Diff line change
@@ -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)
Loading