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

Delete workloads before volumesets on GVC deletion #245

Merged
merged 2 commits into from
Nov 30, 2024

Conversation

zzaakiirr
Copy link
Contributor

@zzaakiirr zzaakiirr commented Nov 25, 2024

What does this PR do?

This PR fixes issue where GVC deletion fails because one of the workloads has volumeset in-use - added deletion of workloads before deletion of volumesets

Steps to reproduce issue

  1. Create GVC
  2. Create volumeset in GVC
  3. Create workload which uses volumeset (created in step 2)
  4. Run cpflow delete -a <GVC_NAME>

Expected behaviour

All volumesets, workloads, identities and images and GVC are deleted

Actual behaviour

Error This volume set is in use by a workload and cannot be deleted appears

Why does this error appears?

See #245 (comment)

Summary by CodeRabbit

  • Bug Fixes

    • Resolved issue preventing deletion of GVCs with in-use volumes.
  • Documentation

    • Updated changelog to reflect recent fixes and contributions.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue preventing the deletion of applications linked to workloads with active volumes.
    • Fixed a failure in the run command related to environment variables in runner workloads.
    • Addressed a potential infinite loop during command execution if an execution step fails.
  • Documentation

    • Updated the changelog to reflect the latest fixes and contributions, enhancing clarity for users.

Copy link

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes involve updates to the CHANGELOG.md file and modifications to the Delete class within the Command module. The CHANGELOG.md now includes a new entry documenting a fix for an issue where an application could not be deleted if one of the workloads had a volume set in use. In the Delete class, the delete_volumesets method has been enhanced to retrieve and delete all workloads linked to a volumeset, improving the deletion process's robustness. Comments in the method have also been updated for clarity.

Changes

File Change Summary
CHANGELOG.md Added new entry under Unreleased for fixing application deletion issue; retained existing fixed issues.
lib/command/delete.rb Updated delete_volumesets method to handle multiple workloads linked to a volumeset; updated comments.

Poem

