Skip to content

Commit

Permalink
Merge pull request #2987 from zendesk/jylee/underscoremethod
Browse files Browse the repository at this point in the history
Fix APIService no method error
  • Loading branch information
grosser authored Oct 9, 2018
2 parents b216397 + cd3cdc9 commit c8be0ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions plugins/kubernetes/app/models/kubernetes/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ def delete_pods
end
end

def request(method, *args)
def request(verb, *args)
SamsonKubernetes.retry_on_connection_errors do
begin
client.send("#{method}_#{@template.fetch(:kind).underscore}", *args)
method = "#{verb}_#{Kubeclient::ClientMixin.underscore_entity(@template.fetch(:kind))}"
client.send(method, *args)
rescue Kubeclient::HttpError
message = $!.message.to_s
if message.include?(" is invalid:") || message.include?(" no kind ")
Expand Down
11 changes: 11 additions & 0 deletions plugins/kubernetes/test/models/kubernetes/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,17 @@ def deployment_stub(replica_count)
end
end
end

it "works with kind APIService" do
template[:kind] = "APIService"
template[:apiVersion] = "apiregistration.k8s.io/v1beta1"
url = "http://foobar.server/apis/apiregistration.k8s.io/v1beta1/namespaces/pod1/apiservices/some-project"
assert_request(:get, url, to_return: {body: old.to_json}) do
assert_request(:put, url, to_return: {body: "{}"}) do
resource.deploy
end
end
end
end
end

Expand Down
8 changes: 7 additions & 1 deletion plugins/kubernetes/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,16 @@ def read_kubernetes_sample_file(file_name)
{"name" => "poddisruptionbudgets", "namespaced" => true, "kind" => "PodDisruptionBudget"}
]
},
"apiregistration.k8s.io/v1beta1" => {
"kind" => "APIResourceList",
"resources" => [
{"name" => "apiservices", "namespaced" => true, "kind" => "APIService"}
]
}
}.freeze

before do
stub_request(:get, %r{http://foobar.server/(api/v1|apis/([a-z]+/[a-z\d]+))$}).to_return do |request|
stub_request(:get, %r{http://foobar.server/(api/v1|apis/([a-z.\d]+/[a-z\d]+))$}).to_return do |request|
version = request.uri.path.split('/', 3).last
body = KUBERNETES_VERSION_REPLIES[version] || raise("Missing version stub for #{version}")
{body: body.to_json}
Expand Down

0 comments on commit c8be0ec

Please sign in to comment.