Skip to content

Commit

Permalink
remove deprecated KubeException
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Nov 20, 2017
1 parent 8c99aea commit 785d382
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def update_secret(namespace)
def secret_exist?(secret)
@cluster.client.get_secret(secret.fetch(:metadata).fetch(:name), secret.fetch(:metadata).fetch(:namespace))
true
rescue KubeException
rescue Kubeclient::HttpError
false
end
end
4 changes: 2 additions & 2 deletions plugins/kubernetes/app/models/kubernetes/api/pod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def containers
# tries to get logs from current or previous pod depending on if it restarted
def logs(container, end_time)
fetch_logs(container, end_time, previous: restarted?)
rescue KubeException # not found or pod is initializing
rescue Kubeclient::HttpError # not found or pod is initializing
begin
fetch_logs(container, end_time, previous: !restarted?)
rescue KubeException
rescue Kubeclient::HttpError
nil
end
end
Expand Down
4 changes: 2 additions & 2 deletions plugins/kubernetes/app/models/kubernetes/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def namespaces

def namespace_exists?(namespace)
connection_valid? && namespaces.include?(namespace)
rescue KubeException
rescue Kubeclient::HttpError
false
end

Expand All @@ -63,7 +63,7 @@ def schedulable_nodes

def connection_valid?
client.api_valid?
rescue KubeException, Errno::ECONNREFUSED
rescue Kubeclient::HttpError, Errno::ECONNREFUSED
false
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def pod_statuses(release, release_docs)
# efficient pod fetching by querying once per cluster instead of once per deploy group
def fetch_pods(release)
release.clients.flat_map do |client, query|
pods = Vault.with_retries(KubeException, attempts: 3) { client.get_pods(query) }
pods = Vault.with_retries(Kubeclient::HttpError, attempts: 3) { client.get_pods(query) }
pods.map! { |p| Kubernetes::Api::Pod.new(p, client: client) }
end
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/kubernetes/app/models/kubernetes/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def update
def fetch_resource
reply = request(:get, name, namespace, as: :raw)
JSON.parse(reply, symbolize_names: true)
rescue KubeException => e
rescue Kubeclient::HttpError => e
raise e unless e.error_code == 404
nil
end
Expand Down
6 changes: 3 additions & 3 deletions plugins/kubernetes/test/models/kubernetes/api/pod_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,17 @@

it "fetches previous logs when current logs are not available" do
stub_request(:get, "#{log_url}&follow=true").
to_raise(KubeException.new('a', 'b', 'c'))
to_raise(Kubeclient::HttpError.new('a', 'b', 'c'))
stub_request(:get, "#{log_url}&previous=true").
and_return(body: "HELLO")
pod_with_client.logs('some-container', 10.seconds.from_now).must_equal "HELLO"
end

it "does not crash when both log endpoints fails with a 404" do
stub_request(:get, "#{log_url}&follow=true").
to_raise(KubeException.new('a', 'b', 'c'))
to_raise(Kubeclient::HttpError.new('a', 'b', 'c'))
stub_request(:get, "#{log_url}&previous=true").
to_raise(KubeException.new('a', 'b', 'c'))
to_raise(Kubeclient::HttpError.new('a', 'b', 'c'))
pod_with_client.logs('some-container', 10.seconds.from_now).must_be_nil
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ def worker_is_unstable

describe "#fetch_pods" do
it "retries on failure" do
Kubeclient::Client.any_instance.expects(:get_pods).times(4).raises(KubeException.new(1, 2, 3))
assert_raises KubeException do
Kubeclient::Client.any_instance.expects(:get_pods).times(4).raises(Kubeclient::HttpError.new(1, 2, 3))
assert_raises Kubeclient::HttpError do
executor.send(:fetch_pods, kubernetes_releases(:test_release))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def daemonset_stub(scheduled, misscheduled)

let(:doc) { kubernetes_release_docs(:test_release_pod_1) }
let(:primary_template) { doc.resource_template[0] }
let(:kube_404) { KubeException.new(404, 2, 3) }
let(:kube_404) { Kubeclient::HttpError.new(404, 2, 3) }
let(:service_url) { "http://foobar.server/api/v1/namespaces/pod1/services/some-project" }

before do
Expand Down
8 changes: 4 additions & 4 deletions plugins/kubernetes/test/models/kubernetes/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def assert_pod_deletion

it "raises when a non 404 exception is raised" do
stub_request(:get, url).to_return(status: 500)
assert_raises(KubeException) { resource.running? }
assert_raises(Kubeclient::HttpError) { resource.running? }
end
end

Expand Down Expand Up @@ -213,7 +213,7 @@ def daemonset_stub(scheduled, misscheduled)
end

it "deletes and created when daemonset exists without pods" do
client.expects(:get_daemon_set).raises(KubeException.new(404, 'Not Found', {}))
client.expects(:get_daemon_set).raises(Kubeclient::HttpError.new(404, 'Not Found', {}))
client.expects(:get_daemon_set).returns(daemonset_stub(0, 0))
client.expects(:delete_daemon_set)
client.expects(:create_daemon_set)
Expand All @@ -222,7 +222,7 @@ def daemonset_stub(scheduled, misscheduled)

it "deletes and created when daemonset exists with pods" do
client.expects(:update_daemon_set)
client.expects(:get_daemon_set).raises(KubeException.new(404, 'Not Found', {}))
client.expects(:get_daemon_set).raises(Kubeclient::HttpError.new(404, 'Not Found', {}))
client.expects(:get_daemon_set).times(4).returns(
daemonset_stub(1, 1), # running check
daemonset_stub(1, 1), # after update check #1 ... still running
Expand Down Expand Up @@ -326,7 +326,7 @@ def deployment_stub(replica_count)
client.expects(:update_deployment).with do |template|
template[:spec][:replicas].must_equal 0
end
client.expects(:get_deployment).raises(KubeException.new(404, 'Not Found', {}))
client.expects(:get_deployment).raises(Kubeclient::HttpError.new(404, 'Not Found', {}))
client.expects(:get_deployment).times(3).returns(
deployment_stub(3),
deployment_stub(3),
Expand Down

0 comments on commit 785d382

Please sign in to comment.