Skip to content

Commit dfc946c

Browse files
authored
Merge pull request #56 from leaseweb/develop
Refactor all controllers, add CAPI clusterclass support add conditions
2 parents 6bbf018 + 894437d commit dfc946c

File tree

131 files changed

+8432
-5629
lines changed

Some content is hidden

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

131 files changed

+8432
-5629
lines changed

.github/workflows/go-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- uses: actions/setup-go@v5
1616
with:
17-
go-version: '1.22'
17+
go-version: '1.23'
1818
- name: Run go test with coverage
1919
run: COVER_PROFILE=coverage.txt make test
2020
- name: Codecov upload

.github/workflows/pr-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Install Go 1.x
1515
uses: actions/setup-go@v5
1616
with:
17-
go-version: '1.22'
17+
go-version: '1.23'
1818

1919
- name: Run unit tests
2020
run: make lint
@@ -31,7 +31,7 @@ jobs:
3131
- name: Install Go 1.x
3232
uses: actions/setup-go@v5
3333
with:
34-
go-version: '1.22'
34+
go-version: '1.23'
3535

3636
- name: Cache
3737
uses: actions/cache@v4

.golangci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ linters:
160160

161161
run:
162162
timeout: 10m
163-
go: "1.22"
163+
go: "1.23"
164164
build-tags:
165165
- tools
166166
- e2e
@@ -200,5 +200,9 @@ issues:
200200
- stylecheck
201201
text: "ST1003: should not use underscores in Go names;"
202202
path: api\/.*\/.*conversion.*\.go$
203+
# Ignore non-constant format string in call to condition utils
204+
- linters:
205+
- govet
206+
text: "non-constant format string in call to sigs\\.k8s\\.io\\/cluster-api\\/util\\/conditions\\."
203207
exclude-files:
204208
- "zz_generated.*\\.go$"

Makefile

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ GOTESTSUM_BIN := gotestsum
6363
GOTESTSUM := $(abspath $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER))
6464
GOTESTSUM_PKG := gotest.tools/gotestsum
6565

66-
CONVERSION_GEN_VER := v0.30.0
66+
CONVERSION_GEN_VER := v0.30.10
6767
CONVERSION_GEN_BIN := conversion-gen
6868
# We are intentionally using the binary without version suffix, to avoid the version
6969
# in generated files.
@@ -91,9 +91,9 @@ GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT
9191
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
9292

9393
MOCKGEN_BIN := mockgen
94-
MOCKGEN_VER := v1.6.0
94+
MOCKGEN_VER := v0.5.0
9595
MOCKGEN := $(abspath $(TOOLS_BIN_DIR)/$(MOCKGEN_BIN)-$(MOCKGEN_VER))
96-
MOCKGEN_PKG := github.com/golang/mock/mockgen
96+
MOCKGEN_PKG := go.uber.org/mock/mockgen
9797

9898
KUBECTL := $(TOOLS_BIN_DIR)/kubectl
9999

@@ -177,8 +177,8 @@ lint: $(GOLANGCI_LINT) generate-mocks ## Run linting for the project.
177177

178178
.PHONY: modules
179179
modules: ## Runs go mod to ensure proper vendoring.
180-
go mod tidy -compat=1.22
181-
cd $(TOOLS_DIR); go mod tidy -compat=1.22
180+
go mod tidy -compat=1.23
181+
cd $(TOOLS_DIR); go mod tidy -compat=1.23
182182

