Skip to content

Commit 4ab9a93

Browse files
committed
Manage controller-gen using the "tool" directive
The "tool" directive of Go 1.24 ensures that tools use dependencies compatible with other packages in the same module. This is perfect for generated code and CRDs based on Go structs. This also bumps controller-gen to v0.17.3.
1 parent 88274d9 commit 4ab9a93

7 files changed

+187
-158
lines changed

Makefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ BUILDAH_BUILD ?= buildah bud
1515
GO ?= go
1616
GO_BUILD = $(GO) build
1717
GO_TEST ?= $(GO) test
18+
19+
# Ensure modules imported by `postgres-operator` and `controller-gen` are compatible
20+
# by managing them together in the main module.
21+
CONTROLLER ?= $(GO) tool sigs.k8s.io/controller-tools/cmd/controller-gen
22+
1823
KUTTL ?= kubectl-kuttl
1924
KUTTL_TEST ?= $(KUTTL) test
2025

@@ -90,6 +95,8 @@ clean-deprecated: ## Clean deprecated resources
9095
[ ! -d build/crd ] || rm -r build/crd
9196
@# Old testing directories
9297
[ ! -d testing/kuttl/e2e-generated-other ] || rm -r testing/kuttl/e2e-generated-other
98+
@# Tools used to be downloaded directly
99+
[ ! -f hack/tools/controller-gen ] || rm hack/tools/controller-gen
93100

94101

95102
##@ Deployment
@@ -205,7 +212,7 @@ check-envtest: get-pgmonitor tools/setup-envtest
205212
$(GO_TEST) -count=1 -cover ./...
206213

207214
# The "PGO_TEST_TIMEOUT_SCALE" environment variable (default: 1) can be set to a
208-
# positive number that extends test timeouts. The following runs tests with
215+
# positive number that extends test timeouts. The following runs tests with
209216
# timeouts that are 20% longer than normal:
210217
# make check-envtest-existing PGO_TEST_TIMEOUT_SCALE=1.2
211218
.PHONY: check-envtest-existing
@@ -270,7 +277,6 @@ generate: generate-rbac
270277

271278
.PHONY: generate-crd
272279
generate-crd: ## Generate Custom Resource Definitions (CRDs)
273-
generate-crd: tools/controller-gen
274280
$(CONTROLLER) \
275281
crd:crdVersions='v1' \
276282
paths='./pkg/apis/...' \
@@ -282,14 +288,12 @@ generate-collector: ## Generate OTel Collector files
282288

283289
.PHONY: generate-deepcopy
284290
generate-deepcopy: ## Generate DeepCopy functions
285-
generate-deepcopy: tools/controller-gen
286291
$(CONTROLLER) \
287292
object:headerFile='hack/boilerplate.go.txt' \
288293
paths='./pkg/apis/postgres-operator.crunchydata.com/...'
289294

290295
.PHONY: generate-rbac
291296
generate-rbac: ## Generate RBAC
292-
generate-rbac: tools/controller-gen
293297
$(CONTROLLER) \
294298
rbac:roleName='postgres-operator' \
295299
paths='./cmd/...' paths='./internal/...' \
@@ -305,11 +309,6 @@ define go-get-tool
305309
@[ -f '$(1)' ] || { echo Downloading '$(2)'; GOBIN='$(abspath $(dir $(1)))' $(GO) install '$(2)'; }
306310
endef
307311

308-
CONTROLLER ?= hack/tools/controller-gen
309-
tools: tools/controller-gen
310-
tools/controller-gen:
311-
$(call go-get-tool,$(CONTROLLER),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.2)
312-
313312
ENVTEST ?= hack/tools/setup-envtest
314313
tools: tools/setup-envtest
315314
tools/setup-envtest:

config/crd/bases/postgres-operator.crunchydata.com_crunchybridgeclusters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.17.2
6+
controller-gen.kubebuilder.io/version: v0.17.3
77
name: crunchybridgeclusters.postgres-operator.crunchydata.com
88
spec:
99
group: postgres-operator.crunchydata.com

config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.17.2
6+
controller-gen.kubebuilder.io/version: v0.17.3
77
name: pgadmins.postgres-operator.crunchydata.com
88
spec:
99
group: postgres-operator.crunchydata.com

config/crd/bases/postgres-operator.crunchydata.com_pgupgrades.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.17.2
6+
controller-gen.kubebuilder.io/version: v0.17.3
77
name: pgupgrades.postgres-operator.crunchydata.com
88
spec:
99
group: postgres-operator.crunchydata.com

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 65 additions & 61 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module github.com/crunchydata/postgres-operator
22

33
// If this is changing when you don't want it to, see hack/go-get.sh
4-
go 1.23.0
4+
go 1.24.0
55