In the meadow where clusters grow,
A fix was found, and now we know,
Workloads linked, no longer a fright,
Deleting them all, a joyful sight!
Hops of joy, our code's in tune,
Thanks to Zakir, we sing a tune! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec0c7a4 and ee4a6df.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • lib/command/delete.rb (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/command/delete.rb
  • CHANGELOG.md

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.

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.

@zzaakiirr
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Nov 25, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 1

🧹 Outside diff range and nitpick comments (3)
spec/command/delete_spec.rb (1)

80-84: LGTM! Proper verification of deletion order.

The expectations correctly verify that workloads are deleted before volumesets, which addresses the core issue. However, consider adding a specific test case that verifies the failure scenario when attempting to delete volumesets before workloads.

Consider adding a test like this:

it "fails when trying to delete volumesets before workloads" do
  # Mock the API to simulate attempting volumeset deletion first
  allow(API::Volumeset).to receive(:delete).and_raise("Volumeset in use by workload")
  
  result = run_cpflow_command("delete", "-a", app, "--volumeset", "postgres-volume", "--yes")
  
  expect(result[:status]).not_to eq(0)
  expect(result[:stderr]).to include("Cannot delete volumeset 'postgres-volume' as it is in use by workload")
end
lib/command/delete.rb (2)

126-128: Ensure @workloads is initialized before use in delete_workloads

The method delete_workloads relies on @workloads being initialized in check_workloads. To avoid potential errors, ensure that delete_workloads is only called after check_workloads, or initialize @workloads to an empty array by default.


Line range hint 134-140: Remove redundant workload deletion in delete_volumesets

Since workloads are now deleted before volumesets in delete_gvc_items, the code in delete_volumesets that deletes workloads if they are attached to volumesets is redundant. Removing this code avoids unnecessary deletion attempts.

Apply this diff to remove the redundant code:

 def delete_volumesets
   @volumesets.each do |volumeset|
     step("Deleting volumeset '#{volumeset['name']}' from app '#{config.app}'") do
-      # If the volumeset is attached to a workload, we need to delete the workload first
-      workload = volumeset.dig("status", "usedByWorkload")&.split("/")&.last
-      cp.delete_workload(workload) if workload

       cp.delete_volumeset(volumeset["name"])
     end
   end
 end
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4c4f5ea and b40a289.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • lib/command/delete.rb (2 hunks)
  • spec/command/delete_spec.rb (4 hunks)
🔇 Additional comments (6)
spec/command/delete_spec.rb (3)

35-38: LGTM! Comprehensive message verification.

The expectations properly verify that appropriate messages are displayed when no resources (workloads, volumesets, images) exist in the app.


48-51: LGTM! Consistent message verification in confirmation context.

The expectations maintain consistency with other scenarios while verifying the confirmation flow.


61-64: LGTM! Consistent message verification in skip confirmation context.

The expectations maintain consistency across all deletion scenarios while verifying the skip confirmation flow.

CHANGELOG.md (1)

23-24: LGTM! The changelog entry is well-formatted and descriptive.

The entry clearly documents the fix for the GVC deletion issue when workloads have volumesets in use, following the established changelog format and properly crediting the contributor.

lib/command/delete.rb (2)

54-61: Refactored delete_whole_app method enhances clarity and maintainability

The introduction of check_gvc_items and delete_gvc_items methods in delete_whole_app improves code organization by separating concerns. This refactoring enhances readability and makes the deletion process more modular.


63-68: Good use of check_gvc_items to consolidate checks

The check_gvc_items method effectively groups the pre-deletion checks for workloads, volumesets, and images, promoting code reuse and maintainability.

lib/command/delete.rb Outdated Show resolved Hide resolved
@zzaakiirr zzaakiirr marked this pull request as ready for review November 25, 2024 10:02
@dzirtusss
Copy link
Collaborator

image

Can we look for force option in api/cli? This will guarantee deletion.

@zzaakiirr
Copy link
Contributor Author

@dzirtusss

Can we look for force option in api/cli? This will guarantee deletion.

There is no force option in API docs:
image

But there is --force option in cpln cli:
Screenshot 2024-11-26 at 13 02 30

Current implementation of cpflow delete logic relies on API requests - I think it's possible to leave gathering info about items that will be deleted via API and replace API DELETE requests with cpln gvc delete <ref> --force command if whole app needs to deleted.

Should we take advantage of this command i/o multiple API DELETE requests? @dzirtusss @rafaelgomesxyz @dzirtusss WDYT?

@rafaelgomesxyz
Copy link
Collaborator

@zzaakiirr I'm confused. I had already fixed this issue:

image

It checks if a volumeset is attached to a workload and deletes it first.

Why is it not working?

@rafaelgomesxyz rafaelgomesxyz added the question Further information is requested label Nov 26, 2024
@rafaelgomesxyz
Copy link
Collaborator

rafaelgomesxyz commented Nov 26, 2024

@zzaakiirr @dzirtusss By the way, I'd prefer if we rely more on the API than the CLI, because we can run into versioning issues with the CLI, while that's not the case for the API.

@zzaakiirr
Copy link
Contributor Author

@zzaakiirr I'm confused. I had already fixed this issue:

image

It checks if a volumeset is attached to a workload and deletes it first.

Why is it not working?

Sorry, I missed that. Maybe API response changed? I don't seee status -> usedByWorkload in response, only status -> workloadLinks:
image

If so, we can fix only this part:
image

OR we can leave current implementation and remove workload deletion logic from #delete_volumesets - this way user can see which workloads will be removed but execution will take longer since we always will be removing all workloads.

@rafaelgomesxyz WDYT?

@rafaelgomesxyz
Copy link
Collaborator

@zzaakiirr It's more efficient to only delete workloads that are using a volumeset, so I'd do it that way.

Copy link
Collaborator

@rafaelgomesxyz rafaelgomesxyz left a comment

Choose a reason for hiding this comment

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

Let's just fix the method we had before instead of deleting all workloads, which takes more time and is less efficient.

I do wonder why the specs weren't failing though, if the API changed. Or maybe they were and we didn't catch it?

@rafaelgomesxyz rafaelgomesxyz added changes requested and removed question Further information is requested review needed labels Nov 26, 2024
@zzaakiirr zzaakiirr force-pushed the fix-volumeset-cannot-be-deleted-error-on-gvc-deletion branch from b40a289 to ec0c7a4 Compare November 27, 2024 08:23
@zzaakiirr
Copy link
Contributor Author

@rafaelgomesxyz

Let's just fix the method we had before instead of deleting all workloads, which takes more time and is less efficient.

Done

I do wonder why the specs weren't failing though, if the API changed. Or maybe they were and we didn't catch it?

The test that should have detected error is marked with :slow label - spec/command/delete_spec.rb:73.
We weren't getting an error because CI for PRs run only fast specs. Justin recently ran all tests for main branch and ended up with GVCs limit error

Copy link
Collaborator

@rafaelgomesxyz rafaelgomesxyz left a comment

Choose a reason for hiding this comment

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

LGTM. Left just a couple minor suggestions, if you could do those before merging.

lib/command/delete.rb Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@zzaakiirr zzaakiirr merged commit f8b544d into main Nov 30, 2024
5 checks passed
@zzaakiirr zzaakiirr deleted the fix-volumeset-cannot-be-deleted-error-on-gvc-deletion branch November 30, 2024 08:40
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.

3 participants