Skip to content

Commit 4816079

Browse files
committed
Decouple framework/ into a standalone Go module
- Replace root-module type aliases with native definitions in framework/api - Remove root-module dependency and replace directive from framework/go.mod - Add dedicated framework/Makefile with generate/lint/test/verify targets - Remove inline `cd framework` from root Makefile; add *-all delegation targets - Update CI workflows to cover both modules independently
1 parent 8a1925b commit 4816079

16 files changed

Lines changed: 330 additions & 101 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ jobs:
2121
go-version-file: go.mod
2222

2323
- name: Run golangci-lint
24-
uses: golangci/golangci-lint-action@v7
25-
with:
26-
version: v2.5.0
24+
run: make lint-all
2725

2826
test:
2927
name: Test
@@ -35,14 +33,17 @@ jobs:
3533
with:
3634
go-version-file: go.mod
3735

38-
- name: Run tests
36+
- name: Run tests (root)
3937
run: make test
4038

39+
- name: Run tests (framework)
40+
run: make -C framework test
41+
4142
- name: Upload coverage to Codecov
4243
if: github.event_name == 'pull_request'
4344
uses: codecov/codecov-action@v4
4445
with:
45-
files: cover.out
46+
files: cover.out,framework/cover.out
4647
fail_ci_if_error: false
4748
env:
4849
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
@@ -58,7 +59,7 @@ jobs:
5859
go-version-file: go.mod
5960

6061
- name: Verify go mod tidy
61-
run: make verify-tidy
62+
run: make verify-tidy-all
6263

6364
- name: Verify formatting
6465
run: make verify-fmt

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
fi
3131
3232
- name: Run tests
33-
run: make test
33+
run: make test-all
3434

3535
- name: Create GitHub Release
3636
uses: softprops/action-gh-release@v2

Makefile

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,29 @@ fmt: ## Run gofmt and golangci-lint formatter.
3131
@if [ -n "$(GOLANGCI_LINT)" ]; then golangci-lint fmt; fi
3232

3333
.PHONY: vet
34-
vet: ## Run go vet across all modules.
34+
vet: ## Run go vet.
3535
go vet ./...
36-
cd framework && go vet ./...
3736

3837
.PHONY: lint
39-
lint: golangci-lint ## Run golangci-lint across all modules.
38+
lint: golangci-lint ## Run golangci-lint.
4039
$(GOLANGCI_LINT) run
41-
cd framework && $(GOLANGCI_LINT) run
4240

4341
.PHONY: lint-fix
44-
lint-fix: golangci-lint ## Run golangci-lint with --fix across all modules.
42+
lint-fix: golangci-lint ## Run golangci-lint with --fix.
4543
$(GOLANGCI_LINT) run --fix
46-
cd framework && $(GOLANGCI_LINT) run --fix
4744

4845
.PHONY: test
49-
test: ## Run tests with race detector and coverage across all modules.
46+
test: ## Run tests with race detector and coverage.
5047
go test -race -coverprofile=$(COVERAGE_FILE) ./...
51-
cd framework && go test -race -coverprofile=$(COVERAGE_FILE) ./...
5248

5349
.PHONY: tidy
54-
tidy: ## Run go mod tidy across all modules.
50+
tidy: ## Run go mod tidy.
5551
go mod tidy
56-
cd framework && go mod tidy
5752

5853
.PHONY: verify-tidy
59-
verify-tidy: ## Verify go.mod and go.sum are tidy across all modules.
54+
verify-tidy: ## Verify go.mod and go.sum are tidy.
6055
go mod tidy
6156
@if [ -f go.sum ]; then git diff --exit-code go.mod go.sum; else git diff --exit-code go.mod; fi
62-
cd framework && go mod tidy
63-
@git diff --exit-code framework/go.mod framework/go.sum
6457

6558
.PHONY: verify-fmt
6659
verify-fmt: ## Verify code is formatted.
@@ -70,6 +63,40 @@ verify-fmt: ## Verify code is formatted.
7063
verify-generate: generate ## Verify generated files are up to date.
7164
@git diff --quiet --exit-code api/ || (echo "Generated files are out of date. Run 'make generate' and commit." && git diff --stat api/ && exit 1)
7265

