Skip to content

Commit

Permalink
Merge pull request openstack-k8s-operators#321 from mrkisaolamb/crd-s…
Browse files Browse the repository at this point in the history
…chema-checker

[make][pre-commit]Check CRD schema to avoid update issues
  • Loading branch information
openshift-merge-bot[bot] authored Nov 28, 2024
2 parents 6821e16 + 2f0f681 commit 70981ed
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ repos:
entry: make
args: ['operator-lint']
pass_filenames: false
- id: make-crd-schema-check
name: make-crd-schema-check
language: system
entry: make
args: ['crd-schema-check']
pass_filenames: false

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,10 @@ force-bump: ## Force bump operator and lib-common dependencies
for dep in $$(cat apis/go.mod | grep openstack-k8s-operators | grep -vE -- 'indirect|infra-operator|^replace' | awk '{print $$1}'); do \
cd ./apis && go get $$dep@$(BRANCH) && cd .. ; \
done

CRD_SCHEMA_CHECKER_VERSION ?= release-4.16

PHONY: crd-schema-check
crd-schema-check: manifests
INSTALL_DIR=$(LOCALBIN) CRD_SCHEMA_CHECKER_VERSION=$(CRD_SCHEMA_CHECKER_VERSION) hack/build-crd-schema-checker.sh
INSTALL_DIR=$(LOCALBIN) BASE_REF="$${PULL_BASE_SHA:-$(BRANCH)}" hack/crd-schema-checker.sh
15 changes: 15 additions & 0 deletions hack/build-crd-schema-checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -euxo pipefail

if [ -f "$INSTALL_DIR/crd-schema-checker" ]; then
exit 0
fi

mkdir -p "$INSTALL_DIR/git-tmp"
git clone https://github.com/openshift/crd-schema-checker.git \
-b "$CRD_SCHEMA_CHECKER_VERSION" "$INSTALL_DIR/git-tmp"
pushd "$INSTALL_DIR/git-tmp"
GOWORK=off make
cp crd-schema-checker "$INSTALL_DIR/"
popd
rm -rf "$INSTALL_DIR/git-tmp"
21 changes: 21 additions & 0 deletions hack/crd-schema-checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -euxo pipefail

CHECKER=$INSTALL_DIR/crd-schema-checker

TMP_DIR=$(mktemp -d)

function cleanup {
rm -rf "$TMP_DIR"
}

trap cleanup EXIT


for crd in config/crd/bases/*.yaml; do
mkdir -p "$(dirname "$TMP_DIR/$crd")"
git show "$BASE_REF:$crd" > "$TMP_DIR/$crd"
$CHECKER check-manifests \
--existing-crd-filename="$TMP_DIR/$crd" \
--new-crd-filename="$crd"
done

0 comments on commit 70981ed

Please sign in to comment.