183183
.PHONY: generate-all
184184
generate-all: generate-mocks generate-conversion generate-deepcopy generate-manifests
@@ -193,17 +193,17 @@ DEEPCOPY_GEN_INPUTS=$(shell find ./api -name "*test*" -prune -o -name "*zz_gener
193193
.PHONY: generate-deepcopy
194194
generate-deepcopy: $(DEEPCOPY_GEN_TARGETS) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
195195
api/%/zz_generated.deepcopy.go: $(CONTROLLER_GEN) $(DEEPCOPY_GEN_INPUTS)
196-
CGO_ENABLED=0 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
196+
CGO_ENABLED=0 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
197197

198-
MANIFEST_GEN_INPUTS=$(shell find ./api ./controllers -type f -name "*test*" -prune -o -name "*zz_generated*" -prune -o -print)
198+
MANIFEST_GEN_INPUTS=$(shell find ./api ./internal/controllers -type f -name "*test*" -prune -o -name "*zz_generated*" -prune -o -print)
199199
# Using a flag file here as config output is too complicated to be a target.
200200
# The following triggers manifest building if $(IMG) differs from that found in config/default/manager_image_patch.yaml.
201201
$(shell grep -qs "$(IMG)" config/default/manager_image_patch_edited.yaml || rm -f config/.flag.mk)
202202
.PHONY: generate-manifests
203203
generate-manifests: config/.flag.mk ## Generates crd, webhook, rbac, and other configuration manifests from kubebuilder instructions in go comments.
204204
config/.flag.mk: $(CONTROLLER_GEN) $(MANIFEST_GEN_INPUTS)
205205
sed -e 's@image: .*@image: '"$(IMG)"'@' config/default/manager_image_patch.yaml > config/default/manager_image_patch_edited.yaml
206-
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="{./,./api/...,./controllers/...}" output:crd:artifacts:config=config/crd/bases
206+
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="{./,./api/...,./internal/controllers/...}" output:crd:artifacts:config=config/crd/bases
207207
@touch config/.flag.mk
208208

209209
.PHONY: generate-conversion
@@ -222,7 +222,7 @@ generate-conversion: $(CONVERSION_GEN) ## Generate code to convert api/v1beta1 a
222222
## Build
223223
## --------------------------------------
224224

225-
MANAGER_BIN_INPUTS=$(shell find ./controllers ./api ./pkg -name "*mock*" -prune -o -name "*test*" -prune -o -type f -print) main.go go.mod go.sum
225+
MANAGER_BIN_INPUTS=$(shell find ./internal/controllers ./api ./pkg -name "*mock*" -prune -o -name "*test*" -prune -o -type f -print) main.go go.mod go.sum
226226
.PHONY: build
227227
build: binaries generate-deepcopy generate-manifests release-manifests ## Build manager binary.
228228
$(BIN_DIR)/manager: $(MANAGER_BIN_INPUTS)
@@ -261,7 +261,7 @@ undeploy: $(KUSTOMIZE) ## Undeploy controller from the K8s cluster specified in
261261
# Using a flag file here as docker build doesn't produce a target file.
262262
DOCKER_BUILD_INPUTS=$(MANAGER_BIN_INPUTS) Dockerfile
263263
.PHONY: docker-build
264-
docker-build: generate-deepcopy generate-conversion build-for-docker .dockerflag.mk ## Build docker image containing the controller manager.
264+
docker-build: generate-deepcopy generate-conversion generate-mocks build-for-docker .dockerflag.mk ## Build docker image containing the controller manager.
265265
.dockerflag.mk: $(DOCKER_BUILD_INPUTS)
266266
docker build -t ${IMG} .
267267
@touch .dockerflag.mk
@@ -304,28 +304,14 @@ cluster-api/tilt-settings.json: hack/tilt-settings.json cluster-api
304304

305305
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
306306

307-
DEEPCOPY_GEN_TARGETS_TEST=$(shell find test/fakes -type d -name "fakes" -exec echo {}\/zz_generated.deepcopy.go \;)
308-
DEEPCOPY_GEN_INPUTS_TEST=$(shell find test/fakes/* -name "*zz_generated*" -prune -o -type f -print)
309-
.PHONY: generate-deepcopy-test
310-
generate-deepcopy-test: $(DEEPCOPY_GEN_TARGETS_TEST) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
311-
test/fakes/zz_generated.deepcopy.go: $(CONTROLLER_GEN) $(DEEPCOPY_GEN_INPUTS_TEST)
312-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
313-
314-
MANIFEST_GEN_INPUTS_TEST=$(shell find test/fakes/* -name "*zz_generated*" -prune -o -type f -print)
315-
.PHONY: generate-manifest-test
316-
generate-manifest-test: config/.flag-test.mk ## Generates crd, webhook, rbac, and other configuration manifests from kubebuilder instructions in go comments.
317-
config/.flag-test.mk: $(CONTROLLER_GEN) $(MANIFEST_GEN_INPUTS_TEST)
318-
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="./test/fakes" output:crd:artifacts:config=test/fakes
319-
@touch config/.flag-test.mk
320-
321307
.PHONY: setup-envtest
322308
setup-envtest: $(SETUP_ENVTEST) ## Set up envtest (download kubebuilder assets)
323309
@echo KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS)
324310

325311
.PHONY: test
326-
test: ## Run tests.
327-
test: generate-deepcopy-test generate-manifest-test generate-mocks setup-envtest $(GINKGO)
328-
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GINKGO) --label-filter="!integ" --cover -coverprofile cover.out --covermode=atomic -v ./api/... ./controllers/... ./pkg/...
312+
test: generate-mocks setup-envtest $(GINKGO)
313+
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GINKGO) --label-filter="!integ" --cover -coverprofile cover.out --covermode=atomic -v ./api/... ./pkg/...
314+
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -v -coverprofile cover.out ./internal/controllers/...
329315

330316
.PHONY: test-pkg
331317
test-pkg: $(GINKGO) ## Run pkg tests.
@@ -371,7 +357,7 @@ clean: ## Cleans up everything.
371357
rm -rf $(TOOLS_BIN_DIR)
372358
rm -rf cluster-api
373359
rm -rf test/e2e/data/infrastructure-cloudstack/*/*yaml
374-
rm -rf config/.flag.mk config/.flag-test.mk .dockerflag.mk
360+
rm -rf config/.flag.mk .dockerflag.mk
375361

376362
##@ Release
377363
## --------------------------------------

PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ resources:
1818
defaulting: true
1919
validation: true
2020
webhookVersion: v1
21+
- api:
22+
crdVersion: v1
23+
namespaced: true
24+
controller: true
25+
domain: cluster.x-k8s.io
26+
group: infrastructure
27+
kind: CloudStackClusterTemplate
28+
path: sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3
29+
version: v1beta3
30+
webhooks:
31+
defaulting: true
32+
validation: true
33+
webhookVersion: v1
2134
- api:
2235
crdVersion: v1
2336
namespaced: true

api/v1beta1/zz_generated.conversion.go

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

api/v1beta2/cloudstackcluster_conversion.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
unsafe "unsafe"
21+
2022
machineryconversion "k8s.io/apimachinery/pkg/conversion"
2123
"k8s.io/utils/ptr"
24+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2225
"sigs.k8s.io/controller-runtime/pkg/conversion"
2326

2427
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
@@ -57,3 +60,10 @@ func Convert_v1beta2_CloudStackClusterSpec_To_v1beta3_CloudStackClusterSpec(in *
5760

5861
return nil
5962
}
63+
64+
func Convert_v1beta3_CloudStackClusterStatus_To_v1beta2_CloudStackClusterStatus(in *v1beta3.CloudStackClusterStatus, out *CloudStackClusterStatus, _ machineryconversion.Scope) error {
65+
out.FailureDomains = *(*clusterv1.FailureDomains)(unsafe.Pointer(&in.FailureDomains))
66+
out.Ready = in.Ready
67+
68+
return nil
69+
}

api/v1beta2/cloudstackmachine_conversion.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
unsafe "unsafe"
21+
22+
corev1 "k8s.io/api/core/v1"
2023
machineryconversion "k8s.io/apimachinery/pkg/conversion"
2124
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2225
"sigs.k8s.io/controller-runtime/pkg/conversion"
@@ -64,9 +67,40 @@ func (r *CloudStackMachine) ConvertFrom(srcRaw conversion.Hub) error {
6467
}
6568

6669
func Convert_v1beta3_CloudStackMachineSpec_To_v1beta2_CloudStackMachineSpec(in *v1beta3.CloudStackMachineSpec, out *CloudStackMachineSpec, s machineryconversion.Scope) error {
70+
if in.DiskOffering != nil {
71+
out.DiskOffering = CloudStackResourceDiskOffering{
72+
CustomSize: in.DiskOffering.CustomSize,
73+
MountPath: in.DiskOffering.MountPath,
74+
Device: in.DiskOffering.Device,
75+
Filesystem: in.DiskOffering.Filesystem,
76+
Label: in.DiskOffering.Label,
77+
}
78+
}
79+
6780
return autoConvert_v1beta3_CloudStackMachineSpec_To_v1beta2_CloudStackMachineSpec(in, out, s)
6881
}
6982

7083
func Convert_v1beta2_CloudStackMachineSpec_To_v1beta3_CloudStackMachineSpec(in *CloudStackMachineSpec, out *v1beta3.CloudStackMachineSpec, s machineryconversion.Scope) error {
84+
if in.DiskOffering != (CloudStackResourceDiskOffering{}) {
85+
out.DiskOffering = &v1beta3.CloudStackResourceDiskOffering{
86+
CustomSize: in.DiskOffering.CustomSize,
87+
MountPath: in.DiskOffering.MountPath,
88+
Device: in.DiskOffering.Device,
89+
Filesystem: in.DiskOffering.Filesystem,
90+
Label: in.DiskOffering.Label,
91+
}
92+
}
93+
7194
return autoConvert_v1beta2_CloudStackMachineSpec_To_v1beta3_CloudStackMachineSpec(in, out, s)
7295
}
96+
97+
func Convert_v1beta3_CloudStackMachineStatus_To_v1beta2_CloudStackMachineStatus(in *v1beta3.CloudStackMachineStatus, out *CloudStackMachineStatus, _ machineryconversion.Scope) error {
98+
out.Ready = in.Ready
99+
out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses))
100+
out.InstanceState = in.InstanceState
101+
out.InstanceStateLastUpdated = in.InstanceStateLastUpdated
102+
out.Status = (*string)(unsafe.Pointer(in.Status))
103+
out.Reason = (*string)(unsafe.Pointer(in.Reason))
104+
105+
return nil
106+
}

