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 930a97c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
21 changes: 17 additions & 4 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,16 @@ func checkAndUpdateExcludeIPs(subnet *kubeovnv1.Subnet) bool {
}

func (c *Controller) handleSubnetFinalizer(subnet *kubeovnv1.Subnet) (bool, error) {
newSubnet := subnet.DeepCopy()
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.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,14 @@ 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.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, time.Duration(180*time.Second))

Check failure on line 751 in test/e2e/ovn-vpc-nat-gw/e2e_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)
framework.ExpectNoError(err)

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

0 comments on commit 930a97c

Please sign in to comment.