Skip to content

Commit

Permalink
Stop and delete the cluster in a single plan call
Browse files Browse the repository at this point in the history
Closes #9
  • Loading branch information
jay7x committed Jun 2, 2024
1 parent b48cfbd commit acc87e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
7 changes: 7 additions & 0 deletions plans/cluster/delete.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# @summary Delete the cluster of Lima VMs
# @param name
# Cluster name
# @param stop
# Stop the cluster before deleting
# @param force
# Forcibly stop the processes
# @param clusters
Expand All @@ -9,6 +11,7 @@
# The host to run the limactl on
plan lima::cluster::delete (
String[1] $name,
Boolean $stop = false,
Boolean $force = false,
Optional[Hash] $clusters = undef,
TargetSpec $target = 'localhost',
Expand All @@ -26,6 +29,10 @@
}
out::verbose("Nodes to delete: ${defined_nodes}")

if $stop {
run_plan('lima::cluster::stop', name => $name, force => $force, clusters => $clusters, target => $target)
}

return run_task('lima::delete', $target, {
names => $defined_nodes,
force => $force,
Expand Down
25 changes: 20 additions & 5 deletions spec/plans/cluster/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
}
end
let(:cluster_name) { 'example' }
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters } }
let(:force) { false }
let(:force) { nil }
let(:stop) { nil }
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters, 'stop' => stop, 'force' => force } }

context 'with non-existent cluster' do
let(:cluster_name) { 'nonexistent' }
Expand All @@ -46,11 +47,12 @@
context 'with existing cluster' do
before :each do
expect_plan('lima::clusters').always_return(clusters[cluster_name])
expect_task('lima::delete').be_called_times(1).with_params('names' => nodes, 'force' => force).always_return(delete: true)
expect_task('lima::delete').be_called_times(1).with_params('names' => nodes, 'force' => force ? true : false).always_return(delete: true)
expect_out_verbose.with_params("Nodes to delete: [#{nodes.join(', ')}]")
expect_plan('lima::cluster::stop').be_called_times(0)
end

context 'with force unset' do
context 'with default params' do
it 'deletes all nodes in the cluster' do
result = run_plan(plan, plan_params)

Expand All @@ -62,7 +64,6 @@

context 'with force => true' do
let(:force) { true }
let(:plan_params) { super().merge('force' => force) }

it 'deletes all nodes in the cluster' do
result = run_plan(plan, plan_params)
Expand All @@ -72,5 +73,19 @@
expect(result.value[0].value).to eq('delete' => true)
end
end

context 'with stop => true' do
let(:stop) { true }

it 'deletes all nodes in the cluster' do
expect_plan('lima::cluster::stop').be_called_times(1)

result = run_plan(plan, plan_params)

expect(result.ok?).to be(true)
expect(result.value.count).to eq(1)
expect(result.value[0].value).to eq('delete' => true)
end
end
end
end

0 comments on commit acc87e2

Please sign in to comment.