Skip to content

Commit 3d1922c

Browse files
committed
Upgrade CAPI to 1.5
1 parent d892f42 commit 3d1922c

25 files changed

+298
-356
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ managers:
9191
manager-cloudstack-infrastructure: ## Build manager binary.
9292
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -ldflags "${LDFLAGS} -extldflags '-static'" -o $(BIN_DIR)/manager .
9393

94-
export K8S_VERSION=1.26.1
94+
export K8S_VERSION=1.28.15
9595
$(KUBECTL) $(API_SERVER) $(ETCD) &:
9696
cd $(TOOLS_DIR) && curl --silent -L "https://go.kubebuilder.io/test-tools/${K8S_VERSION}/$(shell go env GOOS)/$(shell go env GOARCH)" --output - | \
9797
tar -C ./ --strip-components=1 -zvxf -
@@ -244,7 +244,7 @@ delete-kind-cluster:
244244
kind delete cluster --name $(KIND_CLUSTER_NAME)
245245

246246
cluster-api: ## Clone cluster-api repository for tilt use.
247-
git clone --branch v1.4.8 --depth 1 https://github.com/kubernetes-sigs/cluster-api.git
247+
git clone --branch v1.5.8 --depth 1 https://github.com/kubernetes-sigs/cluster-api.git
248248

249249
cluster-api/tilt-settings.json: hack/tilt-settings.json cluster-api
250250
cp ./hack/tilt-settings.json cluster-api

api/v1beta3/cloudstackcluster_webhook.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
ctrl "sigs.k8s.io/controller-runtime"
2828
logf "sigs.k8s.io/controller-runtime/pkg/log"
2929
"sigs.k8s.io/controller-runtime/pkg/webhook"
30+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3031
)
3132

