Skip to content

Commit

Permalink
add fnalizer use 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 d0ea98f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 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.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
}
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.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
}
Expand Down
2 changes: 1 addition & 1 deletion 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

0 comments on commit d0ea98f

Please sign in to comment.