Skip to content

Commit faa724a

Browse files
committed
Update to CAPI 1.5
Signed-off-by: Hans Rakers <[email protected]>
1 parent 7fd4146 commit faa724a

40 files changed

+758
-1032
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ managers:
8888

8989
.PHONY: manager-cloudstack-infrastructure
9090
manager-cloudstack-infrastructure: ## Build manager binary.
91-
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -ldflags "${LDFLAGS} -extldflags '-static'" -o $(BIN_DIR)/manager .
91+
CGO_ENABLED=0 go build -ldflags "${LDFLAGS} -extldflags '-static'" -o $(BIN_DIR)/manager .
9292

93-
export K8S_VERSION=1.26.1
93+
export K8S_VERSION=1.27.1
9494
$(KUBECTL) $(API_SERVER) $(ETCD) &:
9595
cd $(TOOLS_DIR) && curl --silent -L "https://go.kubebuilder.io/test-tools/${K8S_VERSION}/$(shell go env GOOS)/$(shell go env GOARCH)" --output - | \
9696
tar -C ./ --strip-components=1 -zvxf -
@@ -128,8 +128,8 @@ lint: $(GOLANGCI_LINT) $(STATIC_CHECK) generate-mocks ## Run linting for the pro
128128

129129
.PHONY: modules
130130
modules: ## Runs go mod to ensure proper vendoring.
131-
go mod tidy -compat=1.19
132-
cd $(TOOLS_DIR); go mod tidy -compat=1.19
131+
go mod tidy -compat=1.20
132+
cd $(TOOLS_DIR); go mod tidy -compat=1.20
133133

134134
.PHONY: generate-all
135135
generate-all: generate-mocks generate-deepcopy generate-manifests
@@ -240,7 +240,7 @@ delete-kind-cluster:
240240
kind delete cluster --name $(KIND_CLUSTER_NAME)
241241

242242
cluster-api: ## Clone cluster-api repository for tilt use.
243-
git clone --branch v1.4.8 --depth 1 https://github.com/kubernetes-sigs/cluster-api.git
243+
git clone --branch v1.5.5 --depth 1 https://github.com/kubernetes-sigs/cluster-api.git
244244

245245
cluster-api/tilt-settings.json: hack/tilt-settings.json cluster-api
246246
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.0
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.0
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.0
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.0
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.0
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.0
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.0
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.0
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/cloudstackaffinitygroup_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
2626
csCtrlrUtils "sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
2727
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/cloud"
28+
"sigs.k8s.io/cluster-api/util/predicates"
2829
)
2930

3031
//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackaffinitygroups,verbs=get;list;watch;create;update;patch;delete
@@ -89,8 +90,9 @@ func (r *CloudStackAGReconciliationRunner) ReconcileDelete() (ctrl.Result, error
8990
}
9091

9192
// SetupWithManager sets up the controller with the Manager.
92-
func (reconciler *CloudStackAffinityGroupReconciler) SetupWithManager(mgr ctrl.Manager) error {
93+
func (reconciler *CloudStackAffinityGroupReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
9394
return ctrl.NewControllerManagedBy(mgr).
9495
For(&infrav1.CloudStackAffinityGroup{}).
96+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), reconciler.WatchFilterValue)).
9597
Complete(reconciler)
9698
}

controllers/cloudstackaffinitygroup_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var _ = Describe("CloudStackAffinityGroupReconciler", func() {
2929
BeforeEach(func() {
3030
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
3131
dummies.SetDummyVars()
32-
Ω(AffinityGReconciler.SetupWithManager(k8sManager)).Should(Succeed()) // Register CloudStack AffinityGReconciler.
32+
Ω(AffinityGReconciler.SetupWithManager(ctx, k8sManager)).Should(Succeed()) // Register CloudStack AffinityGReconciler.
3333
})
3434

3535
It("Should patch back the affinity group as ready after calling GetOrCreateAffinityGroup.", func() {

0 commit comments

Comments
 (0)