Skip to content

Conversation

@emy
Copy link
Collaborator

@emy emy commented Dec 2, 2025

Is this a BUG FIX or a FEATURE ?:

Uncomment only one, leave it on its own line:

/kind bug

/kind enhancement

What this PR does / why we need it:
The recently added NNCP retry added some delay into the CI (due to the negative tests which will result in the NNCP retrying for minutes each time). So I added a configurable backoff strategy which keeps the same defaults but offers configuration.

Special notes for your reviewer:

Release note:

The NNCP backoff strategy can be configured through the NMState CR now. (Default values stay initial delay 1s, max. delay 30s, 5 retries)

Implements: OPNET-738

Signed-off-by: Emilia Desch <emy@redhat.com>
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/enhancement dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Dec 2, 2025
@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign qinqon for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist
Copy link

Summary of Changes

Hello @emy, 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 NMState operator by making the NNCP retry and backoff strategy configurable via the NMState Custom Resource. This provides operators with greater control over how network configuration policies are retried, which can be particularly useful for optimizing CI environments and handling transient network issues more efficiently.

Highlights

  • Configurable NNCP Retry Strategy: Introduced the ability to configure the NodeNetworkConfigurationPolicy (NNCP) retry and backoff strategy directly through the NMState Custom Resource (CR).
  • Performance Improvement for CI: This change addresses delays in CI caused by negative tests, which previously resulted in NNCP retries lasting several minutes. Users can now adjust retry parameters to optimize CI performance.
  • Default Values Maintained: The existing default retry values (initial delay 1s, maximum delay 30s, 5 retries) are preserved, ensuring no change in behavior unless explicitly configured.
  • New Configuration Fields: Added InitialBackoff, MaximumBackoff, and MaxRetries fields to the NMStateRetryConfiguration struct, allowing fine-grained control over the retry mechanism.
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.

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 introduces a configurable retry strategy for NodeNetworkConfigurationPolicy reconciliation, which is a great enhancement for flexibility, especially in CI environments. The changes are well-structured, touching the API, CRD, controller, and tests. I've found a couple of issues in how the configuration is read and handled, which could lead to incorrect behavior. Specifically, there's a bug that prevents users from setting maxRetries to 0, and some redundant code in error handling. My review includes suggestions to fix these issues. Overall, a good and needed change.

Comment on lines +289 to +302
initialBackoff = defaultInitialBackoff
if retryConfig.InitialBackoff.Duration != 0 {
initialBackoff = retryConfig.InitialBackoff.Duration
}

maximumBackoff = defaultMaximumBackoff
if retryConfig.MaximumBackoff.Duration != 0 {
maximumBackoff = retryConfig.MaximumBackoff.Duration
}

maxRetries = defaultMaxRetries
if retryConfig.MaxRetries != 0 {
maxRetries = retryConfig.MaxRetries
}

Choose a reason for hiding this comment

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

high

The current logic for reading the retry configuration from the NMState CR is flawed. It checks if the values are non-zero before using them, which prevents a user from setting a valid value of 0 for maxRetries. If a user sets maxRetries: 0, this code will ignore it and use the default of 5.

The kubebuilder:default annotations on the API type ensure that if a user doesn't specify a value, it will be defaulted by the API server. The code should use the values from the CR directly. For old CRs that don't have this field, the values will be zero, which will be caught by the subsequent validation logic and correctly fall back to defaults.

initialBackoff = retryConfig.InitialBackoff.Duration
maximumBackoff = retryConfig.MaximumBackoff.Duration
maxRetries = retryConfig.MaxRetries

Comment on lines +339 to +345
if err != nil {
setupLog.Error(err, "failed to retrieve retry configuration, using defaults")
// Use default values if we can't retrieve the configuration
initialBackoff = 1 * time.Second
maximumBackoff = 30 * time.Second
maxRetries = 5
}

Choose a reason for hiding this comment

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

medium

The getRetryConfiguration function already returns default values when an error occurs. The if err != nil block here re-assigns the same defaults, which is redundant. You can simplify this by just logging the error and proceeding with the values returned by the function.

if err != nil {
	setupLog.Error(err, "failed to retrieve retry configuration, using defaults")
}

Signed-off-by: Emilia Desch <emy@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/enhancement release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants