Skip to content

WIP: ⚠️ Upgrade from Kubebuilder 4.5.2 to 4.6.0 and add support for k8s 1.33 #6954

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export IMAGE_VERSION = v1.39.2
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)
export GIT_VERSION = $(shell git describe --dirty --tags --always)
export GIT_COMMIT = $(shell git rev-parse HEAD)
export K8S_VERSION = 1.32.0
export K8S_VERSION = 1.33.0

# Build settings
export TOOLS_DIR = tools/bin
Expand Down
120 changes: 120 additions & 0 deletions changelog/fragments/upgrade_kb_latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
entries:
- description: >
For Go-based operators, upgrade the Go version from `1.23` to `1.24`
kind: "change"
breaking: true
migration:
header: Upgrade Go version to 1.24
body: |
Update the Go version used to `1.24`. This affects:

**Dockerfile:**
```dockerfile
-FROM golang:1.23 AS builder
+FROM golang:1.24 AS builder
```

**.devcontainer/devcontainer.json:**
```json
- "image": "golang:1.23",
+ "image": "golang:1.24",
```

**go.mod:**
```go
-go 1.23.0
+go 1.24.0
```

- description: >
For Go-based operators, upgrade golangci-lint to `v2.1.0` and update `.golangci.yml`
to the v2 config format with enhanced structure and controls.
kind: "change"
breaking: false
migration:
header: Upgrade golangci-lint and use v2 config
body: |
Update golangci-lint usage across the project:

**Makefile:**
```makefile
-GOLANGCI_LINT_VERSION ?= v1.63.4
+GOLANGCI_LINT_VERSION ?= v2.1.0

-$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
+$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
```

**GitHub Actions Workflow:**
```yaml
- uses: golangci/golangci-lint-action@v6
+ uses: golangci/golangci-lint-action@v8
```

**.golangci.yml:**
Convert to v2 layout with keys like `version`, `linters`, `settings`, `formatters`, `exclusions`.
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)

- description: >
For Go-based operators, upgrade controller-gen from `v0.17.2` to `v0.18.0`.
kind: "change"
breaking: false
migration:
header: Upgrade controller-gen to `v0.18.0`
body: |
Update controller-gen tooling and annotations:

**Makefile:**
```makefile
-CONTROLLER_TOOLS_VERSION ?= v0.17.2
+CONTROLLER_TOOLS_VERSION ?= v0.18.0
```

Run `make generate` to regenerate code and manifests with the new version.

- description: >
For Go-based operators, upgrade controller-runtime from `v0.20.4` to `v0.21.0`
and kubernetes dependencies to `v0.33`.
kind: "change"
breaking: false
migration:
header: Upgrade controller-runtime to `v0.21.0`
body: |
Update the `go.mod` import:
```go
-sigs.k8s.io/controller-runtime v0.20.4
+sigs.k8s.io/controller-runtime v0.21.0
```

Run `go mod tidy` to upgrade the k8s dependencies.

- description: >
For Go-based operators, add new target to setup/teardown Kind cluster for E2E tests
and remove Kind setup from CI workflows.
kind: "addition"
breaking: false
migration:
header: Add cluster setup for e2e tests in Makefile and update CI workflow
body: |
Remove direct Kind commands in GitHub workflows:

**Removed:**
```yaml
- name: Create kind cluster
run: kind create cluster
```

**Added to Makefile:**
```makefile
KIND_CLUSTER ?= memcached-operator-test-e2e

.PHONY: setup-test-e2e
setup-test-e2e:
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: cleanup-test-e2e
cleanup-test-e2e:
$(KIND) delete cluster --name $(KIND_CLUSTER)
```

Update `test-e2e` target to call these appropriately.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/operator-framework/operator-sdk

go 1.23.6
go 1.24.3

