Skip to content

Commit b9555d1

Browse files
authored
Merge pull request #103 from Fedosin/kubebuilderv4
✨ port to kubebuilder v4
2 parents 3cd1d3c + 63789f2 commit b9555d1

29 files changed

+81
-62
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ COPY ./ ./
3838
# Cache the go build into the the Go’s compiler cache folder so we take benefits of compiler caching across docker build calls
3939
RUN --mount=type=cache,target=/root/.cache/go-build \
4040
--mount=type=cache,target=/go/pkg/mod \
41-
go build .
41+
go build cmd/main.go
4242

4343
# Build
44-
ARG package=.
44+
ARG path=cmd/main.go
4545
ARG ARCH
4646
ARG ldflags
4747

@@ -50,7 +50,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
5050
--mount=type=cache,target=/go/pkg/mod \
5151
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
5252
go build -ldflags "${ldflags} -extldflags '-static'" \
53-
-o manager ${package}
53+
-o manager ${path}
5454

5555
# Production image
5656
FROM gcr.io/distroless/static:nonroot

Makefile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ GO_INSTALL := ./scripts/go_install.sh
4848
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
4949

5050
# Kubebuilder
51-
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.24.2
51+
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.26.1
5252
export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT ?= 60s
5353
export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?= 60s
5454

@@ -61,15 +61,15 @@ IMAGE_REVIEWERS ?= $(shell ./hack/get-project-maintainers.sh)
6161

6262
# Binaries.
6363
# Need to use abspath so we can invoke these from subdirectories
64-
CONTROLLER_GEN_VER := v0.9.2
64+
CONTROLLER_GEN_VER := v0.12.0
6565
CONTROLLER_GEN_BIN := controller-gen
6666
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)
6767

6868
GOLANGCI_LINT_VER := v1.51.2
6969
GOLANGCI_LINT_BIN := golangci-lint
7070
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
7171

72-
KUSTOMIZE_VER := v4.5.2
72+
KUSTOMIZE_VER := v5.0.1
7373
KUSTOMIZE_BIN := kustomize
7474
KUSTOMIZE := $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER)
7575

@@ -81,7 +81,7 @@ GOTESTSUM_VER := v1.6.4
8181
GOTESTSUM_BIN := gotestsum
8282
GOTESTSUM := $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER)
8383

84-
GINKGO_VER := v2.9.0
84+
GINKGO_VER := v2.9.2
8585
GINKGO_BIN := ginkgo
8686
GINKGO := $(TOOLS_BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER)
8787

@@ -166,7 +166,7 @@ yq: $(YQ) ## Build a local copy of yq.
166166
kpromo: $(KPROMO) ## Build a local copy of kpromo.
167167

168168
$(KUSTOMIZE): ## Build kustomize from tools folder.
169-
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) sigs.k8s.io/kustomize/kustomize/v4 $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)
169+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) sigs.k8s.io/kustomize/kustomize/v5 $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)
170170

171171
$(GO_APIDIFF): ## Build go-apidiff from tools folder.
172172
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/joelanford/go-apidiff $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)
@@ -236,7 +236,7 @@ test-junit: $(SETUP_ENVTEST) $(GOTESTSUM) ## Run tests with verbose setting and
236236

237237
.PHONY: operator
238238
operator: ## Build operator binary
239-
go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/operator sigs.k8s.io/cluster-api-operator
239+
go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/operator cmd/main.go
240240

241241
## --------------------------------------
242242
## Lint / Verify
@@ -285,15 +285,14 @@ generate: $(CONTROLLER_GEN) ## Generate code
285285
.PHONY: generate-go
286286
generate-go: $(CONTROLLER_GEN) ## Runs Go related generate targets for the operator
287287
$(CONTROLLER_GEN) \
288-
object:headerFile=$(ROOT)/hack/boilerplate/boilerplate.generatego.txt \
288+
object:headerFile=$(ROOT)/hack/boilerplate.go.txt \
289289
paths=./api/...
290290

291291
.PHONY: generate-manifests
292292
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests for the operator e.g. CRD, RBAC etc.
293293
$(CONTROLLER_GEN) \
294294
paths=./api/... \
295-
paths=./controllers/... \
296-
paths=./webhook/... \
295+
paths=./internal/controller/... \
297296
crd:crdVersions=v1 \
298297
rbac:roleName=manager-role \
299298
output:crd:dir=./config/crd/bases \
@@ -459,7 +458,7 @@ clean-release: ## Remove the release folder
459458
## E2E
460459
## --------------------------------------
461460

462-
.PHONY: e2e-test
461+
.PHONY: test-e2e
463462
test-e2e: $(KUSTOMIZE)
464463
$(MAKE) release-manifests
465464
$(MAKE) test-e2e-run

