@@ -3,9 +3,9 @@ package subnet
33import (
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