Skip to content

Commit

Permalink
Merge pull request #1009 from yastij/relax-webhook-bootstrapRef
Browse files Browse the repository at this point in the history
relax the validating webhooks to allow updating the bootstrapRef of VSphereVMs
  • Loading branch information
k8s-ci-robot authored Aug 24, 2020
2 parents ca93b3b + b634f69 commit b4a5e19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha3/vspherevm_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (r *VSphereVM) ValidateUpdate(old runtime.Object) error { //nolint
delete(oldVSphereVMSpec, "biosUUID")
delete(newVSphereVMSpec, "biosUUID")

// allow changes to bootstrapRef
delete(oldVSphereVMSpec, "bootstrapRef")
delete(newVSphereVMSpec, "bootstrapRef")

newVSphereVMNetwork := newVSphereVMSpec["network"].(map[string]interface{})
oldVSphereVMNetwork := oldVSphereVMSpec["network"].(map[string]interface{})

Expand Down
30 changes: 19 additions & 11 deletions api/v1alpha3/vspherevm_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
)

var (
Expand All @@ -37,17 +38,17 @@ func TestVSphereVM_ValidateCreate(t *testing.T) {
}{
{
name: "preferredAPIServerCIDR set on creation ",
vSphereVM: createVSphereVM("foo.com", "", "192.168.0.1/32", []string{}),
vSphereVM: createVSphereVM("foo.com", "", "192.168.0.1/32", []string{}, nil),
wantErr: true,
},
{
name: "IPs are not in CIDR format",
vSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32", "192.168.0.3"}),
vSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32", "192.168.0.3"}, nil),
wantErr: true,
},
{
name: "successful VSphereVM creation",
vSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32", "192.168.0.3/32"}),
vSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32", "192.168.0.3/32"}, nil),
wantErr: false,
},
}
Expand Down Expand Up @@ -76,20 +77,26 @@ func TestVSphereVM_ValidateUpdate(t *testing.T) {
}{
{
name: "ProviderID can be updated",
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}),
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32"}),
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}, nil),
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32"}, nil),
wantErr: false,
},
{
name: "updating ips can be done",
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}),
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}),
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}, nil),
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}, nil),
wantErr: false,
},
{
name: "updating bootstrapRef can be done",
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}, nil),
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}, &corev1.ObjectReference{}),
wantErr: false,
},
{
name: "updating server cannot be done",
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}),
vSphereVM: createVSphereVM("bar.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}),
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}, nil),
vSphereVM: createVSphereVM("bar.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}, nil),
wantErr: true,
},
}
Expand All @@ -105,10 +112,11 @@ func TestVSphereVM_ValidateUpdate(t *testing.T) {
}
}

func createVSphereVM(server string, biosUUID string, preferredAPIServerCIDR string, ips []string) *VSphereVM {
func createVSphereVM(server string, biosUUID string, preferredAPIServerCIDR string, ips []string, bootstrapRef *corev1.ObjectReference) *VSphereVM {
VSphereVM := &VSphereVM{
Spec: VSphereVMSpec{
BiosUUID: biosUUID,
BiosUUID: biosUUID,
BootstrapRef: bootstrapRef,
VirtualMachineCloneSpec: VirtualMachineCloneSpec{
Server: server,
Network: NetworkSpec{
Expand Down

0 comments on commit b4a5e19

Please sign in to comment.