3233
// log is for logging in this package.
@@ -53,7 +54,7 @@ func (r *CloudStackCluster) Default() {
5354
var _ webhook.Validator = &CloudStackCluster{}
5455

5556
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
56-
func (r *CloudStackCluster) ValidateCreate() error {
57+
func (r *CloudStackCluster) ValidateCreate() (admission.Warnings, error) {
5758
cloudstackclusterlog.V(1).Info("entered validate create webhook", "api resource name", r.Name)
5859

5960
var errorList field.ErrorList
@@ -80,18 +81,18 @@ func (r *CloudStackCluster) ValidateCreate() error {
8081
}
8182
}
8283

83-
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
84+
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
8485
}
8586

8687
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
87-
func (r *CloudStackCluster) ValidateUpdate(old runtime.Object) error {
88+
func (r *CloudStackCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
8889
cloudstackclusterlog.V(1).Info("entered validate update webhook", "api resource name", r.Name)
8990

9091
spec := r.Spec
9192

9293
oldCluster, ok := old.(*CloudStackCluster)
9394
if !ok {
94-
return errors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", old))
95+
return nil, errors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", old))
9596
}
9697
oldSpec := oldCluster.Spec
9798

@@ -109,7 +110,7 @@ func (r *CloudStackCluster) ValidateUpdate(old runtime.Object) error {
109110
"controlplaneendpoint.port", errorList)
110111
}
111112

112-
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
113+
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
113114
}
114115

115116
// ValidateFailureDomainUpdates verifies that at least one failure domain has not been deleted, and
@@ -150,8 +151,8 @@ func FailureDomainsEqual(fd1, fd2 CloudStackFailureDomainSpec) bool {
150151
}
151152

152153
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
153-
func (r *CloudStackCluster) ValidateDelete() error {
154+
func (r *CloudStackCluster) ValidateDelete() (admission.Warnings, error) {
154155
cloudstackclusterlog.V(1).Info("entered validate delete webhook", "api resource name", r.Name)
155156
// No deletion validations. Deletion webhook not enabled.
156-
return nil
157+
return nil, nil
157158
}

api/v1beta3/cloudstackmachine_webhook.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
ctrl "sigs.k8s.io/controller-runtime"
2828
logf "sigs.k8s.io/controller-runtime/pkg/log"
2929
"sigs.k8s.io/controller-runtime/pkg/webhook"
30+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3031
)
3132

3233
// log is for logging in this package.
@@ -53,7 +54,7 @@ func (r *CloudStackMachine) Default() {
5354
var _ webhook.Validator = &CloudStackMachine{}
5455

5556
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
56-
func (r *CloudStackMachine) ValidateCreate() error {
57+
func (r *CloudStackMachine) ValidateCreate() (admission.Warnings, error) {
5758
cloudstackmachinelog.V(1).Info("entered validate create webhook", "api resource name", r.Name)
5859

5960
var errorList field.ErrorList
@@ -64,18 +65,18 @@ func (r *CloudStackMachine) ValidateCreate() error {
6465
errorList = webhookutil.EnsureIntFieldsAreNotNegative(r.Spec.DiskOffering.CustomSize, "customSizeInGB", errorList)
6566
}
6667

67-
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
68+
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
6869
}
6970

7071
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
71-
func (r *CloudStackMachine) ValidateUpdate(old runtime.Object) error {
72+
func (r *CloudStackMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
7273
cloudstackmachinelog.V(1).Info("entered validate update webhook", "api resource name", r.Name)
7374

7475
var errorList field.ErrorList
7576

7677
oldMachine, ok := old.(*CloudStackMachine)
7778
if !ok {
78-
return errors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachine but got a %T", old))
79+
return nil, errors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachine but got a %T", old))
7980
}
8081
oldSpec := oldMachine.Spec
8182

@@ -98,12 +99,12 @@ func (r *CloudStackMachine) ValidateUpdate(old runtime.Object) error {
9899
errorList = append(errorList, field.Forbidden(field.NewPath("spec", "AffinityGroupIDs"), "AffinityGroupIDs"))
99100
}
100101

101-
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
102+
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
102103
}
103104

104105
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
105-
func (r *CloudStackMachine) ValidateDelete() error {
106+
func (r *CloudStackMachine) ValidateDelete() (admission.Warnings, error) {
106107
cloudstackmachinelog.V(1).Info("entered validate delete webhook", "api resource name", r.Name)
107108
// No deletion validations. Deletion webhook not enabled.
108-
return nil
109+
return nil, nil
109110
}

api/v1beta3/cloudstackmachinetemplate_webhook.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
ctrl "sigs.k8s.io/controller-runtime"
2929
logf "sigs.k8s.io/controller-runtime/pkg/log"
3030
"sigs.k8s.io/controller-runtime/pkg/webhook"
31+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3132
)
3233

3334
// log is for logging in this package.
@@ -54,7 +55,7 @@ func (r *CloudStackMachineTemplate) Default() {
5455
var _ webhook.Validator = &CloudStackMachineTemplate{}
5556

5657
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
57-
func (r *CloudStackMachineTemplate) ValidateCreate() error {
58+
func (r *CloudStackMachineTemplate) ValidateCreate() (admission.Warnings, error) {
5859
cloudstackmachinetemplatelog.V(1).Info("entered validate create webhook", "api resource name", r.Name)
5960

6061
var errorList field.ErrorList
@@ -75,16 +76,16 @@ func (r *CloudStackMachineTemplate) ValidateCreate() error {
7576
errorList = webhookutil.EnsureAtLeastOneFieldExists(spec.Offering.ID, spec.Offering.Name, "Offering", errorList)
7677
errorList = webhookutil.EnsureAtLeastOneFieldExists(spec.Template.ID, spec.Template.Name, "Template", errorList)
7778

78-
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
79+
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
7980
}
8081

8182
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
82-
func (r *CloudStackMachineTemplate) ValidateUpdate(old runtime.Object) error {
83+
func (r *CloudStackMachineTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
8384
cloudstackmachinetemplatelog.V(1).Info("entered validate update webhook", "api resource name", r.Name)
8485

8586
oldMachineTemplate, ok := old.(*CloudStackMachineTemplate)
8687
if !ok {
87-
return errors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachineTemplate but got a %T", old))
88+
return nil, errors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachineTemplate but got a %T", old))
8889
}
8990

9091
// CloudStackMachineTemplateSpec.CloudStackMachineTemplateResource.CloudStackMachineSpec
@@ -106,12 +107,12 @@ func (r *CloudStackMachineTemplate) ValidateUpdate(old runtime.Object) error {
106107
errorList = append(errorList, field.Forbidden(field.NewPath("spec", "AffinityGroupIDs"), "AffinityGroupIDs"))
107108
}
108109

109-
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
110+
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
110111
}
111112

112113
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
113-
func (r *CloudStackMachineTemplate) ValidateDelete() error {
114+
func (r *CloudStackMachineTemplate) ValidateDelete() (admission.Warnings, error) {
114115
cloudstackmachinetemplatelog.V(1).Info("entered validate delete webhook", "api resource name", r.Name)
115116
// No deletion validations. Deletion webhook not enabled.
116-
return nil
117+
return nil, nil
117118
}

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

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

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

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

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

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

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

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

config/rbac/role.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: ClusterRole
44
metadata:
5-
creationTimestamp: null
65
name: manager-role
76
rules:
87
- apiGroups:

config/webhook/manifests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: admissionregistration.k8s.io/v1
33
kind: MutatingWebhookConfiguration
44
metadata:
5-
creationTimestamp: null
65
name: mutating-webhook-configuration
76
webhooks:
87
- admissionReviewVersions:
@@ -72,7 +71,6 @@ webhooks:
7271
apiVersion: admissionregistration.k8s.io/v1
7372
kind: ValidatingWebhookConfiguration
7473
metadata:
75-
creationTimestamp: null
7674
name: validating-webhook-configuration
7775
webhooks:
7876
- admissionReviewVersions:

controllers/cloudstackcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (reconciler *CloudStackClusterReconciler) SetupWithManager(ctx context.Cont
190190

191191
// Add a watch on CAPI Cluster objects for unpause and ready events.
192192
if err = controller.Watch(
193-
&source.Kind{Type: &clusterv1.Cluster{}},
193+
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
194194
handler.EnqueueRequestsFromMapFunc(
195195
util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("CloudStackCluster"), mgr.GetClient(), &infrav1.CloudStackCluster{})),
196196
predicates.ClusterUnpaused(log),

controllers/cloudstackmachine_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func (reconciler *CloudStackMachineReconciler) SetupWithManager(ctx context.Cont
395395
// Queues a reconcile request for owned CloudStackMachine on change.
396396
// Used to update when bootstrap data becomes available.
397397
if err = controller.Watch(
398-
&source.Kind{Type: &clusterv1.Machine{}},
398+
source.Kind(mgr.GetCache(), &clusterv1.Machine{}),
399399
handler.EnqueueRequestsFromMapFunc(
400400
util.MachineToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("CloudStackMachine"))),
401401
predicate.Funcs{
@@ -411,15 +411,15 @@ func (reconciler *CloudStackMachineReconciler) SetupWithManager(ctx context.Cont
411411
}
412412

413413
// Used below, this maps CAPI clusters to CAPC machines
414-
csMachineMapper, err := util.ClusterToObjectsMapper(reconciler.K8sClient, &infrav1.CloudStackMachineList{}, mgr.GetScheme())
414+
csMachineMapper, err := util.ClusterToTypedObjectsMapper(reconciler.K8sClient, &infrav1.CloudStackMachineList{}, mgr.GetScheme())
415415
if err != nil {
416416
return err
417417
}
418418

419419
reconciler.Recorder = mgr.GetEventRecorderFor("capc-machine-controller")
420420
// Add a watch on CAPI Cluster objects for unpause and ready events.
421421
return controller.Watch(
422-
&source.Kind{Type: &clusterv1.Cluster{}},
422+
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
423423
handler.EnqueueRequestsFromMapFunc(csMachineMapper),
424424
predicates.ClusterUnpausedAndInfrastructureReady(log),
425425
)

controllers/controllers_suite_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ func setupFakeTestClient() {
267267
dummies.SetDummyVars()
268268

269269
// Make a fake k8s client with CloudStack and CAPI cluster.
270-
fakeCtrlClient = fake.NewClientBuilder().WithObjects(dummies.CSCluster, dummies.CAPICluster).Build()
270+
fakeCtrlClient = fake.NewClientBuilder().WithScheme(scheme.Scheme).
271+
WithObjects(dummies.CSCluster, dummies.CAPICluster).
272+
WithStatusSubresource(dummies.CSCluster, dummies.CSMachine1).Build()
271273
fakeRecorder = record.NewFakeRecorder(fakeEventBufferSize)
272274
// Setup mock clients.
273275
mockCSAPIClient = cloudstack.NewMockClient(mockCtrl)
@@ -328,7 +330,7 @@ var _ = ginkgo.AfterEach(func() {
328330

329331
var _ = ginkgo.AfterSuite(func() {})
330332

331-
// setClusterReady patches the clsuter with ready status true.
333+
// setClusterReady patches the cluster with ready status true.
332334
func setClusterReady(client client.Client) {
333335
gomega.Eventually(func() error {
334336
ph, err := patch.NewHelper(dummies.CSCluster, client)

0 commit comments

Comments
 (0)