Skip to content

Commit a52abe2

Browse files
authored
fix: webhook e2e (#6163)
Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
1 parent 864f2c6 commit a52abe2

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ talos/controlplane.yaml
6767
talos/worker.yaml
6868
talos/cluster-config.yaml
6969
talos/machine-config.yaml
70+
71+
# Local build binaries
72+
cmd/cmd
73+
cmd/cni/cni
74+
cmd/controller/controller
75+
cmd/daemon/daemon

test/e2e/webhook/subnet/subnet.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package subnet
33
import (
44
"context"
55

6-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7-
86
"github.com/onsi/ginkgo/v2"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
"k8s.io/client-go/util/retry"
99

1010
apiv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
1111
"github.com/kubeovn/kube-ovn/pkg/util"
@@ -95,39 +95,39 @@ var _ = framework.Describe("[group:webhook-subnet]", func() {
9595
f.SkipVersionPriorTo(1, 15, "vpc cannot be set to non-ovn-cluster on update is not supported before 1.15.0")
9696
ginkgo.By("Creating subnet " + subnetName)
9797
subnet := framework.MakeSubnet(subnetName, "", cidr, "", "", "", nil, nil, nil)
98-
subnet = subnetClient.CreateSync(subnet)
98+
subnetClient.CreateSync(subnet)
9999

100100
ginkgo.By("Validating vpc can be changed from empty to ovn-cluster")
101-
modifiedSubnet := subnet.DeepCopy()
102-
modifiedSubnet.Spec.Vpc = util.DefaultVpc
103-
_, err := subnetClient.SubnetInterface.Update(context.TODO(), modifiedSubnet, metav1.UpdateOptions{})
101+
err := updateSubnetVpc(subnetClient, subnetName, util.DefaultVpc)
104102
framework.ExpectNoError(err)
105103

106104
ginkgo.By("Validating vpc cannot be changed from ovn-cluster to another value")
107-
subnet = subnetClient.Get(subnetName)
108-
modifiedSubnet = subnet.DeepCopy()
109-
modifiedSubnet.Spec.Vpc = "test-vpc"
110-
_, err = subnetClient.SubnetInterface.Update(context.TODO(), modifiedSubnet, metav1.UpdateOptions{})
105+
err = updateSubnetVpc(subnetClient, subnetName, "test-vpc")
111106
framework.ExpectError(err, "vpc can only be changed from empty to ovn-cluster")
112107

113108
ginkgo.By("Validating vpc cannot be changed from ovn-cluster to empty")
114-
subnet = subnetClient.Get(subnetName)
115-
modifiedSubnet = subnet.DeepCopy()
116-
modifiedSubnet.Spec.Vpc = ""
117-
_, err = subnetClient.SubnetInterface.Update(context.TODO(), modifiedSubnet, metav1.UpdateOptions{})
109+
err = updateSubnetVpc(subnetClient, subnetName, "")
118110
framework.ExpectError(err, "vpc can only be changed from empty to ovn-cluster")
119111
})
120112

121113
framework.ConformanceIt("check subnet vpc cannot be set to non-ovn-cluster on update", func() {
122114
f.SkipVersionPriorTo(1, 15, "vpc cannot be set to non-ovn-cluster on update is not supported before 1.15.0")
123115
ginkgo.By("Creating subnet " + subnetName + " with empty vpc")
124116
subnet := framework.MakeSubnet(subnetName, "", cidr, "", "", "", nil, nil, nil)
125-
subnet = subnetClient.CreateSync(subnet)
117+
subnetClient.CreateSync(subnet)
126118

127119
ginkgo.By("Validating vpc cannot be changed from empty to non-ovn-cluster value")
128-
modifiedSubnet := subnet.DeepCopy()
129-
modifiedSubnet.Spec.Vpc = "test-vpc"
130-
_, err := subnetClient.SubnetInterface.Update(context.TODO(), modifiedSubnet, metav1.UpdateOptions{})
120+
err := updateSubnetVpc(subnetClient, subnetName, "test-vpc")
131121
framework.ExpectError(err, "vpc can only be changed from empty to ovn-cluster")
132122
})
133123
})
124+
125+
func updateSubnetVpc(client *framework.SubnetClient, name, vpc string) error {
126+
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
127+
subnet := client.Get(name)
128+
modifiedSubnet := subnet.DeepCopy()
129+
modifiedSubnet.Spec.Vpc = vpc
130+
_, err := client.SubnetInterface.Update(context.Background(), modifiedSubnet, metav1.UpdateOptions{})
131+
return err
132+
})
133+
}

0 commit comments

Comments
 (0)