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 issue where cleanup-stale-apps command fails to delete apps with volumesets #175

Merged
merged 2 commits into from
May 16, 2024

Conversation

rafaelgomesxyz
Copy link
Collaborator

@rafaelgomesxyz rafaelgomesxyz commented May 15, 2024

The cleanup-stale-apps command is currently outdated compared to the delete command, in terms of deleting apps with volumesets.

This PR fixes that by changing the cleanup-stale-apps command to simply call the delete command for each app, instead of implementing its own delete methods. That ensures that whatever changes are made to the delete command are reflected in the cleanup-stale-apps command.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue where the cleanup-stale-apps command failed to delete apps with volumesets.
  • New Features

    • Enhanced the cleanup-stale-apps command to unbind apps from the secrets policy if both identity and policy exist.
    • Improved error messages and notifications for deleting workloads, volumesets, and images to include application context for better clarity.
  • Documentation

    • Updated documentation to reflect new functionalities and improved messages for the cleanup-stale-apps command.

@rafaelgomesxyz rafaelgomesxyz self-assigned this May 15, 2024
Copy link

coderabbitai bot commented May 15, 2024

Walkthrough

The recent update fixes a bug in the cleanup-stale-apps command, which now successfully deletes apps with volumesets. Enhancements include unbinding apps from the secrets policy if applicable and providing more detailed error messages within the deletion context. This ensures comprehensive cleanup of workloads, volumesets, and images, improving overall functionality and user feedback.

Changes

File Change Summary
CHANGELOG.md Documented the bug fix and added a summary of changes.
docs/commands.md Updated cleanup-stale-apps command documentation to reflect new functionality and unbinding policy.
lib/command/cleanup_stale_apps.rb Updated descriptions and replaced methods to include volumeset deletion and unbinding from policy.
lib/command/delete.rb Enhanced error messages and notifications to include application context for various deletions.
spec/command/cleanup_stale_apps_spec.rb Updated tests to reflect changes in template names and added expectations for volumeset deletions.
spec/command/delete_spec.rb Refined error and deletion messages to include specific app names for better context.

🐇✨
In code's vast field, bugs once did roam,
Now apps with sets find a cleaner home.
With policies unbound and errors refined,
A smoother path for all combined.
Cheers to changes, precise and neat,
A rabbit's joy in code complete!
🌟🐰


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

return progress.puts("Workload '#{workload}' does not exist.") if cp.fetch_workload(workload).nil?
if cp.fetch_workload(workload).nil?
return progress.puts("Workload '#{workload}' does not exist in app '#{config.app}'.")
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All changes in this file are simply to add, e.g., " app 'my-app'", at the end of the progress messages, so that it's clear which app each item being deleted belongs to.

end
end
def delete_app(app)
Cpl::Cli.start(["delete", "-a", app, "--yes"])
Copy link
Collaborator Author

@rafaelgomesxyz rafaelgomesxyz May 15, 2024

Choose a reason for hiding this comment

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

Simply call the delete command instead of implementing its own delete methods.

It's ok to pass --yes here because this is only called after confirm_delete:

return unless confirm_delete
progress.puts
stale_apps.each do |app|
delete_app(app[:name])

So the confirmation step will already have been handled by the time we get here.

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

Out of diff range and nitpick comments (2)
lib/command/cleanup_stale_apps.rb (1)

Line range hint 44-61: Refactor long method for readability and maintainability.

Consider breaking down the stale_apps method into smaller, more manageable methods to improve readability and maintainability.

def stale_apps
  @stale_apps ||= begin
    apps = []
    now = DateTime.now
    stale_app_image_deployed_days = config[:stale_app_image_deployed_days]

    gvcs = cp.gvc_query(config.app)["items"]
    gvcs.each do |gvc|
      app_name = gvc["name"]
      image = latest_image_for_app(app_name)
      next unless image

      created_date = DateTime.parse(image["created"])
      diff_in_days = (now - created_date).to_i
      next unless diff_in_days >= stale_app_image_deployed_days

      apps.push({ name: app_name, date: created_date })
    end

    apps
  end
end

private

def latest_image_for_app(app_name)
  images = cp.query_images(app_name)["items"].select { |item| item["name"].start_with?("#{app_name}:") }
  latest_image_from(images, app_name: app_name, name_only: false)
end
CHANGELOG.md (1)

Line range hint 116-116: Correct the operating system name.

