Skip to content

Commit f07fc44

Browse files
authored
Upgrade to kubebuilder v4 (#1019)
* Upgrade to kubebuilder v4 * Address kustomize warnings except patchesStrategicMerge * Upgrade kustomize to v5.7.0 * Remove prometheus config --------- Signed-off-by: Rob Hundley <[email protected]>
1 parent 5985c6b commit f07fc44

File tree

130 files changed

+1382
-1449
lines changed

Some content is hidden

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

130 files changed

+1382
-1449
lines changed

.devcontainer/devcontainer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "Kubebuilder DevContainer",
3+
"image": "docker.io/golang:1.23",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/git:1": {}
7+
},
8+
9+
"runArgs": ["--network=host"],
10+
11+
"customizations": {
12+
"vscode": {
13+
"settings": {
14+
"terminal.integrated.shell.linux": "/bin/bash"
15+
},
16+
"extensions": [
17+
"ms-kubernetes-tools.vscode-kubernetes-tools",
18+
"ms-azuretools.vscode-docker"
19+
]
20+
}
21+
},
22+
23+
"onCreateCommand": "bash .devcontainer/post-install.sh"
24+
}
25+

.devcontainer/post-install.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -x
3+
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
5+
chmod +x ./kind
6+
mv ./kind /usr/local/bin/kind
7+
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
9+
chmod +x kubebuilder
10+
mv kubebuilder /usr/local/bin/
11+
12+
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
13+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
14+
chmod +x kubectl
15+
mv kubectl /usr/local/bin/kubectl
16+
17+
docker network create -d=bridge --subnet=172.19.0.0/24 kind
18+
19+
kind version
20+
kubebuilder version
21+
docker --version
22+
go version
23+
kubectl version --client

