Skip to content

Commit a81d55c

Browse files
operator: upgrade to v1.42.1 using upgrade-operator-sdk tool
python3 tools/upgrade-operator-sdk/upgrade.py --operator-dir operator tools/upgrade-operator-sdk/operator Scaffold realigned with operator-sdk v1.42.1, Go bumped to 1.24.13, k8s.io dependencies pinned to v0.33.10.
1 parent a060546 commit a81d55c

Some content is hidden

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

55 files changed

+1822
-787
lines changed

operator/.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
22
# Ignore build and test binaries.
33
bin/
4-
testbin/

operator/.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
21
# Binaries for programs and plugins
32
*.exe
43
*.exe~
54
*.dll
65
*.so
76
*.dylib
8-
bin
9-
testbin/*
7+
bin/*
8+
Dockerfile.cross
109

11-
# Test binary, build with `go test -c`
10+
# Test binary, built with `go test -c`
1211
*.test
1312

1413
# Output of the go coverage tool, specifically when used with LiteIDE
1514
*.out
1615

17-
# Kubernetes Generated files - skip generated files, except for vendored files
16+
# Go workspace file
17+
go.work
1818

19+
# Kubernetes Generated files - skip generated files, except for vendored files
1920
!vendor/**/zz_generated.*
2021

2122
# editor and IDE paraphernalia
2223
.idea
24+
.vscode
2325
*.swp
2426
*.swo
2527
*~

operator/.golangci.yml

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +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
2410
- ginkgolinter
2511
- goconst
2612
- gocyclo
27-
- gofmt
28-
- goimports
29-
- gosimple
3013
- govet
3114
- ineffassign
3215
- lll
@@ -35,12 +18,35 @@ linters:
3518
- prealloc
3619
- revive
3720
- staticcheck
38-
- typecheck
3921
- unconvert
4022
- unparam
4123
- unused
42-
43-
linters-settings:
44-
revive:
24+
settings:
25+
revive:
26+
rules:
27+
- name: comment-spacings
28+
- name: import-shadowing
29+
exclusions:
30+
generated: lax
4531
rules:
46-
- 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$

operator/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22 as builder
2+
FROM golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -14,7 +14,7 @@ RUN go mod download
1414
# Copy the go source
1515
COPY cmd/main.go cmd/main.go
1616
COPY api/ api/
17-
COPY internal/controller/ internal/controller/
17+
COPY internal/ internal/
1818
COPY pkg/ pkg/
1919
COPY version/ version/
2020

operator/Makefile

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,9 @@ endif
4848

4949
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5050
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51-
OPERATOR_SDK_VERSION ?= v1.37.0
52-
51+
OPERATOR_SDK_VERSION ?= v1.42.1
5352
# Image URL to use all building/pushing image targets
5453
IMG ?= controller:latest
55-
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
56-
ENVTEST_K8S_VERSION = 1.30.0
57-
58-
# Force Go toolchain version to prevent automatic selection issues
59-
# See: https://go.dev/doc/toolchain
60-
export GOTOOLCHAIN = go1.22.12
6154

6255
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6356
ifeq (,$(shell go env GOBIN))
@@ -116,21 +109,50 @@ vet: ## Run go vet against code.
116109
go vet ./...
117110

118111
.PHONY: test
119-
test: manifests generate fmt vet envtest ## Run tests.
120-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out
121-
122-
.PHONY: test-e2e # You will need to have a Kind cluster up in running to run this target
123-
test-e2e:
124-
go test ./test/e2e/ -v -ginkgo.v
112+
test: manifests generate fmt vet setup-envtest ## Run tests.
113+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
114+
115+
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
116+
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
117+
# CertManager is installed by default; skip with:
118+
# - CERT_MANAGER_INSTALL_SKIP=true
119+
KIND_CLUSTER ?= 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+
@case "$$($(KIND) get clusters)" in \
128+
*"$(KIND_CLUSTER)"*) \
129+
echo "Kind cluster '$(KIND_CLUSTER)' already exists. Skipping creation." ;; \
130+
*) \
131+
echo "Creating Kind cluster '$(KIND_CLUSTER)'..."; \
132+
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
133+
esac
134+
135+
.PHONY: test-e2e
136+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
137+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
138+
$(MAKE) cleanup-test-e2e
139+
140+
.PHONY: cleanup-test-e2e
141+
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
142+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
125143

126144
.PHONY: lint
127-
lint: golangci-lint ## Run golangci-lint linter & yamllint
145+
lint: golangci-lint ## Run golangci-lint linter
128146
$(GOLANGCI_LINT) run
129147

