Skip to content

fix issue 5167: Add Finalizer when create snat#5170

Closed
QEDQCD wants to merge 5 commits intokubeovn:masterfrom
QEDQCD:bugfix/deletesnat
Closed

fix issue 5167: Add Finalizer when create snat#5170
QEDQCD wants to merge 5 commits intokubeovn:masterfrom
QEDQCD:bugfix/deletesnat

Conversation

@QEDQCD
Copy link
Copy Markdown
Contributor

@QEDQCD QEDQCD commented Apr 21, 2025

Pull Request

What type of this PR

Examples of user facing changes:

  • Bug fixes

Which issue(s) this PR fixes

Fixes #(5167)

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 21, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @QEDQCD, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses issue #5167 by adding a finalizer when creating a SNAT (Source Network Address Translation). The change modifies pkg/controller/vpc_nat_gw_nat.go to ensure the KubeOVNControllerFinalizer is added to the iptablesSnat object during creation. This finalizer helps manage the lifecycle of the SNAT resource and prevents premature deletion before associated resources are cleaned up.

Highlights

  • Bug Fix: Addresses issue #5167 by ensuring a finalizer is added when creating SNAT resources.
  • Finalizer Management: Adds the KubeOVNControllerFinalizer to iptablesSnat objects to control their deletion.

Changelog

  • pkg/controller/vpc_nat_gw_nat.go
    • Replaces the removal of the finalizer with the addition of the KubeOVNControllerFinalizer to the iptablesSnat object in the handleDelIptablesSnatFinalizer function. Line 964 was changed from controllerutil.RemoveFinalizer to controllerutil.AddFinalizer.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A finalizer's gentle hand,
Guides resources across the land.
No premature deletion,
A managed completion,
Ensuring states correctly stand.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request aims to fix issue 5167 by adding a finalizer when creating a snat. The change involves modifying the handleDelIptablesSnatFinalizer function to add the KubeOVNControllerFinalizer instead of removing the deprecated and current finalizers. This ensures that the finalizer is present during snat creation.

Summary of Findings

  • Incorrect Finalizer Handling: The code in handleDelIptablesSnatFinalizer is adding a finalizer instead of removing it, which is counterintuitive to the function's name and purpose. This could lead to unexpected behavior during deletion.

Merge Readiness

The pull request contains a critical error in the finalizer handling logic. The handleDelIptablesSnatFinalizer function is adding a finalizer instead of removing it. This needs to be corrected before merging. I am unable to approve this pull request, and recommend that it not be merged until the critical issue is addressed.

Comment thread pkg/controller/vpc_nat_gw_nat.go Outdated
Comment on lines +964 to +965
controllerutil.AddFinalizer(newIptablesSnat, util.Kub
eOVNControllerFinalizer)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This line is adding the finalizer instead of removing it. The function handleDelIptablesSnatFinalizer should be removing the finalizer, not adding it. This is likely a copy/paste error from the add finalizer function, and needs to be corrected to ensure proper deletion of the SNAT rule. This is a critical issue as it prevents the SNAT rule from being properly deleted, which can lead to resource leaks and other problems.

	controllerutil.RemoveFinalizer(newIptablesSnat, util.KubeOVNControllerFinalizer)

@dosubot dosubot bot added the bug Something isn't working label Apr 21, 2025
newIptablesSnat := cachedIptablesSnat.DeepCopy()
controllerutil.RemoveFinalizer(newIptablesSnat, util.DepreciatedFinalizerName)
controllerutil.RemoveFinalizer(newIptablesSnat, util.KubeOVNControllerFinalizer)
controllerutil.AddFinalizer(newIptablesSnat, util.KubeOVNControllerFinalizer)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉有点不对劲:上面的 handleAddIptablesSnatFinalizer 是删除 finalizer,这里的 handleDelIptablesSnatFinalizer 是添加 finalizer。

@github-actions
Copy link
Copy Markdown
Contributor

PRs go stale after 60d of inactivity. Please comment or re-open the PR if you are still working on this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working need backport no-pr-activity size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 创建snat规则没有默认加上finalizers:- kubeovn.io/kube-ovn-controller

3 participants