Skip to content

Commit

Permalink
controllers: refactor and add verify checks
Browse files Browse the repository at this point in the history
- This PR adds verify targets to check if go modules and manifests are up to date
- It also refactor the verify targets in peerpodconfig-ctrl and add the checks to the controllers workflow

Fixes: #1349

Signed-off-by: Amulyam24 <amulmek1@in.ibm.com>
  • Loading branch information
Amulyam24 authored and bpradipt committed Aug 28, 2023
1 parent 7c1c322 commit 53ce2d7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go_version }}
- name: Verify go modules
run: make verify-modules
- name: Verify go generated code
run: make verify-gen
- name: Verify go modules and manifests
run: make verify
- name: Build the controller manager
run: make build
- name: Run unit tests
Expand Down Expand Up @@ -58,7 +56,9 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go_version }}
- name: Verify go modules
- name: Verify go modules and manifests
run: make verify
- name: Build the controller manager
run: make build
- name: Run unit tests
run: make test
Expand Down
29 changes: 29 additions & 0 deletions peerpod-ctrl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,35 @@ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

##@ Verify

ALL_VERIFY_CHECKS = modules gen manifests

.PHONY: verify
verify: $(addprefix verify-,$(ALL_VERIFY_CHECKS)) ## Run all verify-* targets

.PHONY: verify-modules
verify-modules: ## Verify go modules are up to date
go mod tidy
@if !(git diff --quiet HEAD -- go.sum go.mod); then \
git diff; \
echo "go module files are out of date"; exit 1; \
fi

.PHONY: verify-gen
verify-gen: generate ## Verfiy go generated files are up to date
@if !(git diff --quiet HEAD); then \
git diff; \
echo "generated files are out of date, run make generate"; exit 1; \
fi

.PHONY: verify-manifests
verify-manifests: manifests ## Verfiy manifests are up to date
@if !(git diff --quiet HEAD); then \
git diff; \
echo "generated files are out of date, run make manifests"; exit 1; \
fi

.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
Expand Down
12 changes: 12 additions & 0 deletions peerpodconfig-ctrl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ envtest: $(LOCAL_BIN) ## Download envtest-setup locally if necessary.

##@ Verify

ALL_VERIFY_CHECKS = modules gen manifests

.PHONY: verify
verify: $(addprefix verify-,$(ALL_VERIFY_CHECKS)) ## Run all verify-* targets

.PHONY: verify-modules
verify-modules: ## Verify go modules are up to date
go mod tidy
Expand All @@ -187,6 +192,13 @@ verify-gen: generate ## Verfiy go generated files are up to date
echo "generated files are out of date, run make generate"; exit 1; \
fi

.PHONY: verify-manifests
verify-manifests: manifests ## Verfiy manifests are up to date
@if !(git diff --quiet HEAD); then \
git diff; \
echo "generated files are out of date, run make manifests"; exit 1; \
fi

.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
Expand Down

0 comments on commit 53ce2d7

Please sign in to comment.