Skip to content

Commit 5f3f932

Browse files
Merge pull request #420 from mrkisaolamb/crd-schema-checker
[make][pre-commit]Check CRD schema to avoid update issues
2 parents bc64ab6 + c3f3352 commit 5f3f932

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ repos:
2626
entry: make
2727
args: ['operator-lint']
2828
pass_filenames: false
29+
- id: make-crd-schema-check
30+
name: make-crd-schema-check
31+
language: system
32+
entry: make
33+
args: ['crd-schema-check']
34+
pass_filenames: false
2935

3036
- repo: https://github.com/pre-commit/pre-commit-hooks
3137
rev: v4.4.0

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,11 @@ run-with-webhook: export METRICS_PORT?=8080
353353
run-with-webhook: export HEALTH_PORT?=8081
354354
run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
355355
/bin/bash hack/run_with_local_webhook.sh
356+
357+
CRD_SCHEMA_CHECKER_VERSION ?= release-4.16
358+
BRANCH=main
359+
360+
PHONY: crd-schema-check
361+
crd-schema-check: manifests
362+
INSTALL_DIR=$(LOCALBIN) CRD_SCHEMA_CHECKER_VERSION=$(CRD_SCHEMA_CHECKER_VERSION) hack/build-crd-schema-checker.sh
363+
INSTALL_DIR=$(LOCALBIN) BASE_REF="$${PULL_BASE_SHA:-$(BRANCH)}" hack/crd-schema-checker.sh

hack/build-crd-schema-checker.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
if [ -f "$INSTALL_DIR/crd-schema-checker" ]; then
5+
exit 0
6+
fi
7+
8+
mkdir -p "$INSTALL_DIR/git-tmp"
9+
git clone https://github.com/openshift/crd-schema-checker.git \
10+
-b "$CRD_SCHEMA_CHECKER_VERSION" "$INSTALL_DIR/git-tmp"
11+
pushd "$INSTALL_DIR/git-tmp"
12+
GOWORK=off make
13+
cp crd-schema-checker "$INSTALL_DIR/"
14+
popd
15+
rm -rf "$INSTALL_DIR/git-tmp"

hack/crd-schema-checker.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
CHECKER=$INSTALL_DIR/crd-schema-checker
5+
6+
TMP_DIR=$(mktemp -d)
7+
8+
function cleanup {
9+
rm -rf "$TMP_DIR"
10+
}
11+
12+
trap cleanup EXIT
13+
14+
15+
for crd in config/crd/bases/*.yaml; do
16+
mkdir -p "$(dirname "$TMP_DIR/$crd")"
17+
git show "$BASE_REF:$crd" > "$TMP_DIR/$crd"
18+
$CHECKER check-manifests \
19+
--existing-crd-filename="$TMP_DIR/$crd" \
20+
--new-crd-filename="$crd"
21+
done

0 commit comments

Comments
 (0)