require (
github.com/blang/semver/v4 v4.0.0
Expand Down Expand Up @@ -41,7 +41,7 @@ require (
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e
sigs.k8s.io/controller-runtime v0.20.4
sigs.k8s.io/controller-tools v0.17.2
sigs.k8s.io/kubebuilder/v4 v4.5.2
sigs.k8s.io/kubebuilder/v4 v4.6.0
sigs.k8s.io/yaml v1.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,8 @@ sigs.k8s.io/controller-tools v0.17.2 h1:jNFOKps8WnaRKZU2R+4vRCHnXyJanVmXBWqkuUPF
sigs.k8s.io/controller-tools v0.17.2/go.mod h1:4q5tZG2JniS5M5bkiXY2/potOiXyhoZVw/U48vLkXk0=
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo=
sigs.k8s.io/kubebuilder/v4 v4.5.2 h1:57lmVU1zwjOZAF28hBhZyaxE6qXreHYekI4yt/Q5rEU=
sigs.k8s.io/kubebuilder/v4 v4.5.2/go.mod h1:oJrPYf8hkfLCh2vb40vD/Gm22CJsFHlGQz1mw2ZiQaY=
sigs.k8s.io/kubebuilder/v4 v4.6.0 h1:SBc37jghs3L2UaEL91A1t5K5dANrEviUDuNic9hMQSw=
sigs.k8s.io/kubebuilder/v4 v4.6.0/go.mod h1:zlXrnLiJPDPpK4hKCUrlgzzLOusfA8Sd8tpYGIrvD00=
sigs.k8s.io/kustomize/api v0.18.0 h1:hTzp67k+3NEVInwz5BHyzc9rGxIauoXferXyjv5lWPo=
sigs.k8s.io/kustomize/api v0.18.0/go.mod h1:f8isXnX+8b+SGLHQ6yO4JG1rdkZlvhaCf/uZbLVMb0U=
sigs.k8s.io/kustomize/kyaml v0.18.1 h1:WvBo56Wzw3fjS+7vBjN6TeivvpbW9GmRaWZ9CIVmt4E=
Expand Down
2 changes: 1 addition & 1 deletion images/custom-scorecard-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the custom-scorecard-tests binary
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion images/helm-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion images/operator-sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the operator-sdk binary
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion images/scorecard-test-kuttl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the scorecard-test-kuttl binary
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
ARG TARGETARCH
ARG BUILDPLATFORM

Expand Down
2 changes: 1 addition & 1 deletion images/scorecard-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the scorecard-test binary
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
24 changes: 0 additions & 24 deletions internal/plugins/manifests/v2/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"path/filepath"
"strings"

"sigs.k8s.io/kubebuilder/v4/pkg/plugin/util"

"github.com/spf13/afero"
"sigs.k8s.io/kubebuilder/v4/pkg/config"
"sigs.k8s.io/kubebuilder/v4/pkg/machinery"
Expand Down Expand Up @@ -127,15 +125,6 @@ func (s *initSubcommand) Scaffold(fs machinery.Filesystem) error {
return err
}

// TODO: remove this when we bump kubebuilder to v5.x
// Not adopt changes introduced by mistake in the default Makefile of kubebuilder v4.x.
if operatorType == projutil.OperatorTypeGo {
err = util.ReplaceInFile("Makefile", makefileTestE2ETarget, "")
if err != nil {
return fmt.Errorf("error replacing Makefile: %w", err)
}
}

return nil
}

Expand Down Expand Up @@ -322,17 +311,4 @@ catalog-build: opm ## Build a catalog image.
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)
`

// TODO: remove it when we bump kubebuilder to v5.x
// We will not adopt this change since it did not work and was a bug introduced in the
// default Makefile of kubebuilder v4.x.
makefileTestE2ETarget = `@command -v $(KIND) >/dev/null 2>&1 || { \
echo "Kind is not installed. Please install Kind manually."; \
exit 1; \
}
@$(KIND) get clusters | grep -q 'kind' || { \
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
exit 1; \
}
`
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Kubebuilder DevContainer",
"image": "docker.io/golang:1.23",
"image": "golang:1.24",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
Expand Down
4 changes: 2 additions & 2 deletions testdata/go/v4/memcached-operator/.github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
go-version-file: go.mod

- name: Run linter
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: v1.63.4
version: v2.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
- name: Verify kind installation
run: kind version

- name: Create kind cluster
run: kind create cluster

- name: Running Test e2e
run: |
go mod tidy
Expand Down
57 changes: 31 additions & 26 deletions testdata/go/v4/memcached-operator/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
version: "2"
run:
timeout: 5m
allow-parallel-runners: true

issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
# restore some of the defaults
# (fill in the rest as needed)
exclude-rules:
- path: "api/*"
linters:
- lll
- path: "internal/*"
linters:
- dupl
- lll
linters:
disable-all: true
default: none
enable:
- copyloopvar
- dupl
- errcheck
- copyloopvar
- ginkgolinter
- goconst
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- lll
Expand All @@ -36,12 +18,35 @@ linters:
- prealloc
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- unused

linters-settings:
revive:
settings:
revive:
rules:
- name: comment-spacings
- name: import-shadowing
exclusions:
generated: lax
rules:
- name: comment-spacings
- linters:
- lll
path: api/*
- linters:
- dupl
- lll
path: internal/*
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion testdata/go/v4/memcached-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM docker.io/golang:1.23 AS builder
FROM golang:1.24 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
25 changes: 20 additions & 5 deletions testdata/go/v4/memcached-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
# CertManager is installed by default; skip with:
# - CERT_MANAGER_INSTALL_SKIP=true
KIND_CLUSTER ?= memcached-operator-test-e2e

.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
@command -v $(KIND) >/dev/null 2>&1 || { \
echo "Kind is not installed. Please install Kind manually."; \
exit 1; \
}
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: test-e2e
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
go test ./test/e2e/ -v -ginkgo.v
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

.PHONY: cleanup-test-e2e
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
@$(KIND) delete cluster --name $(KIND_CLUSTER)

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
Expand Down Expand Up @@ -216,12 +231,12 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint

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

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down Expand Up @@ -249,7 +264,7 @@ $(ENVTEST): $(LOCALBIN)
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

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