Skip to content

fix: skip unallocated pods during IPAM initialization#6327

Merged
oilbeater merged 1 commit intomasterfrom
fix/skip-unallocated-pods-in-init-ipam
Feb 24, 2026
Merged

fix: skip unallocated pods during IPAM initialization#6327
oilbeater merged 1 commit intomasterfrom
fix/skip-unallocated-pods-in-init-ipam

Conversation

@oilbeater
Copy link
Copy Markdown
Collaborator

Summary

  • During controller first startup, InitIPAM() iterates all pods and calls getPodKubeovnNets(), which checks namespace network annotations. However, namespace annotations are not yet set at this point because the namespace worker starts after InitIPAM(). This causes spurious error logs for pods not yet managed by kube-ovn (e.g., coredns on first startup):
    E0223 02:05:17.580428  pod.go:1673] namespace kube-system network annotations is empty
    E0223 02:05:17.580621  init.go:442] failed to get pod kubeovn nets coredns-xxx.kube-system address : namespace kube-system network annotations is empty
    
  • Skip pods without any *.kubernetes.io/allocated=true annotation before calling getPodKubeovnNets(), since they have no IP to restore into IPAM anyway. The inner loop at init.go:450 already checks allocated == "true" per provider, so these pods would be no-ops even if they passed.

Test plan

  • Unit tests for hasAllocatedAnnotation() covering nil/empty annotations, default/custom providers, false values, and multi-provider scenarios
  • make lint passes with 0 issues
  • go test ./pkg/controller/... passes

🤖 Generated with Claude Code

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 24, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @oilbeater, 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 refines the IPAM initialization process to prevent unnecessary error logging during the controller's initial startup. By introducing a preliminary check, the system now intelligently bypasses pods that lack IP allocation annotations, ensuring that getPodKubeovnNets() is only called for relevant pods. This optimization improves log clarity and system stability during the critical startup phase.

Highlights

  • Error Log Reduction: Eliminated spurious error logs during controller startup by preventing InitIPAM() from processing pods before namespace network annotations are fully available.
  • IPAM Initialization Optimization: Introduced a preliminary check to skip pods that do not have any *.kubernetes.io/allocated=true annotation during IPAM initialization, as these pods do not require IP restoration.
  • New Helper Function: Added a new private helper function, hasAllocatedAnnotation, to efficiently determine if a given pod has any allocated annotation set to 'true'.
  • Comprehensive Test Coverage: Included a dedicated unit test file for the hasAllocatedAnnotation function, covering various scenarios including nil/empty annotations, default/custom providers, false values, and multi-provider setups.
Changelog
  • pkg/controller/init.go
    • Added a check to skip pods without allocated annotations in the InitIPAM() function.
    • Implemented the hasAllocatedAnnotation helper function.
  • pkg/controller/init_test.go
    • Added a new test file containing unit tests for the hasAllocatedAnnotation function.
Activity
  • Unit tests for hasAllocatedAnnotation() were added and passed, covering nil/empty annotations, default/custom providers, false values, and multi-provider scenarios.
  • make lint passed with 0 issues.
  • go test ./pkg/controller/... passed.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

@dosubot dosubot bot added bug Something isn't working go Pull requests that update Go code test automation tests labels Feb 24, 2026
@coveralls
Copy link
Copy Markdown

coveralls commented Feb 24, 2026

Pull Request Test Coverage Report for Build 22335642797

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 6 of 8 (75.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 23.064%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/controller/init.go 6 8 75.0%
Totals Coverage Status
Change from base Build 22313794790: 0.007%
Covered Lines: 12539
Relevant Lines: 54365

💛 - Coveralls

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 successfully addresses the issue of spurious error logs during InitIPAM() by skipping pods that have not yet been allocated an IP by Kube-OVN. This is a sound approach because InitIPAM() is intended to restore existing state, and pods without allocation annotations have no state to restore at this stage. The implementation is clean, follows existing patterns in the codebase, and includes comprehensive unit tests for the new helper function.

…us errors

During controller startup, InitIPAM() iterates over all pods and calls
getPodKubeovnNets(), which checks namespace network annotations. However,
namespace annotations are not yet set at this point because the namespace
worker starts after InitIPAM(). This causes spurious error logs like
"namespace kube-system network annotations is empty" for pods that have
not been allocated an IP by kube-ovn (e.g., coredns on first startup).

Skip pods without any allocated annotation before calling
getPodKubeovnNets(), since they have no IP to restore into IPAM anyway.

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@oilbeater oilbeater force-pushed the fix/skip-unallocated-pods-in-init-ipam branch from 7403638 to 467049c Compare February 24, 2026 03:43
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 24, 2026
@oilbeater oilbeater merged commit 6ef934d into master Feb 24, 2026
75 of 77 checks passed
@oilbeater oilbeater deleted the fix/skip-unallocated-pods-in-init-ipam branch February 24, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files. test automation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants