Skip to content

Commit

Permalink
🌱 Add a make target and check in CI to verify CRD compatibility (#1449)
Browse files Browse the repository at this point in the history
* add make target for running crd-diff

Signed-off-by: everettraven <[email protected]>

* add GHA to run crd-diff

Signed-off-by: everettraven <[email protected]>

* add crd-diff config file and update make target to inject it

Signed-off-by: everettraven <[email protected]>

* update to official released version of crd-diff

Signed-off-by: everettraven <[email protected]>

---------

Signed-off-by: everettraven <[email protected]>
  • Loading branch information
everettraven authored Nov 26, 2024
1 parent b9294a7 commit 2b4c083
Show file tree
Hide file tree
Showing 7 changed files with 472 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ $(CONTROLLER_GEN): $(BINGO_DIR)/controller-gen.mod
@echo "(re)installing $(GOBIN)/controller-gen-v0.16.1"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=controller-gen.mod -o=$(GOBIN)/controller-gen-v0.16.1 "sigs.k8s.io/controller-tools/cmd/controller-gen"

CRD_DIFF := $(GOBIN)/crd-diff-v0.1.0
$(CRD_DIFF): $(BINGO_DIR)/crd-diff.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/crd-diff-v0.1.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=crd-diff.mod -o=$(GOBIN)/crd-diff-v0.1.0 "github.com/everettraven/crd-diff"

CRD_REF_DOCS := $(GOBIN)/crd-ref-docs-v0.1.0
$(CRD_REF_DOCS): $(BINGO_DIR)/crd-ref-docs.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
Expand Down
5 changes: 5 additions & 0 deletions .bingo/crd-diff.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.22.5

require github.com/everettraven/crd-diff v0.1.0
325 changes: 325 additions & 0 deletions .bingo/crd-diff.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ BINGO="${GOBIN}/bingo-v0.9.0"

CONTROLLER_GEN="${GOBIN}/controller-gen-v0.16.1"

CRD_DIFF="${GOBIN}/crd-diff-v0.1.0"

CRD_REF_DOCS="${GOBIN}/crd-ref-docs-v0.1.0"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.61.0"
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/crd-diff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: crd-diff
on:
pull_request:
jobs:
crd-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run make verify-crd-compatibility
run: make verify-crd-compatibility CRD_DIFF_ORIGINAL_REF=${{ github.event.pull_request.base.sha }} CRD_DIFF_UPDATED_REF=${{ github.event.pull_request.head.sha }}

7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ bingo-upgrade: $(BINGO) #EXHELP Upgrade tools
$(BINGO) get "$$pkg@latest"; \
done

.PHONY: verify-crd-compatibility
CRD_DIFF_ORIGINAL_REF := main
CRD_DIFF_UPDATED_REF := HEAD
CRD_DIFF_CONFIG := crd-diff-config.yaml
verify-crd-compatibility: $(CRD_DIFF)
$(CRD_DIFF) --config="${CRD_DIFF_CONFIG}" "git://${CRD_DIFF_ORIGINAL_REF}?path=config/base/crd/bases/olm.operatorframework.io_clusterextensions.yaml" "git://${CRD_DIFF_UPDATED_REF}?path=config/base/crd/bases/olm.operatorframework.io_clusterextensions.yaml"

.PHONY: test
test: manifests generate fmt vet test-unit test-e2e #HELP Run all tests.

Expand Down
109 changes: 109 additions & 0 deletions crd-diff-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
checks:
crd:
scope:
enabled: true
existingFieldRemoval:
enabled: true
storedVersionRemoval:
enabled: true
version:
sameVersion:
enabled: true
unhandledFailureMode: "Closed"
enum:
enabled: true
removalEnforcement: "Strict"
additionEnforcement: "Strict"
default:
enabled: true
changeEnforcement: "Strict"
removalEnforcement: "Strict"
additionEnforcement: "Strict"
required:
enabled: true
newEnforcement: "Strict"
type:
enabled: true
changeEnforcement: "Strict"
maximum:
enabled: true
additionEnforcement: "Strict"
decreaseEnforcement: "Strict"
maxItems:
enabled: true
additionEnforcement: "Strict"
decreaseEnforcement: "Strict"
maxProperties:
enabled: true
additionEnforcement: "Strict"
decreaseEnforcement: "Strict"
maxLength:
enabled: true
additionEnforcement: "Strict"
decreaseEnforcement: "Strict"
minimum:
enabled: true
additionEnforcement: "Strict"
increaseEnforcement: "Strict"
minItems:
enabled: true
additionEnforcement: "Strict"
increaseEnforcement: "Strict"
minProperties:
enabled: true
additionEnforcement: "Strict"
increaseEnforcement: "Strict"
minLength:
enabled: true
additionEnforcement: "Strict"
increaseEnforcement: "Strict"
servedVersion:
enabled: true
unhandledFailureMode: "Closed"
enum:
enabled: true
removalEnforcement: "Strict"
additionEnforcement: "Strict"
default:
enabled: true
changeEnforcement: "Strict"
removalEnforcement: "Strict"
additionEnforcement: "Strict"
required:
enabled: true
newEnforcement: "Strict"
type:
enabled: true
changeEnforcement: "Strict"
maximum:
enabled: true
additionEnforcement: "Strict"
decreaseEnforcement: "Strict"
maxItems:
enabled: true
additionEnforcement: "Strict"
decreaseEnforcement: "Strict"
maxProperties:
enabled: true
additionEnforcement: "Strict"
decreaseEnforcement: "Strict"
maxLength:
enabled: true
additionEnforcement: "Strict"
decreaseEnforcement: "Strict"
minimum:
enabled: true
additionEnforcement: "Strict"
increaseEnforcement: "Strict"
minItems:
enabled: true
additionEnforcement: "Strict"
increaseEnforcement: "Strict"
minProperties:
enabled: true
additionEnforcement: "Strict"
increaseEnforcement: "Strict"
minLength:
enabled: true
additionEnforcement: "Strict"
increaseEnforcement: "Strict"

0 comments on commit 2b4c083

Please sign in to comment.