130148
.PHONY: lint-fix
131149
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
132150
$(GOLANGCI_LINT) run --fix
133151

152+
.PHONY: lint-config
153+
lint-config: golangci-lint ## Verify golangci-lint linter configuration
154+
$(GOLANGCI_LINT) config verify
155+
134156
##@ Build
135157

136158
.PHONY: build
@@ -163,10 +185,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
163185
docker-buildx: ## Build and push docker image for the manager for cross-platform support
164186
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
165187
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
166-
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
167-
$(CONTAINER_TOOL) buildx use project-v3-builder
188+
- $(CONTAINER_TOOL) buildx create --name operator-builder
189+
$(CONTAINER_TOOL) buildx use operator-builder
168190
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
169-
- $(CONTAINER_TOOL) buildx rm project-v3-builder
191+
- $(CONTAINER_TOOL) buildx rm operator-builder
170192
rm Dockerfile.cross
171193

172194
.PHONY: build-installer
@@ -207,16 +229,20 @@ $(LOCALBIN):
207229

208230
## Tool Binaries
209231
KUBECTL ?= kubectl
232+
KIND ?= kind
210233
KUSTOMIZE ?= $(LOCALBIN)/kustomize
211234
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
212235
ENVTEST ?= $(LOCALBIN)/setup-envtest
213236
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
214237

215238
## Tool Versions
216-
KUSTOMIZE_VERSION ?= v5.4.2
217-
CONTROLLER_TOOLS_VERSION ?= v0.15.0
218-
ENVTEST_VERSION ?= release-0.19
219-
GOLANGCI_LINT_VERSION ?= v1.59.1
239+
KUSTOMIZE_VERSION ?= v5.6.0
240+
CONTROLLER_TOOLS_VERSION ?= v0.18.0
241+
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
242+
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
243+
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
244+
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
245+
GOLANGCI_LINT_VERSION ?= v2.1.0
220246

221247
.PHONY: kustomize
222248
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -228,18 +254,26 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
228254
$(CONTROLLER_GEN): $(LOCALBIN)
229255
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
230256

257+
.PHONY: setup-envtest
258+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
259+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
260+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
261+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
262+
exit 1; \
263+
}
264+
231265
.PHONY: envtest
232266
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
233267
$(ENVTEST): $(LOCALBIN)
234268
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
235-
269+
236270
.PHONY: golangci-lint
237271
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
238272
$(GOLANGCI_LINT): $(LOCALBIN)
239-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
240-
273+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
274+
241275
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
242-
# $1 - target path with name of binary (ideally with version)
276+
# $1 - target path with name of binary
243277
# $2 - package url which can be installed
244278
# $3 - specific version of package
245279
define go-install-tool
@@ -273,14 +307,14 @@ endif
273307

274308
.PHONY: bundle
275309
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
276-
$(OPERATOR_SDK) generate kustomize manifests --interactive=false -q
310+
$(OPERATOR_SDK) generate kustomize manifests -q
277311
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
278312
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
279313
$(OPERATOR_SDK) bundle validate ./bundle
280314

281315
.PHONY: bundle-build
282316
bundle-build: ## Build the bundle image.
283-
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
317+
$(CONTAINER_TOOL) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
284318

285319
.PHONY: bundle-push
286320
bundle-push: ## Push the bundle image.
@@ -295,7 +329,7 @@ ifeq (,$(shell which opm 2>/dev/null))
295329
set -e ;\
296330
mkdir -p $(dir $(OPM)) ;\
297331
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
298-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
332+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.55.0/$${OS}-$${ARCH}-opm ;\
299333
chmod +x $(OPM) ;\
300334
}
301335
else
@@ -320,14 +354,18 @@ endif
320354
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
321355
.PHONY: catalog-build
322356
catalog-build: opm ## Build a catalog image.
323-
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
357+
$(OPM) index add --container-tool $(CONTAINER_TOOL) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
324358

325359
# Push the catalog image.
326360
.PHONY: catalog-push
327361
catalog-push: ## Push a catalog image.
328362
$(MAKE) docker-push IMG=$(CATALOG_IMG)
329363

364+
# Force Go toolchain version
365+
export GOTOOLCHAIN = go1.24.13
366+
330367
.PHONY: metalk8s
331368
metalk8s: manifests kustomize ## Generate MetalK8s resulting manifests
369+
mkdir -p deploy
332370
$(KUSTOMIZE) build config/metalk8s | \
333371
sed 's/BUILD_IMAGE_CLUSTER_OPERATOR:latest/{{ build_image_name("metalk8s-operator") }}/' > deploy/manifests.yaml

0 commit comments

Comments
 (0)