.golangci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
run:
2+
timeout: 5m
3+
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
19+
linters:
20+
disable-all: true
21+
enable:
22+
- dupl
23+
- errcheck
24+
- copyloopvar
25+
- ginkgolinter
26+
- goconst
27+
- gocyclo
28+
- gofmt
29+
- goimports
30+
- gosimple
31+
- govet
32+
- ineffassign
33+
- lll
34+
- misspell
35+
- nakedret
36+
- prealloc
37+
- revive
38+
- staticcheck
39+
- typecheck
40+
- unconvert
41+
- unparam
42+
- unused
43+
44+
linters-settings:
45+
revive:
46+
rules:
47+
- name: comment-spacings

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ VERSION="${NEW_VERSION:-}" make update-version
143143
```
144144

145145
This will update all image tags, the production kustomize overlays, and the
146-
version set in [version.go](./version/version.go) with the SemVer value of
146+
version set in [version.go](./internal/version/version.go) with the SemVer value of
147147
`VERSION`. After this target completes successfully, you should also run
148148
`make bundle` to update the latest production bundle with these new version
149149
values.

Makefile

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ endif
4343

4444
TESTARGS_DEFAULT := "-v"
4545
export TESTARGS ?= $(TESTARGS_DEFAULT)
46-
BUNDLE_VERSION ?= $(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"')
46+
BUNDLE_VERSION ?= $(shell cat ./internal/version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"')
4747
VERSION ?= $(BUNDLE_VERSION)
4848

4949
LOCAL_OS := $(shell uname)
@@ -161,24 +161,30 @@ LOCALBIN ?= $(shell pwd)/bin
161161
$(LOCALBIN):
162162
mkdir -p $(LOCALBIN)
163163

164-
## Tool Binaries
164+
## Local Tool Binaries
165+
KUBECTL ?= kubectl
166+
KIND ?= kind
167+
168+
## Repo Tool Binaries
165169
KUSTOMIZE ?= $(LOCALBIN)/kustomize
166170
YQ ?= $(LOCALBIN)/yq
167171
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
168172
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
169173
ENVTEST ?= $(LOCALBIN)/setup-envtest
174+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
170175

171176
## Tool Versions
172-
KUSTOMIZE_VERSION ?= v5.4.3
177+
KUSTOMIZE_VERSION ?= v5.7.0
173178
CONTROLLER_TOOLS_VERSION ?= v0.17.2
174179
OPERATOR_SDK_VERSION ?= v1.37.0
175180
YQ_VERSION ?= v4.44.3
176181
GO_VERSION ?= 1.24.1
177182

178-
# ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
183+
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
179184
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
180-
# ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
185+
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
181186
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
187+
GOLANGCI_LINT_VERSION ?= v1.63.4
182188

183189
# This pinned version of go has its version pinned to its name, so order of operations is inverted here.
184190
GO ?= $(LOCALBIN)/go$(GO_VERSION)
@@ -208,8 +214,7 @@ $(KUSTOMIZE): $(LOCALBIN) go
208214
.PHONY: controller-gen
209215
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
210216
$(CONTROLLER_GEN): $(LOCALBIN) go
211-
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
212-
GOSUMDB=sum.golang.org GOBIN=$(LOCALBIN) $(GO) install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
217+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
213218

214219
.PHONY: operator-sdk
215220
operator-sdk: $(OPERATOR_SDK) ## Download operator-sdk locally if necessary. If wrong version is installed, it will be overwritten.
@@ -229,11 +234,7 @@ $(OPERATOR_SDK): $(LOCALBIN) go
229234
.PHONY: yq
230235
yq: $(YQ)
231236
$(YQ): $(LOCALBIN) go
232-
@if test -x $(LOCALBIN)/yq && ! $(LOCALBIN)/yq --version | grep -q $(YQ_VERSION); then \
233-
echo "$(LOCALBIN)/yq version is not expected $(YQ_VERSION). Removing it before installing."; \
234-
rm -rf $(LOCALBIN)/yq; \
235-
fi
236-
test -s $(LOCALBIN)/yq || GOSUMDB=sum.golang.org GOBIN=$(LOCALBIN) $(GO) install github.com/mikefarah/yq/v4@$(YQ_VERSION)
237+
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/v4,$(YQ_VERSION))
237238

238239
.PHONY: setup-envtest
239240
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
@@ -247,7 +248,12 @@ setup-envtest: envtest ## Download the binaries required for ENVTEST in the loca
247248
.PHONY: envtest
248249
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
249250
$(ENVTEST): $(LOCALBIN) go
250-
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) $(GO) install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION)
251+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
252+
253+
.PHONY: golangci-lint
254+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
255+
$(GOLANGCI_LINT): $(LOCALBIN)
256+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
251257

252258
.PHONY: opm
253259
OPM = ./bin/opm
@@ -311,24 +317,51 @@ vet: ## Run go vet against code.
311317

312318
.PHONY: test
313319
test: manifests generate fmt vet envtest ## Run tests.
314-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GO) test ./... -coverprofile cover.out
320+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GO) test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
321+
322+
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
323+
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
324+
# CertManager is installed by default; skip with:
325+
# - CERT_MANAGER_INSTALL_SKIP=true
326+
.PHONY: test-e2e
327+
test-e2e: go manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
328+
@command -v $(KIND) >/dev/null 2>&1 || { \
329+
echo "Kind is not installed. Please install Kind manually."; \
330+
exit 1; \
331+
}
332+
@$(KIND) get clusters | grep -q 'kind' || { \
333+
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
334+
exit 1; \
335+
}
336+
$(GO) test ./test/e2e/ -v -ginkgo.v
315337

316338
.PHONY: update-version
317339
update-version: manifests kustomize yq ## Update the Operator SemVer across the project.
318340
./hack/update_operator_version
319341

342+
.PHONY: lint
343+
lint: golangci-lint ## Run golangci-lint linter
344+
$(GOLANGCI_LINT) run
345+
346+
.PHONY: lint-fix
347+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
348+
$(GOLANGCI_LINT) run --fix
349+
350+
.PHONY: lint-config
351+
lint-config: golangci-lint ## Verify golangci-lint linter configuration
352+
$(GOLANGCI_LINT) config verify
320353

321354
##@ Build
322355

323356
.PHONY: build
324357
build: go manifests generate fmt vet ## Build manager binary.
325358
@echo "Building the manager binary"
326-
@CGO_ENABLED=0 $(GO) build -o build/_output/bin/manager main.go
359+
@CGO_ENABLED=0 $(GO) build -o build/_output/bin/manager cmd/main.go
327360
@strip $(STRIP_FLAGS) build/_output/bin/manager
328361

329362
.PHONY: run
330363
run: go manifests generate fmt vet ## Run a controller from your host.
331-
$(GO) run ./main.go
364+
$(GO) run ./cmd/main.go
332365

333366
.PHONY: licenses-dir
334367
licenses-dir:
@@ -383,7 +416,7 @@ bundle-render: ## Render the bundle contents into the local FBC index.
383416
TARGET_ARCH=$(LOCAL_ARCH)
384417
build-image: $(GO) $(CONFIG_DOCKER_TARGET) licenses-dir ## Build the Operator manager image
385418
@echo "Building manager binary for linux/$(TARGET_ARCH)"
386-
@CGO_ENABLED=0 GOOS=linux GOARCH=$(TARGET_ARCH) $(GO) build -a -o build/_output/bin/manager main.go
419+
@CGO_ENABLED=0 GOOS=linux GOARCH=$(TARGET_ARCH) $(GO) build -a -o build/_output/bin/manager cmd/main.go
387420
@echo "Building manager image for linux/$(TARGET_ARCH)"
388421
@DOCKER_BUILDKIT=1 $(CONTAINER_CLI) build --platform=linux/$(TARGET_ARCH) ${IMAGE_BUILD_OPTS} -t $(REGISTRY)/$(IMG)-$(TARGET_ARCH):$(GIT_COMMIT_ID) -f ./Dockerfile .
389422
@echo "Inspect built image $(REGISTRY)/$(IMG)-$(TARGET_ARCH):$(GIT_COMMIT_ID)"
@@ -471,3 +504,19 @@ clean-all: clean-bin clean-dev clean-licenses ## Runs all cleanup targets.
471504

472505

473506
.PHONY: all build run check install uninstall code-dev test test-e2e coverage images csv clean-all clean-bin clean-dev clean-licenses help
507+
508+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
509+
# $1 - target path with name of binary
510+
# $2 - package url which can be installed
511+
# $3 - specific version of package
512+
define go-install-tool
513+
@[ -f "$(1)-$(3)" ] || { \
514+
set -e; \
515+
package=$(2)@$(3) ;\
516+
echo "Downloading $${package}" ;\
517+
rm -f $(1) || true ;\
518+
GOBIN=$(LOCALBIN) $(GO) install $${package} ;\
519+
mv $(1) $(1)-$(3) ;\
520+
} ;\
521+
ln -sf $(1)-$(3) $(1)
522+
endef

PROJECT

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
# More info: https://book.kubebuilder.io/reference/project-config.html
55
domain: ibm.com
66
layout:
7-
- go.kubebuilder.io/v3
7+
- go.kubebuilder.io/v4
88
multigroup: true
9-
plugins:
10-
manifests.sdk.operatorframework.io/v2: {}
11-
scorecard.sdk.operatorframework.io/v2: {}
129
projectName: ibm-iam-operator
1310
repo: github.com/IBM/ibm-iam-operator
1411
resources:
@@ -17,17 +14,17 @@ resources:
1714
namespaced: true
1815
controller: true
1916
domain: ibm.com
20-
group: oidc.security
21-
kind: Client
22-
path: github.com/IBM/ibm-iam-operator/apis/oidc.security/v1
23-
version: v1
17+
group: operator
18+
kind: Authentication
19+
path: github.com/IBM/ibm-iam-operator/api/operator/v1alpha1
20+
version: v1alpha1
2421
- api:
2522
crdVersion: v1
2623
namespaced: true
2724
controller: true
2825
domain: ibm.com
29-
group: operator
30-
kind: Authentication
31-
path: github.com/IBM/ibm-iam-operator/apis/operator/v1alpha1
32-
version: v1alpha1
26+
group: oidc.security
27+
kind: Client
28+
path: github.com/IBM/ibm-iam-operator/api/oidc.security/v1
29+
version: v1
3330
version: "3"

apis/oidc.security/v1/groupversion_info.go renamed to api/oidc.security/v1/groupversion_info.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1 contains API Schema definitions for the oidc.security v1 API group
17+
// Package v1 contains API Schema definitions for the oidc.security v1 API group.
1818
// +kubebuilder:object:generate=true
1919
// +groupName=oidc.security.ibm.com
2020
package v1
@@ -25,10 +25,10 @@ import (
2525
)
2626

2727
var (
28-
// GroupVersion is group version used to register these objects
28+
// GroupVersion is group version used to register these objects.
2929
GroupVersion = schema.GroupVersion{Group: "oidc.security.ibm.com", Version: "v1"}
3030

31-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
3232
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
3333

3434
// AddToScheme adds the types in this group-version to the given scheme.

apis/oidc.security/v1/zz_generated.deepcopy.go renamed to api/oidc.security/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)