66
require (
77
github.com/go-logr/logr v1.4.2
88
github.com/golang-jwt/jwt/v5 v5.2.2
9-
github.com/google/go-cmp v0.6.0
9+
github.com/google/go-cmp v0.7.0
1010
github.com/google/uuid v1.6.0
1111
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.0.0
12-
github.com/onsi/ginkgo/v2 v2.22.0
13-
github.com/onsi/gomega v1.36.1
12+
github.com/onsi/ginkgo/v2 v2.22.1
13+
github.com/onsi/gomega v1.36.2
1414
github.com/pganalyze/pg_query_go/v5 v5.1.0
1515
github.com/pkg/errors v0.9.1
1616
github.com/sirupsen/logrus v1.9.3
@@ -22,19 +22,20 @@ require (
2222
go.opentelemetry.io/otel/sdk v1.32.0
2323
go.opentelemetry.io/otel/trace v1.32.0
2424
golang.org/x/crypto v0.36.0
25-
golang.org/x/tools v0.28.0
25+
golang.org/x/tools v0.30.0
2626
gotest.tools/v3 v3.5.1
27-
k8s.io/api v0.31.0
28-
k8s.io/apimachinery v0.31.0
29-
k8s.io/client-go v0.31.0
30-
k8s.io/component-base v0.31.0
31-
k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a
27+
k8s.io/api v0.32.2
28+
k8s.io/apimachinery v0.32.2
29+
k8s.io/client-go v0.32.2
30+
k8s.io/component-base v0.32.2
31+
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f
3232
sigs.k8s.io/controller-runtime v0.19.3
33-
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
33+
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3
3434
sigs.k8s.io/yaml v1.4.0
3535
)
3636

3737
require (
38+
cel.dev/expr v0.18.0 // indirect
3839
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
3940
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
4041
github.com/beorn7/perks v1.0.1 // indirect
@@ -44,6 +45,7 @@ require (
4445
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4546
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
4647
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
48+
github.com/fatih/color v1.18.0 // indirect
4749
github.com/felixge/httpsnoop v1.0.4 // indirect
4850
github.com/fsnotify/fsnotify v1.7.0 // indirect
4951
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
@@ -52,22 +54,23 @@ require (
5254
github.com/go-openapi/jsonreference v0.21.0 // indirect
5355
github.com/go-openapi/swag v0.23.0 // indirect
5456
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
57+
github.com/gobuffalo/flect v1.0.3 // indirect
5558
github.com/gogo/protobuf v1.3.2 // indirect
56-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
5759
github.com/golang/protobuf v1.5.4 // indirect
58-
github.com/google/cel-go v0.20.1 // indirect
60+
github.com/google/cel-go v0.22.0 // indirect
5961
github.com/google/gnostic-models v0.6.8 // indirect
6062
github.com/google/gofuzz v1.2.0 // indirect
6163
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
6264
github.com/gorilla/websocket v1.5.0 // indirect
6365
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
64-
github.com/imdario/mergo v0.3.16 // indirect
6566
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6667
github.com/josharian/intern v1.0.0 // indirect
6768
github.com/json-iterator/go v1.1.12 // indirect
6869
github.com/klauspost/compress v1.17.11 // indirect
6970
github.com/mailru/easyjson v0.7.7 // indirect
70-
github.com/moby/spdystream v0.4.0 // indirect
71+
github.com/mattn/go-colorable v0.1.13 // indirect
72+
github.com/mattn/go-isatty v0.0.20 // indirect
73+
github.com/moby/spdystream v0.5.0 // indirect
7174
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
7275
github.com/modern-go/reflect2 v1.0.2 // indirect
7376
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@@ -76,9 +79,9 @@ require (
7679
github.com/prometheus/client_model v0.6.1 // indirect
7780
github.com/prometheus/common v0.60.1 // indirect
7881
github.com/prometheus/procfs v0.15.1 // indirect
79-
github.com/spf13/cobra v1.8.1 // indirect
80-
github.com/spf13/pflag v1.0.5 // indirect
81-
github.com/stoewer/go-strcase v1.2.0 // indirect
82+
github.com/spf13/cobra v1.9.1 // indirect
83+
github.com/spf13/pflag v1.0.6 // indirect
84+
github.com/stoewer/go-strcase v1.3.0 // indirect
8285
github.com/x448/float16 v0.8.4 // indirect
8386
go.opentelemetry.io/contrib/bridges/prometheus v0.57.0 // indirect
8487
go.opentelemetry.io/contrib/propagators/aws v1.32.0 // indirect
@@ -102,28 +105,32 @@ require (
102105
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
103106
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
104107
go.uber.org/multierr v1.11.0 // indirect
105-
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
106-
golang.org/x/mod v0.22.0 // indirect
108+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
109+
golang.org/x/mod v0.23.0 // indirect
107110
golang.org/x/net v0.38.0 // indirect
108111
golang.org/x/oauth2 v0.27.0 // indirect
109112
golang.org/x/sync v0.12.0 // indirect
110113
golang.org/x/sys v0.31.0 // indirect
111114
golang.org/x/term v0.30.0 // indirect
112115
golang.org/x/text v0.23.0 // indirect
113-
golang.org/x/time v0.5.0 // indirect
116+
golang.org/x/time v0.7.0 // indirect
114117
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
115118
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
116119
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
117120
google.golang.org/grpc v1.68.0 // indirect
118-
google.golang.org/protobuf v1.35.1 // indirect
121+
google.golang.org/protobuf v1.36.1 // indirect
119122
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
120123
gopkg.in/inf.v0 v0.9.1 // indirect
121124
gopkg.in/yaml.v2 v2.4.0 // indirect
122125
gopkg.in/yaml.v3 v3.0.1 // indirect
123-
k8s.io/apiextensions-apiserver v0.31.0 // indirect
124-
k8s.io/apiserver v0.31.0 // indirect
126+
k8s.io/apiextensions-apiserver v0.32.2 // indirect
127+
k8s.io/apiserver v0.32.2 // indirect
125128
k8s.io/klog/v2 v2.130.1 // indirect
126-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
127-
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
128-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
129+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
130+
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect
131+
sigs.k8s.io/controller-tools v0.17.3 // indirect
132+
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
129133
)
134+
135+
// https://go.dev/doc/modules/managing-dependencies#tools
136+
tool sigs.k8s.io/controller-tools/cmd/controller-gen

0 commit comments

Comments
 (0)