Skip to content

Support negative minHealthy to easily express N-1, N-2 scenarios #371

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

Closed
wants to merge 1 commit into from

Conversation

tiraboschi
Copy link
Contributor

@tiraboschi tiraboschi commented Jun 24, 2025

Why we need this PR

The minHealthy parameter already allows cluster admins to prevent NHC from remediating too many nodes at once, protecting overall compute capacity.

However, expressing N-1 or N-2 scenarios, where only one or two nodes should be remediated at a time,
currently requires knowing the exact number of nodes in advance and updating the configuration as nodes are added.

This change introduces support for negative minHealthy values, which are interpreted as
total number of selected nodes minus the provided value.

For example, -1 means ll but one node must remain healthy.

Changes made

This change:

  • Does not introduce a new API, ensuring full backward compatibility and avoiding ambiguity.
  • Only alters the logic used to compute the absolute minHealthy value (similar to how percentages are handled).
  • Keeps the internal processing and validation unchanged.

Which issue(s) this PR fixes

Fixes https://issues.redhat.com/browse/RHWA-88

Test plan

  • Existing Unit and E2E tests are passing
  • New unit test to ensure that negative values for minHealthy are properly handled

Summary by CodeRabbit

  • New Features

    • Added support for specifying negative values (integers and percentages) for minimum healthy nodes in NodeHealthCheck resources, enabling flexible thresholds like N-1 or N-2.
  • Documentation

    • Clarified acceptance and interpretation of negative values for minimum healthy nodes with updated descriptions and examples in user guides and configuration references.
  • Bug Fixes

    • Adjusted validation and reconciliation logic to correctly accept and process negative values for minimum healthy nodes.
  • Tests

    • Expanded test coverage to ensure correct handling of negative values for minimum healthy nodes.

@openshift-ci openshift-ci bot requested review from clobrano and slintes June 24, 2025 14:01
Copy link
Contributor

openshift-ci bot commented Jun 24, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tiraboschi
Once this PR has been reviewed and has the lgtm label, please assign razo7 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

Copy link
Contributor

openshift-ci bot commented Jun 24, 2025

Hi @tiraboschi. Thanks for your PR.

I'm waiting for a medik8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

Copy link

coderabbitai bot commented Jun 24, 2025

Walkthrough

The changes introduce support for negative values in the MinHealthy field of the NodeHealthCheck resource, allowing both negative integers and percentages. Documentation, CRD schemas, validation logic, and tests were updated to clarify and implement the new behavior, enabling thresholds like N-1 or N-2 for healthy nodes without knowing the total node count in advance.

Changes

File(s) Change Summary
README.md, docs/configuration.md Updated documentation to clarify MinHealthy supports negative integers/percentages and explain new threshold logic.
api/v1alpha1/nodehealthcheck_types.go Updated MinHealthy field docs and regex to allow negative values; expanded comments with examples.
api/v1alpha1/nodehealthcheck_webhook.go, api/v1alpha1/nodehealthcheck_webhook_test.go Removed validation rejecting negative MinHealthy; updated tests to expect acceptance of negative values.
controllers/nodehealthcheck_controller.go Introduced getAbsoluteMinHealthy helper to interpret negative values; updated reconciliation logic accordingly.
controllers/nodehealthcheck_controller_test.go Added/updated tests for negative MinHealthy values and for getAbsoluteMinHealthy function.
e2e/nhc_e2e_test.go Changed tests to initialize and accept negative MinHealthy values.
bundle/manifests/node-healthcheck-operator.clusterserviceversion.yaml,
config/manifests/base/bases/node-healthcheck-operator.clusterserviceversion.yaml,
bundle/manifests/remediation.medik8s.io_nodehealthchecks.yaml,
config/crd/bases/remediation.medik8s.io_nodehealthchecks.yaml
Expanded CRD/spec descriptions and regex patterns to allow and explain negative values for MinHealthy.
api/v1alpha1/zz_generated.deepcopy.go Removed unused import alias; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API Server
    participant NodeHealthCheck Controller

    User->>API Server: Create/Update NodeHealthCheck (MinHealthy: -1)
    API Server->>NodeHealthCheck Controller: Reconcile event
    NodeHealthCheck Controller->>NodeHealthCheck Controller: getAbsoluteMinHealthy(MinHealthy, totalNodes)
    NodeHealthCheck Controller->>NodeHealthCheck Controller: Calculate threshold (totalNodes + MinHealthy)
    NodeHealthCheck Controller-->>API Server: Update status/remediation as needed
Loading

Poem

A rabbit hops through code so neat,
Now MinHealthy’s got a clever feat!
With minus signs, it counts with glee—
N-1, N-2, as easy as can be.
Docs and tests all join the dance,
For NodeHealthCheck, it’s a leap in advance!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5193b4 and 048346d.

📒 Files selected for processing (13)
  • README.md (1 hunks)
  • api/v1alpha1/nodehealthcheck_types.go (1 hunks)
  • api/v1alpha1/nodehealthcheck_webhook.go (0 hunks)
  • api/v1alpha1/nodehealthcheck_webhook_test.go (1 hunks)
  • api/v1alpha1/zz_generated.deepcopy.go (1 hunks)
  • bundle/manifests/node-healthcheck-operator.clusterserviceversion.yaml (1 hunks)
  • bundle/manifests/remediation.medik8s.io_nodehealthchecks.yaml (1 hunks)
  • config/crd/bases/remediation.medik8s.io_nodehealthchecks.yaml (1 hunks)
  • config/manifests/base/bases/node-healthcheck-operator.clusterserviceversion.yaml (1 hunks)
  • controllers/nodehealthcheck_controller.go (2 hunks)
  • controllers/nodehealthcheck_controller_test.go (3 hunks)
  • docs/configuration.md (1 hunks)
  • e2e/nhc_e2e_test.go (2 hunks)
💤 Files with no reviewable changes (1)
  • api/v1alpha1/nodehealthcheck_webhook.go
✅ Files skipped from review due to trivial changes (1)
  • api/v1alpha1/zz_generated.deepcopy.go
🚧 Files skipped from review as they are similar to previous changes (11)
  • api/v1alpha1/nodehealthcheck_webhook_test.go
  • docs/configuration.md
  • README.md
  • e2e/nhc_e2e_test.go
  • bundle/manifests/remediation.medik8s.io_nodehealthchecks.yaml
  • config/manifests/base/bases/node-healthcheck-operator.clusterserviceversion.yaml
  • config/crd/bases/remediation.medik8s.io_nodehealthchecks.yaml
  • controllers/nodehealthcheck_controller.go
  • bundle/manifests/node-healthcheck-operator.clusterserviceversion.yaml
  • api/v1alpha1/nodehealthcheck_types.go
  • controllers/nodehealthcheck_controller_test.go
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

The minHealthy parameter already allows cluster admins
to prevent NHC from remediating too many nodes at once,
protecting overall compute capacity.

However, expressing N-1 or N-2 scenarios, where only
one or two nodes should be remediated at a time,
currently requires knowing the exact number of nodes
in advance and updating the configuration as nodes are added.

This change introduces support for negative minHealthy values,
which are interpreted as
"total number of selected nodes minus the provided value".

For example, -1 means "all but one node must remain healthy".

This change:
- Does not introduce a new API,
  ensuring full backward compatibility and avoiding ambiguity.
- Only alters the logic used to compute the absolute
  minHealthy value (similar to how percentages are handled).
- Keeps the internal processing and validation unchanged.

Signed-off-by: Simone Tiraboschi <[email protected]>
@tiraboschi tiraboschi force-pushed the negative_minHealthy branch from d5193b4 to 048346d Compare June 25, 2025 19:55
@@ -60,7 +60,10 @@ Remediation is not always the correct response to a failure. Especially in
larger clusters, we want to protect against failures that appear to take out
large portions of compute capacity but are really the result of failures on or
near the control plane. For this reason, the NHC CR includes the ability to
define a minimum number of healthy nodes, by percentage or absolute number.
define a minimum number of healthy nodes, by percentage or integer number.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the explanation given in the type definition looks clearer. Could we have something similar also here?

absMinHealthy = total + minHealthy
}
if absMinHealthy < 0 {
err = fmt.Errorf("absolute minHealthy is negative: %d", absMinHealthy)
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, the error message isn't catching completely the problem, unless you know the code, which is that the total number of selected Node is lower than the nodes we want to keep healthy, isn't it?

8,
nil,
),
Entry("positive percentage value with round-up",
Copy link
Contributor

Choose a reason for hiding this comment

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

Great tests 👍

@tiraboschi
Copy link
Contributor Author

closing in favor of #372 that got a wider consensus

@tiraboschi tiraboschi closed this Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants