diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index c6b215db3d02..47c9d806faa7 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -479,8 +479,15 @@ func checkAndUpdateExcludeIPs(subnet *kubeovnv1.Subnet) bool { func (c *Controller) handleSubnetFinalizer(subnet *kubeovnv1.Subnet) (bool, error) { if subnet.DeletionTimestamp.IsZero() && !util.ContainsString(subnet.Finalizers, util.ControllerName) { - subnet.Finalizers = append(subnet.Finalizers, util.ControllerName) - if _, err := c.config.KubeOvnClient.KubeovnV1().Subnets().Update(context.Background(), subnet, metav1.UpdateOptions{}); err != nil { + newSubnet := subnet.DeepCopy() + newSubnet.Finalizers = append(newSubnet.Finalizers, util.ControllerName) + patch, err := util.GenerateMergePatchPayload(subnet, newSubnet) + if err != nil { + klog.Errorf("failed to generate patch payload for subnet '%s', %v", subnet.Name, err) + return false, err + } + if _, err := c.config.KubeOvnClient.KubeovnV1().Subnets().Patch(context.Background(), subnet.Name, + types.MergePatchType, patch, metav1.PatchOptions{}, ""); err != nil { klog.Errorf("failed to add finalizer to subnet %s, %v", subnet.Name, err) return false, err } @@ -496,8 +503,15 @@ func (c *Controller) handleSubnetFinalizer(subnet *kubeovnv1.Subnet) (bool, erro u2oInterconnIP := subnet.Status.U2OInterconnectionIP if !subnet.DeletionTimestamp.IsZero() && (usingIPs == 0 || (usingIPs == 1 && u2oInterconnIP != "")) { - subnet.Finalizers = util.RemoveString(subnet.Finalizers, util.ControllerName) - if _, err := c.config.KubeOvnClient.KubeovnV1().Subnets().Update(context.Background(), subnet, metav1.UpdateOptions{}); err != nil { + newSubnet := subnet.DeepCopy() + newSubnet.Finalizers = util.RemoveString(newSubnet.Finalizers, util.ControllerName) + patch, err := util.GenerateMergePatchPayload(subnet, newSubnet) + if err != nil { + klog.Errorf("failed to generate patch payload for subnet '%s', %v", subnet.Name, err) + return false, err + } + if _, err := c.config.KubeOvnClient.KubeovnV1().Subnets().Patch(context.Background(), subnet.Name, + types.MergePatchType, patch, metav1.PatchOptions{}, ""); err != nil { klog.Errorf("failed to remove finalizer from subnet %s, %v", subnet.Name, err) return false, err } diff --git a/test/e2e/ovn-vpc-nat-gw/e2e_test.go b/test/e2e/ovn-vpc-nat-gw/e2e_test.go index c6814089f259..d7baebd09c80 100644 --- a/test/e2e/ovn-vpc-nat-gw/e2e_test.go +++ b/test/e2e/ovn-vpc-nat-gw/e2e_test.go @@ -158,7 +158,7 @@ var _ = framework.Describe("[group:ovn-vpc-nat-gw]", func() { providerNetworkName = "external" providerExtraNetworkName = "extra" vlanName = "vlan-" + framework.RandomSuffix() - vlanExtraName = "vlan-extra" + framework.RandomSuffix() + vlanExtraName = "vlan-extra-" + framework.RandomSuffix() underlaySubnetName = "external" underlayExtraSubnetName = "extra"