Skip to content

kubectl-ko: collect information about ipsec and xfrm #5472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2025

Conversation

zhangzujian
Copy link
Member

Pull Request

What type of this PR

Examples of user facing changes:

  • Features
  • Bug fixes
  • Docs
  • Tests

Which issue(s) this PR fixes

Fixes #(issue-number)

Copy link

@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.

Summary of Changes

Hello @zhangzujian, 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!

This pull request enhances the kubectl-ko tool by adding the ability to collect diagnostic information related to IPsec and XFRM configurations within the kube-ovn-cni pods. It also refactors the log_linux function to use a case statement, improving code readability.

Highlights

  • Collect IPsec Information: Added functionality to collect IPsec configuration, CA certificates, certificates, and status information.
  • Collect XFRM Information: Added functionality to collect XFRM policy and state information.
  • CNI Pod Selection: Modified the script to target pods with the label app=kube-ovn-cni instead of app=ovs.
  • Code Formatting: Replaced a series of if/elif statements with a case statement for improved readability in the log_linux function.
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.

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

@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

This pull request adds functionality to the kubectl-ko log command to collect ipsec and xfrm information, which is a valuable addition for debugging network issues. The refactoring from a long if/elif chain to a case statement in the log_linux function significantly improves code readability and maintainability.

I've identified one area for improvement regarding performance: the script currently makes a separate kubectl call for each pod to determine its node, which can be inefficient in larger clusters. I've suggested a way to optimize this by fetching all required information in a single command.

Overall, this is a good change that enhances the diagnostic capabilities of the tool.

@@ -1102,63 +1102,114 @@ log_linux(){
component_param=$1
sub_component_param=$2
echo "Collecting $component_param $sub_component_param files"
podNames=`kubectl get pod -n kube-system -l app=ovs -o 'jsonpath={.items[*].metadata.name}'`
podNames=`kubectl get pod -n kube-system -l app=kube-ovn-cni -o 'jsonpath={.items[*].metadata.name}'`

Choose a reason for hiding this comment

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

medium

This line fetches only pod names. The subsequent loop then makes an additional kubectl call for each pod to get its node name (on line 1107). This is inefficient due to the N+1 query problem and can be slow in clusters with many pods. It's better to fetch both pod and node names in a single kubectl call and process them together.

For example, you could refactor the loop like this:

  kubectl get pod -n kube-system -l app=kube-ovn-cni -o 'jsonpath={range .items[*]}{.metadata.name}{" "}{.spec.nodeName}{"\n"}{end}' | while read -r pod nodeName; do
    if [ -z "$pod" ]; then continue; fi
    # ... rest of the loop body ...
  done

This would significantly improve performance by reducing the number of kubectl calls.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 16213165225

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 21.429%

Totals Coverage Status
Change from base Build 16209589487: 0.004%
Covered Lines: 10522
Relevant Lines: 49102

💛 - Coveralls

@zhangzujian zhangzujian marked this pull request as ready for review July 11, 2025 06:46
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 11, 2025
@zhangzujian zhangzujian requested a review from oilbeater July 11, 2025 06:52
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 13, 2025
@zhangzujian zhangzujian merged commit dea713c into kubeovn:master Jul 13, 2025
72 checks passed
zhangzujian added a commit that referenced this pull request Jul 14, 2025
zhangzujian added a commit that referenced this pull request Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer need backport size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants