Skip to content
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

fix: use volume state to check all volumes detached when changing some settings #3490

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

james-munson
Copy link
Contributor

Which issue(s) this PR fixes:

Issue longhorn/longhorn#10233

What this PR does / why we need it:

Revert to checking volume state rather than engine instances when changing some settings.
Rename the engine instance check to reflect what it actually does.

Special notes for your reviewer:

Regression tests for changing settings passed: https://ci.longhorn.io/job/private/job/longhorn-tests-regression/8332/

Additional documentation or context

Copy link

coderabbitai bot commented Jan 17, 2025

Walkthrough

The pull request introduces modifications to the Longhorn system's volume and engine instance state checking mechanisms. The primary change involves shifting from checking engine instances to using volume states for determining whether volumes are detached. This modification addresses potential issues with orphaned engine instances that could incorrectly block settings changes. The changes are implemented across multiple files, including the setting controller, datastore, and system restore validator, ensuring a consistent approach to volume state validation.

Changes

File Change Summary
controller/setting_controller.go Replaced volume detachment checks with volume state checks in multiple methods (syncDangerZoneSettingsForManagedComponents, updateTaintToleration, updatePriorityClass, updateNodeSelector, updateInstanceManagerCPURequest)
datastore/longhorn.go Renamed AreAllVolumesDetached to AreAllEngineInstancesStopped and updated related validation methods
webhook/resources/systemrestore/validator.go Modified Create method to use new volume state checking method

Assessment against linked issues

Objective Addressed Explanation
Use Volume state to determine volume detachment [#10233]
Prevent settings changes when volumes are attached
Address potential issues with orphaned engine instances

Possibly related PRs

Suggested reviewers

  • c3y1huang
  • innobead
  • ChanYiLin
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

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.

Copy link
Contributor

@PhanLe1010 PhanLe1010 left a comment

Choose a reason for hiding this comment

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

In general LGTM.

However, I think that this change should be carefully monitored in the e2e test and negative test. It possible this might introduce regression bug

controller/setting_controller.go Show resolved Hide resolved
@PhanLe1010
Copy link
Contributor

Will defer to @derekbit to take a look first

@derekbit derekbit force-pushed the 10233-volumes-detached branch from 58a62ec to cbb72cd Compare January 31, 2025 09:55
@derekbit
Copy link
Member

@james-munson LGTM. Could you run full regression and e2e test before merging it? Thanks.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
datastore/longhorn.go (1)

Line range hint 397-597: Consider standardizing the volume detachment check approach

The codebase currently has a mix of approaches for checking volume detachment:

  1. Engine instance-based checks via AreAllEngineInstancesStopped
  2. Volume state-based checks via AreAllVolumesDetachedState

Consider:

  • Standardizing on the volume state-based approach as per PR objectives
  • Updating ValidateV1DataEngineEnabled and ValidateV2DataEngineEnabled to use AreAllVolumesDetachedState
  • Adding documentation explaining the rationale for the chosen approach
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58a62ec and cbb72cd.

📒 Files selected for processing (3)
  • controller/setting_controller.go (5 hunks)
  • datastore/longhorn.go (3 hunks)
  • webhook/resources/systemrestore/validator.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • webhook/resources/systemrestore/validator.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (6)
controller/setting_controller.go (4)

Line range hint 303-315: LGTM! Clean implementation of volume state check.

The change to use AreAllVolumesDetachedState() for storage network setting updates is well-implemented with proper error handling and clear error messages.


Line range hint 425-431: LGTM! Consistent implementation of volume state check.

The change to use AreAllVolumesDetachedState() for taint toleration updates maintains consistency with other setting updates and includes proper error handling.


Line range hint 596-602: LGTM! Consistent implementation of volume state check.

The change to use AreAllVolumesDetachedState() for priority class updates follows the same pattern, maintaining code consistency.


1261-1266: LGTM! Appropriate use of engine instance check.

Keeping AreAllEngineInstancesStopped() for instance manager CPU request updates is correct since this setting specifically deals with engine instances rather than volume states.

Let's verify this decision with the following script:

✅ Verification successful

Verification confirms appropriate use of engine instance check

The usage of AreAllEngineInstancesStopped() is correctly implemented for both instance manager CPU settings and data engine enablement settings, as these configurations directly impact engine instances and require them to be stopped before applying changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage context of AreAllEngineInstancesStopped
# Expected: This method should only be used for engine-specific operations

# Search for all usages of AreAllEngineInstancesStopped
rg -A 5 "AreAllEngineInstancesStopped"

# Search for any related engine instance management code
ast-grep --pattern 'func $_($_) {
  $$$
  AreAllEngineInstancesStopped($$$)
  $$$
}'

Length of output: 1867


Script:

#!/bin/bash
# Search for setting names and their context
rg -B 2 -A 2 "SettingNameV[12]DataEngine"

# Search for setting definitions
rg "const.*SettingName.*DataEngine.*=" 

# Search for the specific setting update in setting controller
ast-grep --pattern 'func ($_ *SettingController) $_($_) {
  $$$
  AreAllEngineInstancesStopped($$$)
  $$$
}'

Length of output: 27415

datastore/longhorn.go (2)

Line range hint 537-567: LGTM! Well-structured implementation for checking engine instances

The function properly handles both engine and all-in-one instance managers, with appropriate error handling and clear logic for determining if instances are stopped.


Line range hint 584-597: LGTM! Clean implementation for checking volume states

The function provides a straightforward way to check if all volumes are detached by directly checking their states, which aligns with the PR objectives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants