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

test crd schema checker #1202

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ 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
verbose: true

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,10 @@ run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
.PHONY: webhook-cleanup
webhook-cleanup:
/bin/bash hack/clean_local_webhook.sh

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
4 changes: 4 additions & 0 deletions apis/bases/core.openstack.org_openstackcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10879,6 +10879,8 @@ spec:
format: int32
minimum: 0
type: integer
foo:
type: integer
nodeSelector:
additionalProperties:
type: string
Expand Down Expand Up @@ -14696,6 +14698,8 @@ spec:
type: string
type: object
type: array
required:
- foo
type: object
type: object
type: object
Expand Down
3 changes: 3 additions & 0 deletions apis/core/v1beta1/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ type RabbitmqTemplate struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// NodeSelector to target subset of worker nodes running this service
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Required
Foo int `json:"foo"`
}

// OvnSection defines the desired state of OVN services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10879,6 +10879,8 @@ spec:
format: int32
minimum: 0
type: integer
foo:
type: integer
nodeSelector:
additionalProperties:
type: string
Expand Down Expand Up @@ -14696,6 +14698,8 @@ spec:
type: string
type: object
type: array
required:
- foo
type: object
type: object
type: object
Expand Down
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