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

feat: allow v2 volume to attach on the an old and running instance-manager pod #3198

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

Conversation

derekbit
Copy link
Member

@derekbit derekbit commented Oct 8, 2024

Which issue(s) this PR fixes:

Issue longhorn/longhorn#9383

What this PR does / why we need it:

Special notes for your reviewer:

Additional documentation or context

@derekbit derekbit self-assigned this Oct 8, 2024
@derekbit derekbit force-pushed the issue-9383 branch 2 times, most recently from d02f825 to a3d569a Compare October 16, 2024 02:30
Copy link

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes in this pull request primarily enhance the functionality and error handling of the DataStore and volumeMutator components within the Longhorn project. Key modifications include updates to existing methods to improve instance manager retrieval based on image specifications, the introduction of new methods to check instance manager states, and adjustments to the logic for creating default nodes and managing data engines. These changes aim to ensure better management of Longhorn resources and improve the robustness of operations related to instance managers and volumes.

Changes

File Change Summary
datastore/longhorn.go - Updated GetInstanceManagerByInstanceRO and GetInstanceManagerByInstance to handle image variable.
- Enhanced error messages in GetInstanceManagerByInstanceRO.
- Modified CreateDefaultNode to check user settings before creating disks.
- Updated GetReadyNodeDiskForBackingImage for additional checks.
- Added GetDataEngines method for retrieving enabled data engines.
- Refined labeling methods for consistency.
- Enhanced validation logic for recurring jobs.
webhook/resources/volume/mutator.go - Added areAllDefaultInstanceManagersStopped to check if all instance managers are stopped.
- Added getActiveInstanceManagerImage to determine the active instance manager image.
- Updated Create method to utilize getActiveInstanceManagerImage for image mutation logic.

Assessment against linked issues

Objective Addressed Explanation
Support operations on old and running instance-manager pods for restored volumes (Issue #9383)
Allow v2 volume live upgrade without detaching before Longhorn upgrade (Issue #9383) Changes do not explicitly address live upgrade needs.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e7db6e7 and c215fb8.

📒 Files selected for processing (2)
  • datastore/longhorn.go (2 hunks)
  • webhook/resources/volume/mutator.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (8)
webhook/resources/volume/mutator.go (3)

49-61: Code for areAllDefaultInstanceManagersStopped looks good

The function correctly checks if all default instance managers are stopped by iterating through them and verifying their current state.


211-218: Correctly updating the default image for V2 data engine volumes

The logic in the Create method properly updates the defaultImage based on the active instance manager image for V2 data engine volumes. This ensures that the volume uses the correct image during creation.


63-86: ⚠️ Potential issue

Handle the case when no active instance manager image is found

In the getActiveInstanceManagerImage function, if all default instance managers are stopped and there are no instance managers with a different image, the function returns the defaultInstanceManagerImage. If the intention is to find an active instance manager image different from the default when all defaults are stopped, consider handling the scenario where none is found.

Apply this diff to handle the case:

 for _, im := range ims {
     if im.Spec.Image != defaultInstanceManagerImage {
         return im.Spec.Image, nil
     }
 }
+// If no instance manager with a different image is found, return an error
+return "", errors.New("no active instance manager image found different from the default")

Alternatively, confirm that returning the default image in this case aligns with the expected behavior.

datastore/longhorn.go (5)

3755-3755: Variable 'image' declared to hold the instance image

The variable image is properly declared to store the image specification from the Engine or Replica objects.


3763-3763: Assigning 'image' from obj.Spec.Image

The image variable correctly retrieves the image specification from both Engine and Replica objects.

Also applies to: 3768-3768


3776-3776: Fetching default instance manager image

The code accurately retrieves the default instance manager image using GetSettingValueExisted.


3781-3785: Properly overriding instance manager image for V2 data engine

When the data engine is V2, the code correctly sets instanceManagerImage to the object's image, ensuring the correct instance manager image is used for instance manager selection.


Line range hint 3787-3798: Ensuring only one instance manager is present per criteria

The code assumes that exactly one instance manager will match the given node, image, type, and data engine. This is acceptable if the system guarantees that only one instance manager exists per these parameters. Please ensure that this assumption holds true in all deployment scenarios.


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 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.

@derekbit
Copy link
Member Author

cc @c3y1huang @ChanYiLin @shuo-wu @innobead ready to go.

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.

1 participant