The operating system from Apple should be written as "macOS".

- Fixed failed build on MacOS by adding platform flag and fixed multiple files in yaml document for template.
+ Fixed failed build on macOS by adding platform flag and fixed multiple files in yaml document for template.
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 95cd916 and 50930f7.
Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • docs/commands.md (1 hunks)
  • lib/command/cleanup_stale_apps.rb (4 hunks)
  • lib/command/delete.rb (5 hunks)
  • spec/command/cleanup_stale_apps_spec.rb (3 hunks)
  • spec/command/delete_spec.rb (8 hunks)
Files not reviewed due to errors (4)
  • lib/command/delete.rb (no review received)
  • spec/command/cleanup_stale_apps_spec.rb (no review received)
  • spec/command/delete_spec.rb (no review received)
  • docs/commands.md (no review received)
Additional Context Used
LanguageTool (22)
CHANGELOG.md (11)

Near line 21: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [2.0.0] - 2024-05-14 ### BREAKING CHANGES - C...


Near line 51: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.4.0] - 2024-03-20 ### Added - Added new te...


Near line 66: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.3.0] - 2024-03-19 ### Fixed - Fixed issue ...


Near line 88: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.2.0] - 2024-01-03 ### Fixed - Fixed issue ...


Near line 116: The operating system from Apple is written “macOS”.
Context: ...-17 ### Fixed - Fixed failed build on MacOS by adding platform flag and fixed multi...


Near line 134: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.1.0] - 2023-09-20 ### Fixed - Fixed issue ...


Near line 152: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.0.4] - 2023-07-21 ### Fixed - Fixed issue ...


Near line 158: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.0.3] - 2023-07-07 ### Fixed - Fixed run ...


Near line 172: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.0.2] - 2023-07-02 ### Added - Added steps ...


Near line 179: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.0.1] - 2023-06-28 ### Fixed - Fixed `clean...


Near line 189: Unpaired symbol: ‘[’ seems to be missing
Context: ...//github.com/rafaelgomesxyz). ## [1.0.0] - 2023-05-29 - Initial release [Unrel...

docs/commands.md (11)

Near line 56: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...uantity or are older than the specified amount of days - Specify the max quantity thro...


Near line 57: Possible verb agreement error. Did you mean “specifies”? (Some collective nouns can be treated as both singular and plural, so ‘Specify’ is not always incorrect.)
Context: ...der than the specified amount of days - Specify the max quantity through `image_retenti...


Near line 58: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ne/controlplane.ymlfile - Specify the amount of days throughimage_retention_days` ...


Near line 72: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ... date of the latest image - Specify the amount of days after an app should be consider...


Near line 126: The word ‘deploy’ is a verb. Did you mean the noun “deployment” (= release, placement)?
Context: ...f cpl run with the latest image - The deploy will fail if the release script exits w...


Near line 212: This expression is usually spelled with a hyphen.
Context: ... is only supported for domains that use path based routing mode and have a route configure...


Near line 223: This expression is usually spelled with a hyphen.
Context: ... is only supported for domains that use path based routing mode and have a route configure...


Near line 234: This expression is usually spelled with a hyphen.
Context: ... is only supported for domains that use path based routing mode and have a route configure...


Near line 279: The word ‘deploy’ is a verb. Did you mean the noun “deployment” (= release, placement)?
Context: ...he --run-release-phase option - The deploy will fail if the release script exits w...


Near line 358: Unpaired symbol: ‘"’ seems to be missing
Context: ...t is bash, in which case the args ["-c", cmd_to_run] are passed - Providing `--...


Near line 410: Consider replacing ‘only’ with a different word to let your writing stand out.
Context: ...ne/controlplane.yml` file - This should only be used for temporary apps like review ...

Additional comments not posted (1)
lib/command/cleanup_stale_apps.rb (1)

Line range hint 68-72: LGTM! The confirm_delete method is straightforward and does not require changes.

CHANGELOG.md Show resolved Hide resolved
lib/command/cleanup_stale_apps.rb Show resolved Hide resolved
lib/command/cleanup_stale_apps.rb Show resolved Hide resolved
Copy link
Member

@justin808 justin808 left a comment

Choose a reason for hiding this comment

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

LGTM

@justin808 justin808 merged commit 10b06b9 into main May 16, 2024
5 checks passed
@justin808 justin808 deleted the cleanup-stale-apps-volumesets-fix branch May 16, 2024 00:16
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.

2 participants