PROJECT

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: cluster.x-k8s.io
2-
repo: sigs.k8s.io/cluster-api
6+
layout:
7+
- go.kubebuilder.io/v4
8+
projectName: cluster-api-operator-migration
9+
repo: sigs.k8s.io/cluster-api-operator
310
resources:
4-
- group: operator
11+
- api:
12+
crdVersion: v1
13+
namespaced: true
14+
controller: true
15+
domain: cluster.x-k8s.io
16+
group: operator
517
kind: CoreProvider
18+
path: sigs.k8s.io/cluster-api-operator/api/v1alpha1
619
version: v1alpha1
7-
- group: operator
20+
- api:
21+
crdVersion: v1
22+
namespaced: true
23+
domain: cluster.x-k8s.io
24+
group: operator
825
kind: BootstrapProvider
26+
path: sigs.k8s.io/cluster-api-operator/api/v1alpha1
927
version: v1alpha1
10-
- group: operator
28+
- api:
29+
crdVersion: v1
30+
namespaced: true
31+
domain: cluster.x-k8s.io
32+
group: operator
1133
kind: ControlPlaneProvider
34+
path: sigs.k8s.io/cluster-api-operator/api/v1alpha1
1235
version: v1alpha1
13-
- group: operator
36+
- api:
37+
crdVersion: v1
38+
namespaced: true
39+
domain: cluster.x-k8s.io
40+
group: operator
1441
kind: InfrastructureProvider
42+
path: sigs.k8s.io/cluster-api-operator/api/v1alpha1
1543
version: v1alpha1
16-
version: "2"
44+
version: "3"

main.go renamed to cmd/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545
// +kubebuilder:scaffold:imports
4646

4747
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1"
48-
"sigs.k8s.io/cluster-api-operator/internal/controllers"
48+
providercontroller "sigs.k8s.io/cluster-api-operator/internal/controller"
4949
)
5050

5151
var (
@@ -185,7 +185,7 @@ func setupChecks(mgr ctrl.Manager) {
185185
}
186186

187187
func setupReconcilers(mgr ctrl.Manager) {
188-
if err := (&controllers.GenericProviderReconciler{
188+
if err := (&providercontroller.GenericProviderReconciler{
189189
Provider: &operatorv1.CoreProvider{},
190190
ProviderList: &operatorv1.CoreProviderList{},
191191
Client: mgr.GetClient(),
@@ -195,7 +195,7 @@ func setupReconcilers(mgr ctrl.Manager) {
195195
os.Exit(1)
196196
}
197197

198-
if err := (&controllers.GenericProviderReconciler{
198+
if err := (&providercontroller.GenericProviderReconciler{
199199
Provider: &operatorv1.InfrastructureProvider{},
200200
ProviderList: &operatorv1.InfrastructureProviderList{},
201201
Client: mgr.GetClient(),
@@ -205,7 +205,7 @@ func setupReconcilers(mgr ctrl.Manager) {
205205
os.Exit(1)
206206
}
207207

208-
if err := (&controllers.GenericProviderReconciler{
208+
if err := (&providercontroller.GenericProviderReconciler{
209209
Provider: &operatorv1.BootstrapProvider{},
210210
ProviderList: &operatorv1.BootstrapProviderList{},
211211
Client: mgr.GetClient(),
@@ -215,7 +215,7 @@ func setupReconcilers(mgr ctrl.Manager) {
215215
os.Exit(1)
216216
}
217217

218-
if err := (&controllers.GenericProviderReconciler{
218+
if err := (&providercontroller.GenericProviderReconciler{
219219
Provider: &operatorv1.ControlPlaneProvider{},
220220
ProviderList: &operatorv1.ControlPlaneProviderList{},
221221
Client: mgr.GetClient(),

config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.9.2
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.12.0
87
name: bootstrapproviders.operator.cluster.x-k8s.io
98
spec:
109
group: operator.cluster.x-k8s.io

config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.9.2
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.12.0
87
name: controlplaneproviders.operator.cluster.x-k8s.io
98
spec:
109
group: operator.cluster.x-k8s.io

config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.9.2
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.12.0
87
name: coreproviders.operator.cluster.x-k8s.io
98
spec:
109
group: operator.cluster.x-k8s.io

config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.9.2
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.12.0
87
name: infrastructureproviders.operator.cluster.x-k8s.io
98
spec:
109
group: operator.cluster.x-k8s.io

config/webhook/manifests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: admissionregistration.k8s.io/v1
33
kind: ValidatingWebhookConfiguration
44
metadata:
5-
creationTimestamp: null
65
name: validating-webhook-configuration
76
webhooks:
87
- admissionReviewVersions:

controllers/alias.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package controllers
1818

1919
import (
2020
"k8s.io/client-go/rest"
21-
internalcontrollers "sigs.k8s.io/cluster-api-operator/internal/controllers"
21+
internalcontrollers "sigs.k8s.io/cluster-api-operator/internal/controller"
2222
ctrl "sigs.k8s.io/controller-runtime"
2323
"sigs.k8s.io/controller-runtime/pkg/client"
2424
"sigs.k8s.io/controller-runtime/pkg/controller"

0 commit comments

Comments
 (0)