Skip to content

Commit 1714dc4

Browse files
Upgrade from Kubebuilder 4.5.2 to 4.6.0 and add support for k8s 1.33
Signed-off-by: Camila Macedo <[email protected]>
1 parent 1bf4815 commit 1714dc4

File tree

43 files changed

+525
-385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+525
-385
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export IMAGE_VERSION = v1.40.0
99
export SIMPLE_VERSION = $(shell (test "$(shell git describe --tags)" = "$(shell git describe --tags --abbrev=0)" && echo $(shell git describe --tags)) || echo $(shell git describe --tags --abbrev=0)+git)
1010
export GIT_VERSION = $(shell git describe --dirty --tags --always)
1111
export GIT_COMMIT = $(shell git rev-parse HEAD)
12-
export K8S_VERSION = 1.32.0
12+
export K8S_VERSION = 1.33.0
1313

1414
# Build settings
1515
export TOOLS_DIR = tools/bin
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
entries:
2+
- description: >
3+
For Go-based operators, upgrade the Go version from `1.23` to `1.24`
4+
kind: "change"
5+
breaking: true
6+
migration:
7+
header: Upgrade Go version to 1.24
8+
body: |
9+
Update the Go version used to `1.24`. This affects:
10+
11+
**Dockerfile:**
12+
```dockerfile
13+
-FROM golang:1.23 AS builder
14+
+FROM golang:1.24 AS builder
15+
```
16+
17+
**.devcontainer/devcontainer.json:**
18+
```json
19+
- "image": "golang:1.23",
20+
+ "image": "golang:1.24",
21+
```
22+
23+
**go.mod:**
24+
```go
25+
-go 1.23.0
26+
+go 1.24.0
27+
```
28+
29+
- description: >
30+
For Go-based operators, upgrade golangci-lint to `v2.1.0` and update `.golangci.yml`
31+
to the v2 config format with enhanced structure and controls.
32+
kind: "change"
33+
breaking: false
34+
migration:
35+
header: Upgrade golangci-lint and use v2 config
36+
body: |
37+
Update golangci-lint usage across the project:
38+
39+
**Makefile:**
40+
```makefile
41+
-GOLANGCI_LINT_VERSION ?= v1.63.4
42+
+GOLANGCI_LINT_VERSION ?= v2.1.0
43+
44+
-$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
45+
+$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
46+
```
47+
48+
**GitHub Actions Workflow:**
49+
```yaml
50+
- uses: golangci/golangci-lint-action@v6
51+
+ uses: golangci/golangci-lint-action@v8
52+
```
53+
54+
**.golangci.yml:**
55+
Convert to v2 layout with keys like `version`, `linters`, `settings`, `formatters`, `exclusions`.
56+
You might want to copy and paste the file from the Memcached sample from the tag release `v1.40.0`: [testdata/go/v4/memcached-operator/.golangci.yml](https://github.com/operator-framework/operator-sdk/tree/v1.40.0/testdata/go/v4/memcached-operator/.golangci.yml)
57+
58+
- description: >
59+
For Go-based operators, upgrade controller-gen from `v0.17.2` to `v0.18.0`.
60+
kind: "change"
61+
breaking: false
62+
migration:
63+
header: Upgrade controller-gen to `v0.18.0`
64+
body: |
65+
Update controller-gen tooling and annotations:
66+
67+
**Makefile:**
68+
```makefile
69+
-CONTROLLER_TOOLS_VERSION ?= v0.17.2
70+
+CONTROLLER_TOOLS_VERSION ?= v0.18.0
71+
```
72+
73+
Run `make generate` to regenerate code and manifests with the new version.
74+
75+
- description: >
76+
For Go-based operators, upgrade controller-runtime from `v0.20.4` to `v0.21.0`
77+
and kubernetes dependencies to `v0.33`.
78+
kind: "change"
79+
breaking: false
80+
migration:
81+
header: Upgrade controller-runtime to `v0.21.0`
82+
body: |
83+
Update the `go.mod` import:
84+
```go
85+
-sigs.k8s.io/controller-runtime v0.20.4
86+
+sigs.k8s.io/controller-runtime v0.21.0
87+
```
88+
89+
Run `go mod tidy` to upgrade the k8s dependencies.
90+
91+
- description: >
92+
For Go-based operators, add new target to setup/teardown Kind cluster for E2E tests
93+
and remove Kind setup from CI workflows.
94+
kind: "addition"
95+
breaking: false
96+
migration:
97+
header: Add cluster setup for e2e tests in Makefile and update CI workflow
98+
body: |
99+
Remove direct Kind commands in GitHub workflows:
100+
101+
**Removed:**
102+
```yaml
103+
- name: Create kind cluster
104+
run: kind create cluster
105+
```
106+
107+
**Added to Makefile:**
108+
```makefile
109+
KIND_CLUSTER ?= memcached-operator-test-e2e
110+
111+
.PHONY: setup-test-e2e
112+
setup-test-e2e:
113+
$(KIND) create cluster --name $(KIND_CLUSTER)
114+
115+
.PHONY: cleanup-test-e2e
116+
cleanup-test-e2e:
117+
$(KIND) delete cluster --name $(KIND_CLUSTER)
118+
```
119+
120+
Update `test-e2e` target to call these appropriately.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/operator-framework/operator-sdk
22

3-
go 1.23.6
3+
go 1.24.3
44

55
require (
66
github.com/blang/semver/v4 v4.0.0
@@ -41,7 +41,7 @@ require (
4141
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e
4242
sigs.k8s.io/controller-runtime v0.20.4
4343
sigs.k8s.io/controller-tools v0.17.2
44-
sigs.k8s.io/kubebuilder/v4 v4.5.2
44+
sigs.k8s.io/kubebuilder/v4 v4.6.0
4545
sigs.k8s.io/yaml v1.4.0
4646
)
4747

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,8 @@ sigs.k8s.io/controller-tools v0.17.2 h1:jNFOKps8WnaRKZU2R+4vRCHnXyJanVmXBWqkuUPF
874874
sigs.k8s.io/controller-tools v0.17.2/go.mod h1:4q5tZG2JniS5M5bkiXY2/potOiXyhoZVw/U48vLkXk0=
875875
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=
876876
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo=
877-
sigs.k8s.io/kubebuilder/v4 v4.5.2 h1:57lmVU1zwjOZAF28hBhZyaxE6qXreHYekI4yt/Q5rEU=
878-
sigs.k8s.io/kubebuilder/v4 v4.5.2/go.mod h1:oJrPYf8hkfLCh2vb40vD/Gm22CJsFHlGQz1mw2ZiQaY=
877+
sigs.k8s.io/kubebuilder/v4 v4.6.0 h1:SBc37jghs3L2UaEL91A1t5K5dANrEviUDuNic9hMQSw=
878+
sigs.k8s.io/kubebuilder/v4 v4.6.0/go.mod h1:zlXrnLiJPDPpK4hKCUrlgzzLOusfA8Sd8tpYGIrvD00=
879879
sigs.k8s.io/kustomize/api v0.18.0 h1:hTzp67k+3NEVInwz5BHyzc9rGxIauoXferXyjv5lWPo=
880880
sigs.k8s.io/kustomize/api v0.18.0/go.mod h1:f8isXnX+8b+SGLHQ6yO4JG1rdkZlvhaCf/uZbLVMb0U=
881881
sigs.k8s.io/kustomize/kyaml v0.18.1 h1:WvBo56Wzw3fjS+7vBjN6TeivvpbW9GmRaWZ9CIVmt4E=

images/custom-scorecard-tests/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the custom-scorecard-tests binary
2-
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
33
ARG TARGETARCH
44

55
WORKDIR /workspace

images/helm-operator/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
33
ARG TARGETARCH
44

55
WORKDIR /workspace

images/operator-sdk/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the operator-sdk binary
2-
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
33
ARG TARGETARCH
44

55
WORKDIR /workspace

images/scorecard-test-kuttl/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the scorecard-test-kuttl binary
2-
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
33
ARG TARGETARCH
44
ARG BUILDPLATFORM
55

images/scorecard-test/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the scorecard-test binary
2-
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
33
ARG TARGETARCH
44

55
WORKDIR /workspace

internal/plugins/manifests/v2/init.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"path/filepath"
2222
"strings"
2323

24-
"sigs.k8s.io/kubebuilder/v4/pkg/plugin/util"
25-
2624
"github.com/spf13/afero"
2725
"sigs.k8s.io/kubebuilder/v4/pkg/config"
2826
"sigs.k8s.io/kubebuilder/v4/pkg/machinery"
@@ -127,15 +125,6 @@ func (s *initSubcommand) Scaffold(fs machinery.Filesystem) error {
127125
return err
128126
}
129127

130-
// TODO: remove this when we bump kubebuilder to v5.x
131-
// Not adopt changes introduced by mistake in the default Makefile of kubebuilder v4.x.
132-
if operatorType == projutil.OperatorTypeGo {
133-
err = util.ReplaceInFile("Makefile", makefileTestE2ETarget, "")
134-
if err != nil {
135-
return fmt.Errorf("error replacing Makefile: %w", err)
136-
}
137-
}
138-
139128
return nil
140129
}
141130

@@ -322,17 +311,4 @@ catalog-build: opm ## Build a catalog image.
322311
catalog-push: ## Push a catalog image.
323312
$(MAKE) docker-push IMG=$(CATALOG_IMG)
324313
`
325-
326-
// TODO: remove it when we bump kubebuilder to v5.x
327-
// We will not adopt this change since it did not work and was a bug introduced in the
328-
// default Makefile of kubebuilder v4.x.
329-
makefileTestE2ETarget = `@command -v $(KIND) >/dev/null 2>&1 || { \
330-
echo "Kind is not installed. Please install Kind manually."; \
331-
exit 1; \
332-
}
333-
@$(KIND) get clusters | grep -q 'kind' || { \
334-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
335-
exit 1; \
336-
}
337-
`
338314
)

testdata/go/v4/memcached-operator/.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Kubebuilder DevContainer",
3-
"image": "docker.io/golang:1.23",
3+
"image": "golang:1.24",
44
"features": {
55
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
66
"ghcr.io/devcontainers/features/git:1": {}

testdata/go/v4/memcached-operator/.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
go-version-file: go.mod
1919

2020
- name: Run linter
21-
uses: golangci/golangci-lint-action@v6
21+
uses: golangci/golangci-lint-action@v8
2222
with:
23-
version: v1.63.4
23+
version: v2.1.0

testdata/go/v4/memcached-operator/.github/workflows/test-e2e.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29-
- name: Create kind cluster
30-
run: kind create cluster
31-
3229
- name: Running Test e2e
3330
run: |
3431
go mod tidy
Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
7+
- copyloopvar
228
- dupl
239
- errcheck
24-
- copyloopvar
2510
- ginkgolinter
2611
- goconst
2712
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3113
- govet
3214
- ineffassign
3315
- lll
@@ -36,12 +18,35 @@ linters:
3618
- prealloc
3719
- revive
3820
- staticcheck
39-
- typecheck
4021
- unconvert
4122
- unparam
4223
- unused
43-
44-
linters-settings:
45-
revive:
24+
settings:
25+
revive:
26+
rules:
27+
- name: comment-spacings
28+
- name: import-shadowing
29+
exclusions:
30+
generated: lax
4631
rules:
47-
- name: comment-spacings
32+
- linters:
33+
- lll
34+
path: api/*
35+
- linters:
36+
- dupl
37+
- lll
38+
path: internal/*
39+
paths:
40+
- third_party$
41+
- builtin$
42+
- examples$
43+
formatters:
44+
enable:
45+
- gofmt
46+
- goimports
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- third_party$
51+
- builtin$
52+
- examples$

testdata/go/v4/memcached-operator/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM docker.io/golang:1.23 AS builder
2+
FROM golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

testdata/go/v4/memcached-operator/Makefile

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
116116
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
117117
# CertManager is installed by default; skip with:
118118
# - CERT_MANAGER_INSTALL_SKIP=true
119+
KIND_CLUSTER ?= memcached-operator-test-e2e
120+
121+
.PHONY: setup-test-e2e
122+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
123+
@command -v $(KIND) >/dev/null 2>&1 || { \
124+
echo "Kind is not installed. Please install Kind manually."; \
125+
exit 1; \
126+
}
127+
$(KIND) create cluster --name $(KIND_CLUSTER)
128+
119129
.PHONY: test-e2e
120-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
121-
go test ./test/e2e/ -v -ginkgo.v
130+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
131+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
132+
$(MAKE) cleanup-test-e2e
133+
134+
.PHONY: cleanup-test-e2e
135+
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
136+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
122137

123138
.PHONY: lint
124139
lint: golangci-lint ## Run golangci-lint linter
@@ -216,12 +231,12 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
216231

217232
## Tool Versions
218233
KUSTOMIZE_VERSION ?= v5.6.0
219-
CONTROLLER_TOOLS_VERSION ?= v0.17.2
234+
CONTROLLER_TOOLS_VERSION ?= v0.18.0
220235
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
221236
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
222237
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
223238
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
224-
GOLANGCI_LINT_VERSION ?= v1.63.4
239+
GOLANGCI_LINT_VERSION ?= v2.1.0
225240

226241
.PHONY: kustomize
227242
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -249,7 +264,7 @@ $(ENVTEST): $(LOCALBIN)
249264
.PHONY: golangci-lint
250265
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
251266
$(GOLANGCI_LINT): $(LOCALBIN)
252-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
267+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
253268

254269
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
255270
# $1 - target path with name of binary

0 commit comments

Comments
 (0)