Skip to content
Merged
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
4 changes: 2 additions & 2 deletions controllers/vmware/test/controllers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ func getManager(cfg *rest.Config, networkProvider string, withWebhooks bool) man
}

if withWebhooks {
if err := (&vmwarewebhooks.VSphereMachineTemplateWebhook{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&vmwarewebhooks.VSphereMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&vmwarewebhooks.VSphereMachineWebhook{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&vmwarewebhooks.VSphereMachine{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
}
Expand Down
12 changes: 6 additions & 6 deletions internal/test/helpers/envtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,27 @@ func NewTestEnvironment(ctx context.Context) *TestEnvironment {
Password: simr.Password(),
}
managerOpts.AddToManager = func(_ context.Context, _ *capvcontext.ControllerManagerContext, mgr ctrlmgr.Manager) error {
if err := (&webhooks.VSphereClusterTemplateWebhook{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&webhooks.VSphereClusterTemplate{}).SetupWebhookWithManager(mgr); err != nil {
return err
}

if err := (&webhooks.VSphereMachineWebhook{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&webhooks.VSphereMachine{}).SetupWebhookWithManager(mgr); err != nil {
return err
}

if err := (&webhooks.VSphereMachineTemplateWebhook{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&webhooks.VSphereMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil {
return err
}

if err := (&webhooks.VSphereVMWebhook{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&webhooks.VSphereVM{}).SetupWebhookWithManager(mgr); err != nil {
return err
}

if err := (&webhooks.VSphereDeploymentZoneWebhook{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&webhooks.VSphereDeploymentZone{}).SetupWebhookWithManager(mgr); err != nil {
return err
}

return (&webhooks.VSphereFailureDomainWebhook{}).SetupWebhookWithManager(mgr)
return (&webhooks.VSphereFailureDomain{}).SetupWebhookWithManager(mgr)
}

mgr, err := manager.New(ctx, managerOpts)
Expand Down
18 changes: 9 additions & 9 deletions internal/webhooks/vmware/vspheremachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ import (
// +kubebuilder:webhook:verbs=create;update,path=/validate-vmware-infrastructure-cluster-x-k8s-io-v1beta1-vspheremachine,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=vmware.infrastructure.cluster.x-k8s.io,resources=vspheremachines,versions=v1beta1,name=validation.vspheremachine.vmware.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
// +kubebuilder:webhook:verbs=create;update,path=/mutate-vmware-infrastructure-cluster-x-k8s-io-v1beta1-vspheremachine,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=vmware.infrastructure.cluster.x-k8s.io,resources=vspheremachines,versions=v1beta1,name=default.vspheremachine.vmware.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1

// VSphereMachineWebhook implements a validation and defaulting webhook for VSphereMachine.
type VSphereMachineWebhook struct{}
// VSphereMachine implements a validation and defaulting webhook for VSphereMachine.
type VSphereMachine struct{}

var _ webhook.CustomValidator = &VSphereMachineWebhook{}
var _ webhook.CustomDefaulter = &VSphereMachineWebhook{}
var _ webhook.CustomValidator = &VSphereMachine{}
var _ webhook.CustomDefaulter = &VSphereMachine{}

func (webhook *VSphereMachineWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (webhook *VSphereMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(&vmwarev1.VSphereMachine{}).
WithValidator(webhook).
Expand All @@ -50,17 +50,17 @@ func (webhook *VSphereMachineWebhook) SetupWebhookWithManager(mgr ctrl.Manager)
}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (webhook *VSphereMachineWebhook) Default(_ context.Context, _ runtime.Object) error {
func (webhook *VSphereMachine) Default(_ context.Context, _ runtime.Object) error {
return nil
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereMachineWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereMachine) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereMachineWebhook) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereMachine) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList

newTyped, ok := newRaw.(*vmwarev1.VSphereMachine)
Expand Down Expand Up @@ -100,6 +100,6 @@ func (webhook *VSphereMachineWebhook) ValidateUpdate(_ context.Context, oldRaw r
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereMachineWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereMachine) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
2 changes: 1 addition & 1 deletion internal/webhooks/vmware/vspheremachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestVSphereMachine_ValidateUpdate(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)

webhook := &VSphereMachineWebhook{}
webhook := &VSphereMachine{}
_, err := webhook.ValidateUpdate(context.Background(), tc.oldVSphereMachine, tc.vsphereMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
Expand Down
16 changes: 8 additions & 8 deletions internal/webhooks/vmware/vspheremachinetemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ import (

// +kubebuilder:webhook:verbs=create;update,path=/validate-vmware-infrastructure-cluster-x-k8s-io-v1beta1-vspheremachinetemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=vmware.infrastructure.cluster.x-k8s.io,resources=vspheremachinetemplates,versions=v1beta1,name=validation.vspheremachinetemplate.vmware.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1

// VSphereMachineTemplateWebhook implements a validation webhook for VSphereMachineTemplate.
type VSphereMachineTemplateWebhook struct{}
// VSphereMachineTemplate implements a validation webhook for VSphereMachineTemplate.
type VSphereMachineTemplate struct{}

var _ webhook.CustomValidator = &VSphereMachineTemplateWebhook{}
var _ webhook.CustomValidator = &VSphereMachineTemplate{}

func (webhook *VSphereMachineTemplateWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (webhook *VSphereMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(&vmwarev1.VSphereMachineTemplate{}).
WithValidator(webhook).
Complete()
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereMachineTemplateWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereMachineTemplate) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
vSphereMachineTemplate, ok := obj.(*vmwarev1.VSphereMachineTemplate)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereMachineTemplate but got a %T", obj))
Expand All @@ -57,15 +57,15 @@ func (webhook *VSphereMachineTemplateWebhook) ValidateCreate(ctx context.Context
}

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

func (webhook *VSphereMachineTemplateWebhook) validate(_ context.Context, _, newVSphereMachineTemplate *vmwarev1.VSphereMachineTemplate) (admission.Warnings, error) {
func (webhook *VSphereMachineTemplate) validate(_ context.Context, _, newVSphereMachineTemplate *vmwarev1.VSphereMachineTemplate) (admission.Warnings, error) {
var allErrs field.ErrorList

// Validate namingStrategy
Expand Down Expand Up @@ -103,6 +103,6 @@ func (webhook *VSphereMachineTemplateWebhook) validate(_ context.Context, _, new
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereMachineTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereMachineTemplate) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
2 changes: 1 addition & 1 deletion internal/webhooks/vmware/vspheremachinetemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestVSphereMachineTemplate_Validate(t *testing.T) {
},
}

webhook := &VSphereMachineTemplateWebhook{}
webhook := &VSphereMachineTemplate{}
_, err := webhook.validate(context.Background(), nil, vSphereMachineTemplate)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
Expand Down
14 changes: 7 additions & 7 deletions internal/webhooks/vsphereclustertemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ import (

// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-vsphereclustertemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=vsphereclustertemplates,versions=v1beta1,name=validation.vsphereclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1

// VSphereClusterTemplateWebhook implements a validation and defaulting webhook for VSphereClusterTemplate.
type VSphereClusterTemplateWebhook struct{}
// VSphereClusterTemplate implements a validation webhook for VSphereClusterTemplate.
type VSphereClusterTemplate struct{}

var _ webhook.CustomValidator = &VSphereClusterTemplateWebhook{}
var _ webhook.CustomValidator = &VSphereClusterTemplate{}

func (webhook *VSphereClusterTemplateWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (webhook *VSphereClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(&infrav1.VSphereClusterTemplate{}).
WithValidator(webhook).
Complete()
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereClusterTemplateWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereClusterTemplate) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereClusterTemplateWebhook) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereClusterTemplate) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
oldTyped, ok := oldRaw.(*infrav1.VSphereClusterTemplate)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereClusterTemplate but got a %T", oldRaw))
Expand All @@ -67,6 +67,6 @@ func (webhook *VSphereClusterTemplateWebhook) ValidateUpdate(_ context.Context,
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereClusterTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereClusterTemplate) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
10 changes: 5 additions & 5 deletions internal/webhooks/vspheredeploymentzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ import (

// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-vspheredeploymentzone,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=vspheredeploymentzones,versions=v1beta1,name=default.vspheredeploymentzone.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1

// VSphereDeploymentZoneWebhook implements a validation and defaulting webhook for VSphereDeploymentZone.
type VSphereDeploymentZoneWebhook struct{}
// VSphereDeploymentZone implements a defaulting webhook for VSphereDeploymentZone.
type VSphereDeploymentZone struct{}

var _ webhook.CustomDefaulter = &VSphereDeploymentZoneWebhook{}
var _ webhook.CustomDefaulter = &VSphereDeploymentZone{}

func (webhook *VSphereDeploymentZoneWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (webhook *VSphereDeploymentZone) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(&infrav1.VSphereDeploymentZone{}).
WithDefaulter(webhook, admission.DefaulterRemoveUnknownOrOmitableFields).
Complete()
}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (webhook *VSphereDeploymentZoneWebhook) Default(_ context.Context, obj runtime.Object) error {
func (webhook *VSphereDeploymentZone) Default(_ context.Context, obj runtime.Object) error {
typedObj, ok := obj.(*infrav1.VSphereDeploymentZone)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereDeploymentZone but got a %T", obj))
Expand Down
2 changes: 1 addition & 1 deletion internal/webhooks/vspheredeploymentzone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestVSphereDeploymentZone_Default(t *testing.T) {
ControlPlane: tt.boolPtr,
},
}
webhook := VSphereDeploymentZoneWebhook{}
webhook := VSphereDeploymentZone{}
g.Expect(webhook.Default(context.Background(), &vdz)).NotTo(HaveOccurred())
g.Expect(vdz.Spec.ControlPlane).NotTo(BeNil())
g.Expect(*vdz.Spec.ControlPlane).To(Equal(tt.expectedVal))
Expand Down
18 changes: 9 additions & 9 deletions internal/webhooks/vspherefailuredomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ import (
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-vspherefailuredomain,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=vspherefailuredomains,versions=v1beta1,name=validation.vspherefailuredomain.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
// +kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-vspherefailuredomain,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=vspherefailuredomains,verbs=create;update,versions=v1beta1,name=default.vspherefailuredomain.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1

// VSphereFailureDomainWebhook implements a validation and defaulting webhook for VSphereFailureDomain.
type VSphereFailureDomainWebhook struct{}
// VSphereFailureDomain implements a validation and defaulting webhook for VSphereFailureDomain.
type VSphereFailureDomain struct{}

var _ webhook.CustomValidator = &VSphereFailureDomainWebhook{}
var _ webhook.CustomDefaulter = &VSphereFailureDomainWebhook{}
var _ webhook.CustomValidator = &VSphereFailureDomain{}
var _ webhook.CustomDefaulter = &VSphereFailureDomain{}

func (webhook *VSphereFailureDomainWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (webhook *VSphereFailureDomain) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(&infrav1.VSphereFailureDomain{}).
WithValidator(webhook).
Expand All @@ -50,7 +50,7 @@ func (webhook *VSphereFailureDomainWebhook) SetupWebhookWithManager(mgr ctrl.Man
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereFailureDomainWebhook) ValidateCreate(_ context.Context, raw runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereFailureDomain) ValidateCreate(_ context.Context, raw runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList

obj, ok := raw.(*infrav1.VSphereFailureDomain)
Expand Down Expand Up @@ -91,7 +91,7 @@ func (webhook *VSphereFailureDomainWebhook) ValidateCreate(_ context.Context, ra
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereFailureDomainWebhook) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereFailureDomain) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
oldTyped, ok := oldRaw.(*infrav1.VSphereFailureDomain)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereFailureDomain but got a %T", oldRaw))
Expand All @@ -107,12 +107,12 @@ func (webhook *VSphereFailureDomainWebhook) ValidateUpdate(_ context.Context, ol
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (webhook *VSphereFailureDomainWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (webhook *VSphereFailureDomain) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (webhook *VSphereFailureDomainWebhook) Default(_ context.Context, obj runtime.Object) error {
func (webhook *VSphereFailureDomain) Default(_ context.Context, obj runtime.Object) error {
typedObj, ok := obj.(*infrav1.VSphereFailureDomain)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a VSphereFailureDomain but got a %T", obj))
Expand Down
4 changes: 2 additions & 2 deletions internal/webhooks/vspherefailuredomain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestVsphereFailureDomain_Default(t *testing.T) {
m := &infrav1.VSphereFailureDomain{
Spec: infrav1.VSphereFailureDomainSpec{},
}
webhook := &VSphereFailureDomainWebhook{}
webhook := &VSphereFailureDomain{}
g.Expect(webhook.Default(context.Background(), m)).ToNot(HaveOccurred())

g.Expect(*m.Spec.Zone.AutoConfigure).To(BeFalse())
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestVSphereFailureDomain_ValidateCreate(t *testing.T) {
// Need to reinit the test variable
tt := tt
t.Run(tt.name, func(*testing.T) {
webhook := &VSphereFailureDomainWebhook{}
webhook := &VSphereFailureDomain{}
_, err := webhook.ValidateCreate(context.Background(), &tt.failureDomain)
if tt.errExpected == nil || *tt.errExpected {
g.Expect(err).To(HaveOccurred())
Expand Down
Loading