api/v1beta2/zz_generated.conversion.go

Lines changed: 15 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta3/cloudstackcluster_types.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ var K8sClient client.Client
3030

3131
// CloudStackClusterSpec defines the desired state of CloudStackCluster.
3232
type CloudStackClusterSpec struct {
33+
// FailureDomains is a list of failure domains for the cluster.
34+
//+listType=map
35+
//+listMapKey=name
36+
//+listMapKeyType=string
3337
FailureDomains []CloudStackFailureDomainSpec `json:"failureDomains"`
3438

3539
// The kubernetes control plane endpoint.
@@ -51,11 +55,28 @@ type CloudStackClusterStatus struct {
5155
// Reflects the readiness of the CS cluster.
5256
//+optional
5357
Ready bool `json:"ready"`
58+
59+
// Conditions defines current service state of the CloudStackCluster.
60+
//+optional
61+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
5462
}
5563

56-
//+kubebuilder:object:root=true
64+
// GetConditions returns the conditions for the CloudStackCluster.
65+
func (r *CloudStackCluster) GetConditions() clusterv1.Conditions {
66+
return r.Status.Conditions
67+
}
68+
69+
// SetConditions sets the conditions for the CloudStackCluster.
70+
func (r *CloudStackCluster) SetConditions(conditions clusterv1.Conditions) {
71+
r.Status.Conditions = conditions
72+
}
73+
74+
//+kubebuilder:resource:path=cloudstackclusters,scope=Namespaced,categories=cluster-api,shortName=cscluster
5775
//+kubebuilder:subresource:status
5876
//+kubebuilder:storageversion
77+
//+kubebuilder:object:root=true
78+
//+kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels['cluster\\.x-k8s\\.io/cluster-name']",description="Cluster"
79+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of CloudStackCluster"
5980

6081
// CloudStackCluster is the Schema for the cloudstackclusters API.
6182
type CloudStackCluster struct {

0 commit comments

Comments
 (0)