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

🌱 Add a make target and check in CI to verify CRD compatibility #1449

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion .bingo/Variables.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.9. DO NOT EDIT.
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.8. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realize I wasn't up to date on my bingo version. I don't think we should touch the auto-generated files though. If we are concerned about this particular change I can update my bingo version to v0.9

BINGO_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
GOPATH ?= $(shell go env GOPATH)
Expand Down 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.0.0-20241112183958-25304aa59cdb
$(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.0.0-20241112183958-25304aa59cdb"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=crd-diff.mod -o=$(GOBIN)/crd-diff-v0.0.0-20241112183958-25304aa59cdb "github.com/everettraven/crd-diff"

everettraven marked this conversation as resolved.
Show resolved Hide resolved
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
everettraven marked this conversation as resolved.
Show resolved Hide resolved

require github.com/everettraven/crd-diff v0.0.0-20241112183958-25304aa59cdb
323 changes: 323 additions & 0 deletions .bingo/crd-diff.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion .bingo/variables.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.9. DO NOT EDIT.
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.8. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
GOBIN=${GOBIN:=$(go env GOBIN)}
Expand All @@ -12,6 +12,8 @@ BINGO="${GOBIN}/bingo-v0.9.0"

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

CRD_DIFF="${GOBIN}/crd-diff-v0.0.0-20241112183958-25304aa59cdb"

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"
everettraven marked this conversation as resolved.
Show resolved Hide resolved
enum:
enabled: true
removalEnforcement: "Strict"
additionEnforcement: "Strict"
Copy link
Contributor Author

@everettraven everettraven Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enforcement means addition of new allowed enum values is considered incompatible. I know we have some areas of our API where we anticipate adding some enum values so we may want to move this to the less strict IfPreviouslyConstrained that allows addition of new allowed enum values only if the property was previously constrained by enum values. (i.e adding net new enum restrictions to a property is still considered incompatible)

I left this as strict as possible for now so that we can have a discussion as to whether we want to start as strict as possible and loosen as needed (where it makes sense) or leave room for planned future changes to not be "prevented" by this more restrictive configuration.

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"
Loading