Skip to content

Commit

Permalink
Do not try to destroy runner vm if it's already deleted
Browse files Browse the repository at this point in the history
Vm can be deleted via UI or respirate might run label again. So if vm is
already deleted, we should not try to delete it. "vm" returns nil, and
fails with "NoMethodError".
  • Loading branch information
enescakir committed Sep 13, 2023
1 parent bb4ef84 commit 9e28223
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions prog/vm/github_runner.rb
Expand Up @@ -184,9 +184,11 @@ def before_run
rescue Octokit::NotFound
end

vm.private_subnets.each { _1.incr_destroy }
vm.sshable.destroy
vm.incr_destroy
if vm
vm.private_subnets.each { _1.incr_destroy }
vm.sshable.destroy
vm.incr_destroy
end

hop_wait_vm_destroy
end
Expand Down
12 changes: 12 additions & 0 deletions spec/prog/vm/github_runner_spec.rb
Expand Up @@ -238,6 +238,18 @@

expect { nx.destroy }.to hop("wait_vm_destroy")
end

it "does not destroy vm if it's already destroyed" do
expect(nx).to receive(:register_deadline)
expect(nx).to receive(:decr_destroy)
expect(client).to receive(:get).and_raise(Octokit::NotFound)
expect(client).not_to receive(:delete)
expect(github_runner).to receive(:vm).and_return(nil)
expect(sshable).not_to receive(:destroy)
expect(vm).not_to receive(:incr_destroy)

expect { nx.destroy }.to hop("wait_vm_destroy")
end
end

describe "#wait_vm_destroy" do
Expand Down

0 comments on commit 9e28223

Please sign in to comment.