Skip to content

Commit

Permalink
[CI] Generate CRD json schema separately in pre-commit (#2930)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortalHappiness authored Feb 6, 2025
1 parent 3e97888 commit f3ed172
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@

# Any file with a .log extension
**/*.log

# Ignore generated CRD schema files
schema/
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ repos:
pass_filenames: false
additional_dependencies:
- github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3

- repo: local
hooks:
- id: generate-crd-schema
name: generate CRD schemas for use of kubeconform
entry: ./scripts/generate-crd-schema.sh
language: python
require_serial: true
always_run: true
pass_filenames: false
additional_dependencies:
- PyYAML==6.0.1
- id: validate-helm-charts
name: validate helm charts with kubeconform
entry: bash scripts/validate-helm.sh
Expand Down
16 changes: 16 additions & 0 deletions scripts/generate-crd-schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -euo pipefail

if [ ! -d "schema" ]; then
mkdir schema
fi

convert_script=$(realpath scripts/openapi2jsonschema.py)
crd_files=$(find ray-operator/config/crd/bases -name "*.yaml" -exec realpath {} \;)

cd schema

for crd_file in $crd_files; do
$convert_script "$crd_file"
done
30 changes: 14 additions & 16 deletions scripts/validate-helm.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#!/bin/bash
#!/usr/bin/env bash

set -euo pipefail
export KUBERAY_HOME=$(git rev-parse --show-toplevel)
SCRIPT_PATH="${KUBERAY_HOME}/scripts/openapi2jsonschema.py"
RAYCLUSTER_CRD_PATH="$KUBERAY_HOME/ray-operator/config/crd/bases/ray.io_rayclusters.yaml"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

# Convert CRD YAML to JSON Schema
pushd "${tmp}" > /dev/null
"$SCRIPT_PATH" "$RAYCLUSTER_CRD_PATH"
popd > /dev/null
RAYCLUSTER_CRD_SCHEMA="${tmp}/raycluster_v1.json"
raycluster_crd_schema=./schema/raycluster_v1.json

if [ ! -f "$raycluster_crd_schema" ]; then
echo "CRD schema not found: $raycluster_crd_schema"
echo 'Please run "pre-commit genearete-crd-schema --all-files" first'
exit 1
fi

charts=("kuberay-apiserver" "kuberay-operator" "ray-cluster")

# Validate Helm charts with kubeconform
echo "Validating Helm Charts with kubeconform..."
helm template "$KUBERAY_HOME/helm-chart/kuberay-apiserver" | kubeconform --summary -schema-location default
helm template "$KUBERAY_HOME/helm-chart/kuberay-operator" | kubeconform --summary -schema-location default
helm template "$KUBERAY_HOME/helm-chart/ray-cluster" | kubeconform --summary -schema-location default -schema-location "$RAYCLUSTER_CRD_SCHEMA"
for chart in "${charts[@]}"; do
helm template ./helm-chart/"$chart" | kubeconform --summary -schema-location default -schema-location "$raycluster_crd_schema"
done

0 comments on commit f3ed172

Please sign in to comment.