Skip to content

Conversation

@mkowalski
Copy link
Member

@mkowalski mkowalski commented May 21, 2025

This commit adds a context to the function executing nmstatectl on the host. Thanks to this, we can add timeout of 10 seconds to every execution of nmstatectl show.

Given this is a reasonable time in which this should finish, we will prevent process from hanging in rare cases when show takes infinite amount of time to finish.

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:

Special notes for your reviewer:

Release note:

Every execution of `nmstatectl show` has a default timeout of 10 seconds. This prevents rare cases when the command never finishes and leaves the process hanging.

Summary by Sourcery

Add context support to nmstatectl invocations, migrate to exec.CommandContext, and enforce a 10s timeout on the Show command to avoid indefinite hangs.

Enhancements:

  • Introduce context.Context parameters to nmstatectl execution functions and switch to exec.CommandContext
  • Apply a default 10-second timeout to the Show command to prevent hangs
  • Update Set, Commit, Rollback, Statistic, and Policy functions to supply a context to nmstatectl calls

This commit adds a context to the function executing nmstatectl on the
host. Thanks to this, we can add timeout of 10 seconds to every
execution of `nmstatectl show`.

Given this is a reasonable time in which this should finish, we will
prevent process from hanging in rare cases when `show` takes infinite
amount of time to finish.

Signed-off-by: Mat Kowalski <[email protected]>
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/bug labels May 21, 2025
@kubevirt-bot kubevirt-bot requested review from phoracek and qinqon May 21, 2025 08:01
@sourcery-ai
Copy link

sourcery-ai bot commented May 21, 2025

Reviewer's Guide

The PR refactors nmstatectl command invocations to use Go contexts, enabling a default 10-second timeout on Show and paving the way for controllable deadlines across other calls.

File-Level Changes

Change Details Files
Introduce context-aware command execution
  • Change nmstatectlWithInput signature to accept a context and use exec.CommandContext
  • Update nmstatectl wrapper to accept context and delegate to nmstatectlWithInput
  • Switch Set/Commit/Rollback/Statistic/Policy calls to pass context.TODO()
pkg/nmstatectl/nmstatectl.go
Enforce a 10s timeout on Show
  • Wrap Show() in context.WithTimeout(10s) with deferred cancel
  • Pass the timeout-aware context to nmstatectl
pkg/nmstatectl/nmstatectl.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@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 mkowalski for approval. For more information see the Code Review Process.

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

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

@qinqon
Copy link
Member

qinqon commented May 21, 2025

Snyk checks have failed. 114 issues have been found so far.

Icon Severity Issues
Critical 10
High 35
Medium 53
Low 16

security/snyk check is complete. 114 issues have been found. (View Details)

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @mkowalski - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kubevirt-bot
Copy link
Collaborator

@mkowalski: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-nmstate-unit-test 5d94dc4 link true /test pull-kubernetes-nmstate-unit-test
pull-kubernetes-nmstate-e2e-handler-k8s-future 5d94dc4 link false /test pull-kubernetes-nmstate-e2e-handler-k8s-future

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@kubevirt-bot
Copy link
Collaborator

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 22, 2025
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/bug needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants