Skip to content

Commit

Permalink
Delete workloads before volumesets on GVC deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
zzaakiirr committed Nov 25, 2024
1 parent 692d032 commit b40a289
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ _Please add entries here for your pull requests that have not yet been released.

- Fixed potential infinite loop that could occur for a command if one of the execution steps fails and gets stuck. [PR 217](https://github.com/shakacode/control-plane-flow/pull/217) by [Zakir Dzhamaliddinov](https://github.com/zzaakiirr).

- Fixed issue where GVC cannot be deleted because one of the workloads has volumeset in-use. [PR 245](https://github.com/shakacode/control-plane-flow/pull/245) by [Zakir Dzhamaliddinov](https://github.com/zzaakiirr).


## [4.0.0] - 2024-08-21

### Fixed
Expand Down
28 changes: 26 additions & 2 deletions lib/command/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,37 @@ def delete_single_workload(workload)
def delete_whole_app
return progress.puts("App '#{config.app}' does not exist.") if cp.fetch_gvc.nil?

check_volumesets
check_images
check_gvc_items
return unless confirm_delete(config.app)

run_pre_deletion_hook unless config.options[:skip_pre_deletion_hook]
unbind_identity_from_policy

delete_gvc_items
end

def check_gvc_items
check_workloads
check_volumesets
check_images
end

def delete_gvc_items
delete_workloads
delete_volumesets
delete_gvc
delete_images
end

def check_workloads
@workloads = cp.fetch_workloads["items"]
return progress.puts("No workloads to delete from app '#{config.app}'.") unless @workloads.any?

message = "The following workloads will be deleted along with the app '#{config.app}':"
workloads_list = @workloads.map { |workload| "- #{workload['name']}" }.join("\n")
progress.puts("#{Shell.color(message, :red)}\n#{workloads_list}\n\n")
end

def check_volumesets
@volumesets = cp.fetch_volumesets["items"]
return progress.puts("No volumesets to delete from app '#{config.app}'.") unless @volumesets.any?
Expand Down Expand Up @@ -103,6 +123,10 @@ def delete_workload(workload)
end
end

def delete_workloads
@workloads.each { |workload| delete_workload(workload["name"]) }
end

def delete_volumesets
@volumesets.each do |volumeset|
step("Deleting volumeset '#{volumeset['name']}' from app '#{config.app}'") do
Expand Down
5 changes: 5 additions & 0 deletions spec/command/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

expect(Shell).to have_received(:confirm).once
expect(result[:status]).to eq(0)
expect(result[:stderr]).to include("No workloads to delete from app '#{app}'")
expect(result[:stderr]).to include("No volumesets to delete from app '#{app}'")
expect(result[:stderr]).to include("No images to delete from app '#{app}'")
expect(result[:stderr]).not_to include("Deleting app")
Expand All @@ -44,6 +45,7 @@

expect(Shell).to have_received(:confirm).once
expect(result[:status]).to eq(0)
expect(result[:stderr]).to include("No workloads to delete from app '#{app}'")
expect(result[:stderr]).to include("No volumesets to delete from app '#{app}'")
expect(result[:stderr]).to include("No images to delete from app '#{app}'")
expect(result[:stderr]).to match(/Deleting app '#{app}'[.]+? done!/)
Expand All @@ -56,6 +58,7 @@

expect(Shell).not_to have_received(:confirm)
expect(result[:status]).to eq(0)
expect(result[:stderr]).to include("No workloads to delete from app '#{app}'")
expect(result[:stderr]).to include("No volumesets to delete from app '#{app}'")
expect(result[:stderr]).to include("No images to delete from app '#{app}'")
expect(result[:stderr]).to match(/Deleting app '#{app}'[.]+? done!/)
Expand All @@ -74,6 +77,8 @@
result = run_cpflow_command("delete", "-a", app, "--yes")

expect(result[:status]).to eq(0)
expect(result[:stderr]).to match(/Deleting workload 'postgres' from app '#{app}'[.]+? done!/)
expect(result[:stderr]).to match(/Deleting workload 'rails' from app '#{app}'[.]+? done!/)
expect(result[:stderr]).to match(/Deleting volumeset 'detached-volume' from app '#{app}'[.]+? done!/)
expect(result[:stderr]).to match(/Deleting volumeset 'postgres-volume' from app '#{app}'[.]+? done!/)
expect(result[:stderr]).to match(/Deleting app '#{app}'[.]+? done!/)
Expand Down

0 comments on commit b40a289

Please sign in to comment.