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(backup): do not get backing image custom resource #3372

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

mantissahz
Copy link
Contributor

Which issue(s) this PR fixes:

Issue #ref longhorn/longhorn#10026, longhorn/longhorn#6341

What this PR does / why we need it:

Do not get the backing image custom resource if the backup backing image is synchronized from the remote backup target because the backing image might not exist.

Special notes for your reviewer:

Additional documentation or context

@mantissahz mantissahz requested review from ChanYiLin, derekbit and a team December 20, 2024 10:30
@mantissahz mantissahz self-assigned this Dec 20, 2024
Copy link

coderabbitai bot commented Dec 20, 2024

Warning

Rate limit exceeded

@mantissahz has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c4b2597 and 778870f.

📒 Files selected for processing (1)
  • webhook/resources/backupbackingimage/validator.go (1 hunks)

Walkthrough

The pull request introduces modifications to the backup target management system in Longhorn. The changes focus on enhancing the BackupTargetController by adding a new synchronization label, improving error handling, and refining the synchronization process for backup volumes and backing images. A new constant BackupTargetSync is added to types to support this functionality. The webhook validator for backup backing images is also updated to handle synchronization-related checks more robustly.

Changes

File Change Summary
controller/backup_target_controller.go - Added new label types.GetLonghornLabelKey(types.BackupTargetSync) to backup backing image creation
- Enhanced error handling and logging in synchronization methods
- Improved resource lifecycle management
types/types.go - Added new constant BackupTargetSync for backup synchronization labeling
webhook/resources/backupbackingimage/validator.go - Modified Create method to check for synchronization label
- Updated backing image existence check logic

Sequence Diagram

sequenceDiagram
    participant Controller as BackupTargetController
    participant Webhook as BackupBackingImageValidator
    participant Store as BackupStore

    Controller->>Store: Sync Backup Resources
    Controller->>Controller: Add Sync Label
    Controller->>Webhook: Validate Backup Backing Image
    Webhook->>Webhook: Check Sync Label
    Webhook->>Store: Verify Backing Image
    Webhook-->>Controller: Validation Result
Loading

Possibly related PRs

Suggested reviewers

  • derekbit
  • ChanYiLin

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

@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 (2)
webhook/resources/backupbackingimage/validator.go (1)

47-61: Validate both label presence and label content.

Currently, the logic attempts to bypass the backing image existence check if a specific key is found in the Labels map. Consider verifying that the label does not just exist but also equals the expected value (though here it's set to an empty string). For instance, certain misconfigurations might occur if a different label key is used or if the user uses a label with a mismatched value.

types/types.go (1)

141-142: Add a quick note clarifying usage of 'BackupTargetSync'.

The new constant clarifies that objects are brought in from a remote backup target. For maintainability, add a short clarifying comment next to this constant (or in your developer docs) indicating its usage patterns, especially that it is checked in admission webhooks to skip local references.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1b74376 and c4b2597.

📒 Files selected for processing (3)
  • controller/backup_target_controller.go (1 hunks)
  • types/types.go (1 hunks)
  • webhook/resources/backupbackingimage/validator.go (1 hunks)
🔇 Additional comments (1)
controller/backup_target_controller.go (1)

663-665: Ensure backward compatibility when adding the new label.

By introducing the BackupTargetSync label, any existing logic that expects backups to always have a corresponding backing image resource in the cluster now has a condition to bypass it. Confirm that no external controllers or external scripts rely on the presence of backing images for all backup items. Otherwise, you may encounter unexpected issues where those components assume that the backing image always exists.

Would you like me to generate a script that searches for any external references to backing image existence checks?

Comment on lines 47 to 61
// The backup backing image might be created by the backup target controller synchronized from the remote backup target,
// and the backing image might not exist in the local cluster
exists := false
if backupBackingImage.Labels != nil {
_, exists = backupBackingImage.Labels[types.GetLonghornLabelKey(types.BackupTargetSync)]
}
// TODO: support backup for v2 data engine in the future
if types.IsDataEngineV2(backingImage.Spec.DataEngine) {
return werror.NewInvalidError(fmt.Sprintf("backing image %v uses v2 data engine which doesn't support backup operations", backingImageName), "")
if !exists {
backingImage, err := bbi.ds.GetBackingImageRO(backingImageName)
if err != nil {
return werror.NewInvalidError(fmt.Sprintf("failed to get the backing image %v for backup: %v", backingImageName, err), "")
}
// TODO: support backup for v2 data engine in the future
if types.IsDataEngineV2(backingImage.Spec.DataEngine) {
return werror.NewInvalidError(fmt.Sprintf("backing image %v uses v2 data engine which doesn't support backup operations", backingImageName), "")
}
Copy link
Member

@derekbit derekbit Dec 20, 2024

Choose a reason for hiding this comment

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

I think we don't need to validate whether a backing image exists. We can allow users to create v2 backing image but always failed the backup (backupBacking.status.State=error, backupBackingImage.status.Error = "backing up v2 backing image is not supported). Then, we don't need the special label. WDYT?

cc @ChanYiLin

Copy link
Contributor Author

@mantissahz mantissahz Dec 23, 2024

Choose a reason for hiding this comment

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

Removed the label, and ignored the error ErrorIsNotFound. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me

Copy link
Contributor

Choose a reason for hiding this comment

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

After a second thought, I think using webhook is still more simple.
The current change in this PR is also good enough
If the backing image exists in the cluster and it is v2 backing image
then the webhook blocks the backup creation.

If the backing image doesn't exist in the cluster, then the backupbackingimage is pulled from the remote, we allow it.

Copy link
Member

Choose a reason for hiding this comment

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

There are two different behaviors for v2 backup backingimage. Is making them consistent better?

@mantissahz mantissahz requested a review from a team December 23, 2024 02:30
if backup backing image is synchronized from remote backup target
because backing image might not exist.

ref longhorn/longhorn 10026, 6341

Signed-off-by: James Lu <[email protected]>
Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

LGTM

@derekbit derekbit merged commit 6adf428 into longhorn:master Dec 23, 2024
9 checks passed
@mantissahz
Copy link
Contributor Author

@mergify backport v1.8.x

Copy link

mergify bot commented Dec 23, 2024

backport v1.8.x

✅ Backports have been created

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.

3 participants