Skip to content

Commit

Permalink
Merge pull request #1970 from chrischdi/bump-capi-v1-5-beta
Browse files Browse the repository at this point in the history
✨ Bump cluster-api dependency to v1.5.0-beta.1
  • Loading branch information
k8s-ci-robot authored Jul 11, 2023
2 parents e0b05be + 7805709 commit 6d70d7e
Show file tree
Hide file tree
Showing 73 changed files with 544 additions and 1,170 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,21 @@ GOVC_BIN := govc
GOVC := $(abspath $(TOOLS_BIN_DIR)/$(GOVC_BIN)-$(GOVC_VER))
GOVC_PKG := github.com/vmware/govmomi/govc

KUSTOMIZE_VER := v4.5.2
KUSTOMIZE_BIN := kustomize
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v4

CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
GINKGO := $(TOOLS_BIN_DIR)/ginkgo
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
KIND := $(TOOLS_BIN_DIR)/kind
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/setup-envtest)
CONVERSION_VERIFIER := $(abspath $(TOOLS_BIN_DIR)/conversion-verifier)
GO_APIDIFF := $(TOOLS_BIN_DIR)/go-apidiff
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes
TOOLING_BINARIES := $(CONTROLLER_GEN) $(CONVERSION_GEN) $(GINKGO) $(GOLANGCI_LINT) $(KIND) $(KUSTOMIZE) $(CONVERSION_VERIFIER) $(GO_APIDIFF) $(RELEASE_NOTES)
TOOLING_BINARIES := $(CONTROLLER_GEN) $(CONVERSION_GEN) $(GINKGO) $(GOLANGCI_LINT) $(KIND) $(CONVERSION_VERIFIER) $(GO_APIDIFF) $(RELEASE_NOTES)
ARTIFACTS ?= $(ROOT_DIR)/_artifacts

# Set --output-base for conversion-gen if we are not within GOPATH
Expand Down Expand Up @@ -232,6 +236,12 @@ $(GOVC): # Build GOVC from tools folder.
.PHONY: $(GOVC_BIN)
$(GOVC_BIN): $(GOVC) ## Build a local copy of kustomize.

$(KUSTOMIZE): # Build kustomize from tools folder.
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)

.PHONY: $(KUSTOMIZE_BIN)
$(KUSTOMIZE_BIN): $(KUSTOMIZE) ## Build a local copy of kustomize.

## --------------------------------------
## Linting and fixing linter errors
## --------------------------------------
Expand Down
15 changes: 8 additions & 7 deletions apis/v1beta1/vsphereclustertemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (r *VSphereClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -36,20 +37,20 @@ func (r *VSphereClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error
var _ webhook.Validator = &VSphereClusterTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *VSphereClusterTemplate) ValidateCreate() error {
return nil
func (r *VSphereClusterTemplate) ValidateCreate() (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *VSphereClusterTemplate) ValidateUpdate(oldRaw runtime.Object) error {
func (r *VSphereClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
old := oldRaw.(*VSphereClusterTemplate) //nolint:forcetypeassert
if !reflect.DeepEqual(r.Spec.Template.Spec, old.Spec.Template.Spec) {
return field.Forbidden(field.NewPath("spec", "template", "spec"), "VSphereClusterTemplate spec is immutable")
return nil, field.Forbidden(field.NewPath("spec", "template", "spec"), "VSphereClusterTemplate spec is immutable")
}
return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *VSphereClusterTemplate) ValidateDelete() error {
return nil
func (r *VSphereClusterTemplate) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
15 changes: 8 additions & 7 deletions apis/v1beta1/vspherefailuredomain_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (r *VSphereFailureDomain) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -41,7 +42,7 @@ var _ webhook.Validator = &VSphereFailureDomain{}
var _ webhook.Defaulter = &VSphereFailureDomain{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *VSphereFailureDomain) ValidateCreate() error {
func (r *VSphereFailureDomain) ValidateCreate() (admission.Warnings, error) {
var allErrs field.ErrorList

if r.Spec.Topology.ComputeCluster == nil && r.Spec.Topology.Hosts != nil {
Expand All @@ -64,21 +65,21 @@ func (r *VSphereFailureDomain) ValidateCreate() error {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "Topology", "ComputeCluster"), fmt.Sprintf("cannot be nil if zone's Failure Domain type is %s", r.Spec.Zone.Type)))
}

return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *VSphereFailureDomain) ValidateUpdate(old runtime.Object) error {
func (r *VSphereFailureDomain) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
oldVSphereFailureDomain, ok := old.(*VSphereFailureDomain)
if !ok || !reflect.DeepEqual(r.Spec, oldVSphereFailureDomain.Spec) {
return field.Forbidden(field.NewPath("spec"), "VSphereFailureDomainSpec is immutable")
return nil, field.Forbidden(field.NewPath("spec"), "VSphereFailureDomainSpec is immutable")
}
return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *VSphereFailureDomain) ValidateDelete() error {
return nil
func (r *VSphereFailureDomain) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
Expand Down
3 changes: 1 addition & 2 deletions apis/v1beta1/vspherefailuredomain_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"k8s.io/utils/pointer"
)

//nolint
func TestVsphereFailureDomain_Default(t *testing.T) {
g := NewWithT(t)
m := &VSphereFailureDomain{
Expand Down Expand Up @@ -135,7 +134,7 @@ func TestVSphereFailureDomain_ValidateCreate(t *testing.T) {
// Need to reinit the test variable
tt := tt
t.Run(tt.name, func(t *testing.T) {
err := tt.failureDomain.ValidateCreate()
_, err := tt.failureDomain.ValidateCreate()
if tt.errExpected == nil || !*tt.errExpected {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
17 changes: 9 additions & 8 deletions apis/v1beta1/vspheremachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (m *VSphereMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -49,7 +50,7 @@ func (m *VSphereMachine) Default() {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (m *VSphereMachine) ValidateCreate() error {
func (m *VSphereMachine) ValidateCreate() (admission.Warnings, error) {
var allErrs field.ErrorList
spec := m.Spec

Expand All @@ -65,21 +66,21 @@ func (m *VSphereMachine) ValidateCreate() error {
}
}

return aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
return nil, aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
//
//nolint:forcetypeassert
func (m *VSphereMachine) ValidateUpdate(old runtime.Object) error {
func (m *VSphereMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
newVSphereMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(m)
if err != nil {
return apierrors.NewInternalError(errors.Wrap(err, "failed to convert new VSphereMachine to unstructured object"))
return nil, apierrors.NewInternalError(errors.Wrap(err, "failed to convert new VSphereMachine to unstructured object"))
}

oldVSphereMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
if err != nil {
return apierrors.NewInternalError(errors.Wrap(err, "failed to convert old VSphereMachine to unstructured object"))
return nil, apierrors.NewInternalError(errors.Wrap(err, "failed to convert old VSphereMachine to unstructured object"))
}

var allErrs field.ErrorList
Expand Down Expand Up @@ -112,10 +113,10 @@ func (m *VSphereMachine) ValidateUpdate(old runtime.Object) error {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
}

return aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
return nil, aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (m *VSphereMachine) ValidateDelete() error {
return nil
func (m *VSphereMachine) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
9 changes: 4 additions & 5 deletions apis/v1beta1/vspheremachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

var someProviderID = "vsphere://42305f0b-dad7-1d3d-5727-0eaffffffffc"

//nolint
func TestVsphereMachine_Default(t *testing.T) {
g := NewWithT(t)
m := &VSphereMachine{
Expand All @@ -35,7 +34,7 @@ func TestVsphereMachine_Default(t *testing.T) {
g.Expect(m.Spec.Datacenter).To(Equal("*"))
}

//nolint
//nolint:all
func TestVSphereMachine_ValidateCreate(t *testing.T) {

g := NewWithT(t)
Expand Down Expand Up @@ -67,7 +66,7 @@ func TestVSphereMachine_ValidateCreate(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := tc.vsphereMachine.ValidateCreate()
_, err := tc.vsphereMachine.ValidateCreate()
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand All @@ -77,7 +76,7 @@ func TestVSphereMachine_ValidateCreate(t *testing.T) {
}
}

//nolint
//nolint:all
func TestVSphereMachine_ValidateUpdate(t *testing.T) {

g := NewWithT(t)
Expand Down Expand Up @@ -121,7 +120,7 @@ func TestVSphereMachine_ValidateUpdate(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := tc.vsphereMachine.ValidateUpdate(tc.oldVSphereMachine)
_, err := tc.vsphereMachine.ValidateUpdate(tc.oldVSphereMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
20 changes: 10 additions & 10 deletions apis/v1beta1/vspheremachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ type VSphereMachineTemplateWebhook struct{}
var _ webhook.CustomValidator = &VSphereMachineTemplateWebhook{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (v *VSphereMachineTemplateWebhook) ValidateCreate(_ context.Context, raw runtime.Object) error {
func (v *VSphereMachineTemplateWebhook) ValidateCreate(_ context.Context, raw runtime.Object) (admission.Warnings, error) {
obj, ok := raw.(*VSphereMachineTemplate)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereMachineTemplate but got a %T", raw))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereMachineTemplate but got a %T", raw))
}

var allErrs field.ErrorList
Expand All @@ -75,34 +75,34 @@ func (v *VSphereMachineTemplateWebhook) ValidateCreate(_ context.Context, raw ru
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "template", "spec", "hardwareVersion"), spec.HardwareVersion, "should be a valid VM hardware version, example vmx-17"))
}
}
return aggregateObjErrors(obj.GroupVersionKind().GroupKind(), obj.Name, allErrs)
return nil, aggregateObjErrors(obj.GroupVersionKind().GroupKind(), obj.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (v *VSphereMachineTemplateWebhook) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) error {
func (v *VSphereMachineTemplateWebhook) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
newObj, ok := newRaw.(*VSphereMachineTemplate)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereMachineTemplate but got a %T", newRaw))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereMachineTemplate but got a %T", newRaw))
}
oldObj, ok := oldRaw.(*VSphereMachineTemplate)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereMachineTemplate but got a %T", oldRaw))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereMachineTemplate but got a %T", oldRaw))
}

req, err := admission.RequestFromContext(ctx)
if err != nil {
return apierrors.NewBadRequest(fmt.Sprintf("expected a admission.Request inside context: %v", err))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a admission.Request inside context: %v", err))
}

var allErrs field.ErrorList
if !topology.ShouldSkipImmutabilityChecks(req, newObj) &&
!reflect.DeepEqual(newObj.Spec.Template.Spec, oldObj.Spec.Template.Spec) {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "template", "spec"), newObj, machineTemplateImmutableMsg))
}
return aggregateObjErrors(newObj.GroupVersionKind().GroupKind(), newObj.Name, allErrs)
return nil, aggregateObjErrors(newObj.GroupVersionKind().GroupKind(), newObj.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (v *VSphereMachineTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) error {
return nil
func (v *VSphereMachineTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
4 changes: 2 additions & 2 deletions apis/v1beta1/vspheremachinetemplate_webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestVSphereMachineTemplate_ValidateCreate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
webhook := &VSphereMachineTemplateWebhook{}
err := webhook.ValidateCreate(context.Background(), tc.vsphereMachine)
_, err := webhook.ValidateCreate(context.Background(), tc.vsphereMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestVSphereMachineTemplate_ValidateUpdate(t *testing.T) {
if tc.req != nil {
ctx = admission.NewContextWithRequest(ctx, *tc.req)
}
err := webhook.ValidateUpdate(ctx, tc.oldVSphereMachine, tc.vsphereMachine)
_, err := webhook.ValidateUpdate(ctx, tc.oldVSphereMachine, tc.vsphereMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
17 changes: 9 additions & 8 deletions apis/v1beta1/vspherevm_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (r *VSphereVM) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -46,7 +47,7 @@ func (r *VSphereVM) Default() {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *VSphereVM) ValidateCreate() error {
func (r *VSphereVM) ValidateCreate() (admission.Warnings, error) {
var allErrs field.ErrorList
spec := r.Spec

Expand All @@ -65,20 +66,20 @@ func (r *VSphereVM) ValidateCreate() error {
if r.Spec.OS == Windows && len(r.Name) > 15 {
allErrs = append(allErrs, field.Invalid(field.NewPath("name"), r.Name, "name has to be less than 16 characters for Windows VM"))
}
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
//
//nolint:forcetypeassert
func (r *VSphereVM) ValidateUpdate(old runtime.Object) error {
func (r *VSphereVM) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
newVSphereVM, err := runtime.DefaultUnstructuredConverter.ToUnstructured(r)
if err != nil {
return apierrors.NewInternalError(errors.Wrap(err, "failed to convert new VSphereVM to unstructured object"))
return nil, apierrors.NewInternalError(errors.Wrap(err, "failed to convert new VSphereVM to unstructured object"))
}
oldVSphereVM, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
if err != nil {
return apierrors.NewInternalError(errors.Wrap(err, "failed to convert old VSphereVM to unstructured object"))
return nil, apierrors.NewInternalError(errors.Wrap(err, "failed to convert old VSphereVM to unstructured object"))
}

var allErrs field.ErrorList
Expand Down Expand Up @@ -107,12 +108,12 @@ func (r *VSphereVM) ValidateUpdate(old runtime.Object) error {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
}

return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *VSphereVM) ValidateDelete() error {
return nil
func (r *VSphereVM) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}

func (r *VSphereVM) deleteSpecKeys(spec map[string]interface{}, keys []string) {
Expand Down
Loading

0 comments on commit 6d70d7e

Please sign in to comment.