Skip to content

Commit 20ff729

Browse files
committed
Add a Make target that runs crd-schema-checker
This tool estimates the total and relative cost of CEL validation rules. See: https://github.com/openshift/crd-schema-checker
1 parent c8a6ba2 commit 20ff729

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CONTROLLER ?= $(GO) tool sigs.k8s.io/controller-tools/cmd/controller-gen
1414
# Run tests using the latest tools.
1515
CHAINSAW ?= $(GO) run github.com/kyverno/chainsaw@latest
1616
CHAINSAW_TEST ?= $(CHAINSAW) test
17+
CRD_CHECKER ?= $(GO) run github.com/openshift/crd-schema-checker/cmd/crd-schema-checker@latest
1718
ENVTEST ?= $(GO) run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
1819
KUTTL ?= $(GO) run github.com/kudobuilder/kuttl/cmd/kubectl-kuttl@latest
1920
KUTTL_TEST ?= $(KUTTL) test
@@ -148,6 +149,12 @@ check: ## Run basic go tests with coverage output
148149
check: get-pgmonitor
149150
QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" $(GO_TEST) -cover ./...
150151

152+
# Informational only; no criteria to enforce at this time.
153+
.PHONY: check-crd
154+
check-crd:
155+
$(foreach CRD, $(wildcard config/crd/bases/*.yaml), \
156+
$(CRD_CHECKER) check-manifests --new-crd-filename '$(CRD)' 2>&1 | awk -f hack/check-manifests.awk $(newline))
157+
151158
# Available versions: curl -s 'https://storage.googleapis.com/kubebuilder-tools/' | grep -o '<Key>[^<]*</Key>'
152159
# - KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true
153160
.PHONY: check-envtest
@@ -254,3 +261,9 @@ generate-rbac: ## Generate RBAC
254261
) rbac:roleName='postgres-operator' $(\
255262
) paths='./cmd/...' paths='./internal/...' $(\
256263
) output:dir='config/rbac' # {directory}/role.yaml
264+
265+
# https://www.gnu.org/software/make/manual/make.html#Multi_002dLine
266+
define newline
267+
268+
269+
endef

hack/check-manifests.awk

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2025 Crunchy Data Solutions, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
## TODO: Exit successfully only when there are no errors.
6+
#/^ERROR:/ { rc = 1 }
7+
#END { exit rc }
8+
9+
# Shorten these frequent messages about validation rules.
10+
/The maximum allowable value is 10000000[.]/ {
11+
sub(/ The maximum allowable value is 10000000./, "")
12+
sub(/ allowed budget/, "&, 10M")
13+
}
14+
15+
# These are informational, but "MustNot" sounds like something is wrong.
16+
/^info: "MustNotExceedCostBudget"/ {
17+
sub(/"MustNotExceedCostBudget"/, "\"CostBudget\"")
18+
}
19+
20+
# Color errors and warnings when attached to a terminal.
21+
ENVIRON["MAKE_TERMOUT"] != "" {
22+
sub(/^ERROR:/, "\033[0;31m&\033[0m")
23+
sub(/^Warning:/, "\033[1;33m&\033[0m")
24+
}
25+
26+
{ print }

0 commit comments

Comments
 (0)