66+
##@ All Modules
67+
68+
.PHONY: all-modules
69+
all-modules: all ## Run all checks across root and framework modules.
70+
$(MAKE) -C framework all
71+
72+
.PHONY: generate-all
73+
generate-all: generate ## Regenerate DeepCopy methods across all modules.
74+
$(MAKE) -C framework generate
75+
76+
.PHONY: test-all
77+
test-all: test ## Run tests across all modules.
78+
$(MAKE) -C framework test
79+
80+
.PHONY: lint-all
81+
lint-all: lint ## Run golangci-lint across all modules.
82+
$(MAKE) -C framework lint
83+
84+
.PHONY: lint-fix-all
85+
lint-fix-all: lint-fix ## Run golangci-lint with --fix across all modules.
86+
$(MAKE) -C framework lint-fix
87+
88+
.PHONY: tidy-all
89+
tidy-all: tidy ## Run go mod tidy across all modules.
90+
$(MAKE) -C framework tidy
91+
92+
.PHONY: verify-tidy-all
93+
verify-tidy-all: verify-tidy ## Verify go.mod/go.sum are tidy across all modules.
94+
$(MAKE) -C framework verify-tidy
95+
96+
.PHONY: verify-generate-all
97+
verify-generate-all: verify-generate ## Verify generated files are up to date across all modules.
98+
$(MAKE) -C framework verify-generate
99+
73100
##@ Tools
74101

75102
.PHONY: golangci-lint
@@ -90,4 +117,4 @@ endif
90117

91118
.PHONY: help
92119
help: ## Display this help.
93-
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
120+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

