Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to CAPI 1.5 #342

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/go-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.19.3
go-version: '1.20'
- name: Run go test with coverage
run: COVER_PROFILE=coverage.txt make test
- name: Codecov upload
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ managers:

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

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

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

.PHONY: generate-all
generate-all: generate-mocks generate-deepcopy generate-manifests
Expand Down Expand Up @@ -240,7 +240,7 @@ delete-kind-cluster:
kind delete cluster --name $(KIND_CLUSTER_NAME)

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

cluster-api/tilt-settings.json: hack/tilt-settings.json cluster-api
cp ./hack/tilt-settings.json cluster-api
Expand Down
5 changes: 1 addition & 4 deletions api/v1beta1/cloudstackaffinitygroup_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ func (dst *CloudStackAffinityGroup) ConvertFrom(srcRaw conversion.Hub) error { /
}

// Preserve Hub data on down-conversion
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}
return nil
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta3_CloudStackAffinityGroupSpec_To_v1beta1_CloudStackAffinityGroupSpec(in *v1beta3.CloudStackAffinityGroupSpec, out *CloudStackAffinityGroupSpec, s machineryconversion.Scope) error { // nolint
Expand Down
5 changes: 1 addition & 4 deletions api/v1beta1/cloudstackisolatednetwork_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ func (dst *CloudStackIsolatedNetwork) ConvertFrom(srcRaw conversion.Hub) error {
}

// Preserve Hub data on down-conversion
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}
return nil
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in *v1beta3.CloudStackIsolatedNetworkSpec, out *CloudStackIsolatedNetworkSpec, s machineryconversion.Scope) error { // nolint
Expand Down
5 changes: 1 addition & 4 deletions api/v1beta1/cloudstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ func (dst *CloudStackMachine) ConvertFrom(srcRaw conversion.Hub) error { // noli
}

// Preserve Hub data on down-conversion
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}
return nil
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta3_CloudStackMachineSpec_To_v1beta1_CloudStackMachineSpec(in *v1beta3.CloudStackMachineSpec, out *CloudStackMachineSpec, s machineryconversion.Scope) error { // nolint
Expand Down
5 changes: 1 addition & 4 deletions api/v1beta1/cloudstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ func (dst *CloudStackMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
}

// Preserve Hub data on down-conversion
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}
return nil
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta1_CloudStackMachineTemplateSpec_To_v1beta3_CloudStackMachineTemplateSpec(in *CloudStackMachineTemplateSpec, out *v1beta3.CloudStackMachineTemplateSpec, s machineryconversion.Scope) error { // nolint
Expand Down
5 changes: 3 additions & 2 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
conv "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
Expand Down Expand Up @@ -90,7 +91,7 @@ func GetFailureDomains(csCluster *CloudStackCluster) ([]v1beta3.CloudStackFailur
var failureDomains []v1beta3.CloudStackFailureDomainSpec
namespace := csCluster.Namespace
for _, zone := range csCluster.Spec.Zones {
name, err := GetDefaultFailureDomainName(namespace, csCluster.Name, zone.ID, zone.Name)
name, err := GetDefaultFailureDomainName(namespace, zone.ID, zone.Name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -122,7 +123,7 @@ func GetFailureDomains(csCluster *CloudStackCluster) ([]v1beta3.CloudStackFailur
// When upgrading cluster using eks-a, a secret named global will be created by eks-a, and it is used by following
// method to get zoneID by calling cloudstack API.
// When upgrading cluster using clusterctl directly, zoneID is fetched directly from kubernetes cluster in cloudstackzones.
func GetDefaultFailureDomainName(namespace string, clusterName string, zoneID string, zoneName string) (string, error) {
func GetDefaultFailureDomainName(namespace string, zoneID string, zoneName string) (string, error) {
if len(zoneID) > 0 {
return zoneID, nil
}
Expand Down
15 changes: 8 additions & 7 deletions api/v1beta3/cloudstackcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

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

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

var errorList field.ErrorList
Expand All @@ -80,18 +81,18 @@ func (r *CloudStackCluster) ValidateCreate() error {
}
}

return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

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

spec := r.Spec

oldCluster, ok := old.(*CloudStackCluster)
if !ok {
return errors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", old))
return nil, errors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", old))
}
oldSpec := oldCluster.Spec

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

return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

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

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *CloudStackCluster) ValidateDelete() error {
func (r *CloudStackCluster) ValidateDelete() (admission.Warnings, error) {
cloudstackclusterlog.V(1).Info("entered validate delete webhook", "api resource name", r.Name)
// No deletion validations. Deletion webhook not enabled.
return nil
return nil, nil
}
15 changes: 8 additions & 7 deletions api/v1beta3/cloudstackmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

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

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

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

return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

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

var errorList field.ErrorList

oldMachine, ok := old.(*CloudStackMachine)
if !ok {
return errors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachine but got a %T", old))
return nil, errors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachine but got a %T", old))
}
oldSpec := oldMachine.Spec

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

return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *CloudStackMachine) ValidateDelete() error {
func (r *CloudStackMachine) ValidateDelete() (admission.Warnings, error) {
cloudstackmachinelog.V(1).Info("entered validate delete webhook", "api resource name", r.Name)
// No deletion validations. Deletion webhook not enabled.
return nil
return nil, nil
}
15 changes: 8 additions & 7 deletions api/v1beta3/cloudstackmachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

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

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

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

return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

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

oldMachineTemplate, ok := old.(*CloudStackMachineTemplate)
if !ok {
return errors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachineTemplate but got a %T", old))
return nil, errors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachineTemplate but got a %T", old))
}

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

return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
return nil, webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *CloudStackMachineTemplate) ValidateDelete() error {
func (r *CloudStackMachineTemplate) ValidateDelete() (admission.Warnings, error) {
cloudstackmachinetemplatelog.V(1).Info("entered validate delete webhook", "api resource name", r.Name)
// No deletion validations. Deletion webhook not enabled.
return nil
return nil, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cloudstackaffinitygroups.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cloudstackclusters.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cloudstackfailuredomains.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cloudstackisolatednetworks.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cloudstackmachines.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cloudstackmachinestatecheckers.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cloudstackmachinetemplates.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cloudstackzones.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
2 changes: 0 additions & 2 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
creationTimestamp: null
name: mutating-webhook-configuration
webhooks:
- admissionReviewVersions:
Expand Down Expand Up @@ -72,7 +71,6 @@ webhooks:
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
creationTimestamp: null
name: validating-webhook-configuration
webhooks:
- admissionReviewVersions:
Expand Down
Loading
Loading