Skip to content

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

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

Merged
merged 4 commits into from
Nov 26, 2024
Merged
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
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"
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