api/common/types_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ type testComponentStatus struct {
2121

2222
type testComponent struct {
2323
metav1.TypeMeta `json:",inline"`
24-
metav1.ObjectMeta `json:"metadata,omitempty"`
24+
metav1.ObjectMeta `json:"metadata"`
2525

26-
Spec testComponentSpec `json:"spec,omitempty"`
27-
Status testComponentStatus `json:"status,omitempty"`
26+
Spec testComponentSpec `json:"spec"`
27+
Status testComponentStatus `json:"status"`
2828
}
2929

3030
type testComponentSpec struct {

api/common/validation/validate_internal_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestValidate_ReturnsAllViolations(t *testing.T) {
9797

9898
type brokenNilStatus struct {
9999
metav1.TypeMeta `json:",inline"`
100-
metav1.ObjectMeta `json:"metadata,omitempty"`
100+
metav1.ObjectMeta `json:"metadata"`
101101
}
102102

103103
func (b *brokenNilStatus) GetStatus() *common.Status { return nil }
@@ -120,7 +120,7 @@ func (b *brokenNilStatus) DeepCopyObject() runtime.Object {
120120

121121
type brokenNilReleaseStatus struct {
122122
metav1.TypeMeta `json:",inline"`
123-
metav1.ObjectMeta `json:"metadata,omitempty"`
123+
metav1.ObjectMeta `json:"metadata"`
124124

125125
status common.Status
126126
}
@@ -151,7 +151,7 @@ func (b *brokenNilReleaseStatus) DeepCopyObject() runtime.Object {
151151

152152
type brokenConditionsNotStored struct {
153153
metav1.TypeMeta `json:",inline"`
154-
metav1.ObjectMeta `json:"metadata,omitempty"`
154+
metav1.ObjectMeta `json:"metadata"`
155155

156156
releases common.ComponentReleaseStatus
157157
status common.Status
@@ -183,7 +183,7 @@ func (b *brokenConditionsNotStored) DeepCopyObject() runtime.Object {
183183

184184
type brokenReleasesNotStored struct {
185185
metav1.TypeMeta `json:",inline"`
186-
metav1.ObjectMeta `json:"metadata,omitempty"`
186+
metav1.ObjectMeta `json:"metadata"`
187187

188188
releases common.ComponentReleaseStatus
189189
status common.Status
@@ -215,7 +215,7 @@ func (b *brokenReleasesNotStored) DeepCopyObject() runtime.Object {
215215

216216
type brokenPhaseNotWritable struct {
217217
metav1.TypeMeta `json:",inline"`
218-
metav1.ObjectMeta `json:"metadata,omitempty"`
218+
metav1.ObjectMeta `json:"metadata"`
219219

220220
releases common.ComponentReleaseStatus
221221
status common.Status

api/common/validation/validate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ type fakeModuleStatus struct {
4848

4949
type fakeModule struct {
5050
metav1.TypeMeta `json:",inline"`
51-
metav1.ObjectMeta `json:"metadata,omitempty"`
51+
metav1.ObjectMeta `json:"metadata,omitzero"`
5252

53-
Status fakeModuleStatus `json:"status,omitempty"`
53+
Status fakeModuleStatus `json:"status,omitzero"`
5454
}
5555

5656
func (f *fakeModule) GetStatus() *common.Status {

framework/Makefile

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
GOLANGCI_LINT_VERSION ?= v2.5.0
2+
CONTROLLER_GEN_VERSION ?= v0.20.1
3+
COVERAGE_FILE ?= cover.out
4+
5+
GOLANGCI_LINT = $(shell which golangci-lint 2>/dev/null)
6+
CONTROLLER_GEN = $(shell which controller-gen 2>/dev/null)
7+
8+
# Pin the toolchain to the exact Go version declared in go.mod so that
9+
# the race-instrumented stdlib is compiled with the same compiler version
10+
# used for user code.
11+
GO_MOD_VERSION := $(shell awk '/^go /{print $$2; exit}' go.mod)
12+
export GOTOOLCHAIN := go$(GO_MOD_VERSION)
13+
14+
.PHONY: all
15+
all: fmt vet lint test
16+
17+
##@ Code Generation
18+
19+
.PHONY: generate
20+
generate: controller-gen ## Regenerate DeepCopy methods for api/ types.
21+
$(CONTROLLER_GEN) object paths="./api/..."
22+
23+
##@ Development
24+
25+
.PHONY: fmt
26+
fmt: ## Run gofmt and golangci-lint formatter.
27+
gofmt -w .
28+
@if [ -n "$(GOLANGCI_LINT)" ]; then golangci-lint fmt; fi
29+
30+
.PHONY: vet
31+
vet: ## Run go vet.
32+
go vet ./...
33+
34+
.PHONY: lint
35+
lint: golangci-lint ## Run golangci-lint.
36+
$(GOLANGCI_LINT) run
37+
38+
.PHONY: lint-fix
39+
lint-fix: golangci-lint ## Run golangci-lint with --fix.
40+
$(GOLANGCI_LINT) run --fix
41+
42+
.PHONY: test
43+
test: ## Run tests with race detector and coverage.
44+
go test -race -coverprofile=$(COVERAGE_FILE) ./...
45+
46+
.PHONY: tidy
47+
tidy: ## Run go mod tidy.
48+
go mod tidy
49+
50+
.PHONY: verify-tidy
51+
verify-tidy: ## Verify go.mod and go.sum are tidy.
52+
go mod tidy
53+
@git diff --exit-code go.mod go.sum
54+
55+
.PHONY: verify-fmt
56+
verify-fmt: ## Verify code is formatted.
57+
@test -z "$$(gofmt -l .)" || (echo "Files not formatted:"; gofmt -l .; exit 1)
58+
59+
.PHONY: verify-generate
60+
verify-generate: generate ## Verify generated files are up to date.
61+
@git diff --quiet --exit-code api/ || (echo "Generated files are out of date. Run 'make -C framework generate' and commit." && git diff --stat api/ && exit 1)
62+
63+
##@ Tools
64+
65+
.PHONY: golangci-lint
66+
golangci-lint: ## Install golangci-lint if not present.
67+
ifeq ($(GOLANGCI_LINT),)
68+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
69+
$(eval GOLANGCI_LINT = $(shell go env GOPATH)/bin/golangci-lint)
70+
endif
71+
72+
.PHONY: controller-gen
73+
controller-gen: ## Install controller-gen if not present.
74+
ifeq ($(CONTROLLER_GEN),)
75+
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
76+
$(eval CONTROLLER_GEN = $(shell go env GOPATH)/bin/controller-gen)
77+
endif
78+
79+
##@ Help
80+
81+
.PHONY: help
82+
help: ## Display this help.
83+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

0 commit comments

Comments
 (0)