Skip to content

Commit b4a5e19

Browse files
authored
Merge pull request #1009 from yastij/relax-webhook-bootstrapRef
relax the validating webhooks to allow updating the bootstrapRef of VSphereVMs
2 parents ca93b3b + b634f69 commit b4a5e19

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

api/v1alpha3/vspherevm_webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func (r *VSphereVM) ValidateUpdate(old runtime.Object) error { //nolint
7575
delete(oldVSphereVMSpec, "biosUUID")
7676
delete(newVSphereVMSpec, "biosUUID")
7777

78+
// allow changes to bootstrapRef
79+
delete(oldVSphereVMSpec, "bootstrapRef")
80+
delete(newVSphereVMSpec, "bootstrapRef")
81+
7882
newVSphereVMNetwork := newVSphereVMSpec["network"].(map[string]interface{})
7983
oldVSphereVMNetwork := oldVSphereVMSpec["network"].(map[string]interface{})
8084

api/v1alpha3/vspherevm_webhook_test.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/gomega"
23+
corev1 "k8s.io/api/core/v1"
2324
)
2425

2526
var (
@@ -37,17 +38,17 @@ func TestVSphereVM_ValidateCreate(t *testing.T) {
3738
}{
3839
{
3940
name: "preferredAPIServerCIDR set on creation ",
40-
vSphereVM: createVSphereVM("foo.com", "", "192.168.0.1/32", []string{}),
41+
vSphereVM: createVSphereVM("foo.com", "", "192.168.0.1/32", []string{}, nil),
4142
wantErr: true,
4243
},
4344
{
4445
name: "IPs are not in CIDR format",
45-
vSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32", "192.168.0.3"}),
46+
vSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32", "192.168.0.3"}, nil),
4647
wantErr: true,
4748
},
4849
{
4950
name: "successful VSphereVM creation",
50-
vSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32", "192.168.0.3/32"}),
51+
vSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32", "192.168.0.3/32"}, nil),
5152
wantErr: false,
5253
},
5354
}
@@ -76,20 +77,26 @@ func TestVSphereVM_ValidateUpdate(t *testing.T) {
7677
}{
7778
{
7879
name: "ProviderID can be updated",
79-
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}),
80-
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32"}),
80+
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}, nil),
81+
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32"}, nil),
8182
wantErr: false,
8283
},
8384
{
8485
name: "updating ips can be done",
85-
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}),
86-
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}),
86+
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}, nil),
87+
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}, nil),
88+
wantErr: false,
89+
},
90+
{
91+
name: "updating bootstrapRef can be done",
92+
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}, nil),
93+
vSphereVM: createVSphereVM("foo.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}, &corev1.ObjectReference{}),
8794
wantErr: false,
8895
},
8996
{
9097
name: "updating server cannot be done",
91-
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}),
92-
vSphereVM: createVSphereVM("bar.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}),
98+
oldVSphereVM: createVSphereVM("foo.com", "", "", []string{"192.168.0.1/32"}, nil),
99+
vSphereVM: createVSphereVM("bar.com", biosUUID, "", []string{"192.168.0.1/32", "192.168.0.10/32"}, nil),
93100
wantErr: true,
94101
},
95102
}
@@ -105,10 +112,11 @@ func TestVSphereVM_ValidateUpdate(t *testing.T) {
105112
}
106113
}
107114

108-
func createVSphereVM(server string, biosUUID string, preferredAPIServerCIDR string, ips []string) *VSphereVM {
115+
func createVSphereVM(server string, biosUUID string, preferredAPIServerCIDR string, ips []string, bootstrapRef *corev1.ObjectReference) *VSphereVM {
109116
VSphereVM := &VSphereVM{
110117
Spec: VSphereVMSpec{
111-
BiosUUID: biosUUID,
118+
BiosUUID: biosUUID,
119+
BootstrapRef: bootstrapRef,
112120
VirtualMachineCloneSpec: VirtualMachineCloneSpec{
113121
Server: server,
114122
Network: NetworkSpec{

0 commit comments

Comments
 (0)