Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit d882d3b

Browse files
Aakash Shahsethboyles
andcommitted
Update KpackClient#delete_image to be Idempotent
[#171900207] Co-authored-by: Aakash Shah <ashah@pivotal.io> Co-authored-by: Seth Boyles <sboyles@pivotal.io>
1 parent beddea9 commit d882d3b

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/kubernetes/kpack_client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def update_image(*args)
2828

2929
def delete_image(name, namespace)
3030
@client.delete_image(name, namespace)
31+
rescue Kubeclient::ResourceNotFoundError
32+
nil
3133
rescue Kubeclient::HttpError => e
3234
raise CloudController::Errors::ApiError.new_from_details('KpackImageError', 'delete', e.message)
3335
end

spec/unit/lib/kubernetes/kpack_client_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@
102102
subject.delete_image('resource-name', 'namespace')
103103
}.to raise_error(CloudController::Errors::ApiError)
104104
end
105+
106+
context 'when the image is not present' do
107+
it 'returns nil' do
108+
allow(kube_client).to receive(:delete_image).with('name', 'namespace').and_raise(Kubeclient::ResourceNotFoundError.new(404, 'images not found', '{"kind": "Status"}'))
109+
110+
image = subject.delete_image('name', 'namespace')
111+
expect(image).to be_nil
112+
end
113+
end
105114
end
106115
end
107116
end

0 commit comments

Comments
 (0)