Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit dd2e83e

Browse files
committed
Migrate to kubebuilder v4 layout
1 parent 10e2c0d commit dd2e83e

30 files changed

+377
-670
lines changed

.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/

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*.dll
66
*.so
77
*.dylib
8-
bin
9-
testbin/*
8+
bin/*
109
Dockerfile.cross
1110

1211
# Test binary, build with `go test -c`
@@ -21,6 +20,7 @@ Dockerfile.cross
2120

2221
# editor and IDE paraphernalia
2322
.idea
23+
.vscode
2424
*.swp
2525
*.swo
2626
*~

Dockerfile

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

@@ -12,16 +12,17 @@ COPY go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY main.go main.go
15+
COPY cmd/main.go cmd/main.go
1616
COPY api/ api/
17-
COPY controllers/ controllers/
17+
COPY internal/controller/ internal/controller/
18+
COPY pkg/ pkg/
1819

1920
# Build
2021
# the GOARCH has not a default value to allow the binary be built according to the host where the command
2122
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2223
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2324
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
2526

2627
# Use distroless as minimal base image to package the manager binary
2728
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Image URL to use all building/pushing image targets
33
IMG ?= controller:latest
44
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5-
ENVTEST_K8S_VERSION = 1.26.0
5+
ENVTEST_K8S_VERSION = 1.27.1
66

77
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
88
ifeq (,$(shell go env GOBIN))
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -44,7 +50,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4450

4551
.PHONY: generate
4652
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
47-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
53+
$(CONTROLLER_GEN) object paths="./..."
4854

4955
.PHONY: fmt
5056
fmt: ## Run go fmt against code.
@@ -62,22 +68,22 @@ test: manifests generate fmt vet envtest ## Run tests.
6268

6369
.PHONY: build
6470
build: manifests generate fmt vet ## Build manager binary.
65-
go build -o bin/manager main.go
71+
go build -o bin/manager cmd/main.go
6672

6773
.PHONY: run
6874
run: manifests generate fmt vet ## Run a controller from your host.
69-
go run ./main.go
75+
go run ./cmd/main.go
7076

7177
# If you wish built the manager image targeting other platforms you can use the --platform flag.
7278
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
7379
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7480
.PHONY: docker-build
7581
docker-build: test ## Build docker image with the manager.
76-
docker build -t ${IMG} .
82+
$(CONTAINER_TOOL) build -t ${IMG} .
7783

7884
.PHONY: docker-push
7985
docker-push: ## Push docker image with the manager.
80-
docker push ${IMG}
86+
$(CONTAINER_TOOL) push ${IMG}
8187

8288
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
8389
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -90,10 +96,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
9096
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
9197
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
9298
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93-
- docker buildx create --name project-v3-builder
94-
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
96-
- docker buildx rm project-v3-builder
99+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
100+
$(CONTAINER_TOOL) buildx use project-v3-builder
101+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
102+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
97103
rm Dockerfile.cross
98104

99105
##@ Deployment
@@ -104,20 +110,20 @@ endif
104110

105111
.PHONY: install
106112
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
107-
$(KUSTOMIZE) build config/crd | kubectl apply -f -
113+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
108114

109115
.PHONY: uninstall
110116
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
111-
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
117+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
112118

113119
.PHONY: deploy
114120
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
115121
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
116-
$(KUSTOMIZE) build config/default | kubectl apply -f -
122+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
117123

118124
.PHONY: undeploy
119125
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
120-
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
126+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
121127

122128
##@ Build Dependencies
123129

@@ -127,23 +133,23 @@ $(LOCALBIN):
127133
mkdir -p $(LOCALBIN)
128134

129135
## Tool Binaries
136+
KUBECTL ?= kubectl
130137
KUSTOMIZE ?= $(LOCALBIN)/kustomize
131138
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
132139
ENVTEST ?= $(LOCALBIN)/setup-envtest
133140

134141
## Tool Versions
135-
KUSTOMIZE_VERSION ?= v3.8.7
136-
CONTROLLER_TOOLS_VERSION ?= v0.11.1
142+
KUSTOMIZE_VERSION ?= v5.0.1
143+
CONTROLLER_TOOLS_VERSION ?= v0.12.0
137144

138-
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
139145
.PHONY: kustomize
140146
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
141147
$(KUSTOMIZE): $(LOCALBIN)
142148
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
143149
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
144150
rm -rf $(LOCALBIN)/kustomize; \
145151
fi
146-
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
152+
test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
147153

148154
.PHONY: controller-gen
149155
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.

PROJECT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# More info: https://book.kubebuilder.io/reference/project-config.html
55
domain: cluster.x-k8s.io
66
layout:
7-
- go.kubebuilder.io/v3
7+
- go.kubebuilder.io/v4
88
projectName: cluster-api-provider-scaleway
99
repo: github.com/Tomy2e/cluster-api-provider-scaleway
1010
resources:

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,3 @@ make manifests
8181
**NOTE:** Run `make --help` for more information on all potential `make` targets
8282

8383
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
84-
85-

api/v1beta1/scalewayclustertemplate_types.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
55
)
66

7+
// ScalewayClusterTemplateSpec defines the desired state of ScalewayClusterTemplate
78
type ScalewayClusterTemplateSpec struct {
89
Template ScalewayClusterTemplateResource `json:"template"`
910
}
1011

12+
type ScalewayClusterTemplateResource struct {
13+
// Standard object's metadata.
14+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
15+
// +optional
16+
ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`
17+
Spec ScalewayClusterSpec `json:"spec"`
18+
}
19+
1120
//+kubebuilder:object:root=true
1221
//+kubebuilder:resource:path=scalewayclustertemplates,scope=Namespaced,categories=cluster-api,shortName=sct
1322
//+kubebuilder:storageversion
@@ -20,14 +29,6 @@ type ScalewayClusterTemplate struct {
2029
Spec ScalewayClusterTemplateSpec `json:"spec,omitempty"`
2130
}
2231

23-
type ScalewayClusterTemplateResource struct {
24-
// Standard object's metadata.
25-
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
26-
// +optional
27-
ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`
28-
Spec ScalewayClusterSpec `json:"spec"`
29-
}
30-
3132
//+kubebuilder:object:root=true
3233

3334
// ScalewayClusterTemplateList contains a list of ScalewayClusterTemplate

api/v1beta1/scalewaymachinetemplate_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ type ScalewayMachineTemplateSpec struct {
99
Template ScalewayMachineTemplateResource `json:"template"`
1010
}
1111

12+
type ScalewayMachineTemplateResource struct {
13+
// Standard object's metadata.
14+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
15+
// +optional
16+
ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`
17+
Spec ScalewayMachineSpec `json:"spec"`
18+
}
19+
1220
//+kubebuilder:object:root=true
1321
//+kubebuilder:resource:path=scalewaymachinetemplates,scope=Namespaced,categories=cluster-api,shortName=smt
1422
//+kubebuilder:storageversion
@@ -21,14 +29,6 @@ type ScalewayMachineTemplate struct {
2129
Spec ScalewayMachineTemplateSpec `json:"spec,omitempty"`
2230
}
2331

24-
type ScalewayMachineTemplateResource struct {
25-
// Standard object's metadata.
26-
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
27-
// +optional
28-
ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`
29-
Spec ScalewayMachineSpec `json:"spec"`
30-
}
31-
3232
//+kubebuilder:object:root=true
3333

3434
// ScalewayMachineTemplateList contains a list of ScalewayMachineTemplate

main.go renamed to cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1818

1919
infrastructurev1beta1 "github.com/Tomy2e/cluster-api-provider-scaleway/api/v1beta1"
20-
"github.com/Tomy2e/cluster-api-provider-scaleway/controllers"
20+
"github.com/Tomy2e/cluster-api-provider-scaleway/internal/controller"
2121
//+kubebuilder:scaffold:imports
2222
)
2323

@@ -74,14 +74,14 @@ func main() {
7474
os.Exit(1)
7575
}
7676

77-
if err = (&controllers.ScalewayClusterReconciler{
77+
if err = (&controller.ScalewayClusterReconciler{
7878
Client: mgr.GetClient(),
7979
Scheme: mgr.GetScheme(),
8080
}).SetupWithManager(mgr); err != nil {
8181
setupLog.Error(err, "unable to create controller", "controller", "ScalewayCluster")
8282
os.Exit(1)
8383
}
84-
if err = (&controllers.ScalewayMachineReconciler{
84+
if err = (&controller.ScalewayMachineReconciler{
8585
Client: mgr.GetClient(),
8686
Scheme: mgr.GetScheme(),
8787
}).SetupWithManager(mgr); err != nil {

config/crd/bases/infrastructure.cluster.x-k8s.io_scalewayclusters.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.11.1
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.12.0
87
name: scalewayclusters.infrastructure.cluster.x-k8s.io
98
spec:
109
group: infrastructure.cluster.x-k8s.io

0 commit comments

Comments
 (0)