Skip to content

Commit

Permalink
add fnalizer using patch interface
Browse files Browse the repository at this point in the history
Signed-off-by: zcq98 <[email protected]>
  • Loading branch information
zcq98 committed Dec 11, 2023
1 parent 61ef8b0 commit f3799ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 18 additions & 4 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
}
Expand All @@ -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
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
}
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/ovn-vpc-nat-gw/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -740,14 +740,15 @@ var _ = framework.Describe("[group:ovn-vpc-nat-gw]", func() {
noBfdExtraSubnetV4Cidr := "192.168.3.0/24"
noBfdExtraSubnetV4Gw := "192.168.3.1"

noBfdVpc = vpcClient.Get(noBfdVpcName)
CachedVpc := vpcClient.Get(noBfdVpcName)
noBfdVpc = CachedVpc.DeepCopy()
noBfdVpc.Spec.ExtraExternalSubnets = append(noBfdVpc.Spec.ExtraExternalSubnets, underlayExtraSubnetName)
noBfdVpc.Spec.StaticRoutes = append(noBfdVpc.Spec.StaticRoutes, &kubeovnv1.StaticRoute{
Policy: kubeovnv1.PolicySrc,
CIDR: noBfdExtraSubnetV4Cidr,
NextHopIP: gatewayV4,
})
_, err = vpcClient.Update(context.Background(), noBfdVpc, metav1.UpdateOptions{})
_ = vpcClient.PatchSync(CachedVpc, noBfdVpc, nil, 180*time.Second)
framework.ExpectNoError(err)

ginkgo.By("Creating overlay subnet " + noBfdExtraSubnetName)
Expand Down

0 comments on commit f3799ce

Please sign in to comment.