Skip to content

Commit

Permalink
Merge pull request #378 from cben/blacklist-processedtemplates
Browse files Browse the repository at this point in the history
[v4.1.z] Don't try creating methods for /processedtemplates pseudo-entity
  • Loading branch information
cben authored Dec 17, 2018
2 parents e686cc9 + 7610ecf commit 60e0a5f
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ def load_entities
@entities = {}
fetch_entities['resources'].each do |resource|
next if resource['name'].include?('/')
# Not a regular entity, special functionality covered by `process_template`.
# https://github.com/openshift/origin/issues/21668
next if resource['kind'] == 'Template' && resource['name'] == 'processedtemplates'
resource['kind'] ||=
Kubeclient::Common::MissingKindCompatibility.resource_kind(resource['name'])
entity = ClientMixin.parse_definition(resource['kind'], resource['name'])
Expand Down
27 changes: 27 additions & 0 deletions test/json/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"apiVersion": "template.openshift.io/v1",
"kind": "Template",
"metadata": {
"creationTimestamp": "2018-12-17T16:11:36Z",
"name": "my-template",
"namespace": "default",
"resourceVersion": "21954",
"selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates/my-template",
"uid": "6e03e3e6-0216-11e9-b1e0-68f728fac3ab"
},
"objects": [
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "${NAME_PREFIX}my-service"
}
}
],
"parameters": [
{
"description": "Prefix for names",
"name": "NAME_PREFIX"
}
]
}
75 changes: 75 additions & 0 deletions test/json/template.openshift.io_api_resource_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "template.openshift.io/v1",
"resources": [
{
"name": "brokertemplateinstances",
"singularName": "",
"namespaced": false,
"kind": "BrokerTemplateInstance",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
]
},
{
"name": "processedtemplates",
"singularName": "",
"namespaced": true,
"kind": "Template",
"verbs": [
"create"
]
},
{
"name": "templateinstances",
"singularName": "",
"namespaced": true,
"kind": "TemplateInstance",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
]
},
{
"name": "templateinstances/status",
"singularName": "",
"namespaced": true,
"kind": "TemplateInstance",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "templates",
"singularName": "",
"namespaced": true,
"kind": "Template",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
]
}
]
}
35 changes: 35 additions & 0 deletions test/json/template_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"kind": "TemplateList",
"apiVersion": "template.openshift.io/v1",
"metadata": {
"selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates",
"resourceVersion": "22758"
},
"items": [
{
"metadata": {
"name": "my-template",
"namespace": "default",
"selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates/my-template",
"uid": "6e03e3e6-0216-11e9-b1e0-68f728fac3ab",
"resourceVersion": "21954",
"creationTimestamp": "2018-12-17T16:11:36Z"
},
"objects": [
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "${NAME_PREFIX}my-service"
}
}
],
"parameters": [
{
"name": "NAME_PREFIX",
"description": "Prefix for names"
}
]
}
]
}
36 changes: 36 additions & 0 deletions test/test_process_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,40 @@ def test_process_template
data['metadata']['namespace'] == 'default'
end
end

# Ensure _template and _templates methods hit `/templates` rather than
# `/processedtemplates` URL.
def test_templates_methods
stub_request(:get, %r{/apis/template\.openshift\.io/v1$}).to_return(
body: open_test_file('template.openshift.io_api_resource_list.json'),
status: 200
)
client = Kubeclient::Client.new('http://localhost:8080/apis/template.openshift.io', 'v1')

expected_url = 'http://localhost:8080/apis/template.openshift.io/v1/namespaces/default/templates'
stub_request(:get, expected_url)
.to_return(body: open_test_file('template_list.json'), status: 200)
client.get_templates(namespace: 'default')
assert_requested(:get, expected_url, times: 1)

expected_url = 'http://localhost:8080/apis/template.openshift.io/v1/namespaces/default/templates/my-template'
stub_request(:get, expected_url)
.to_return(body: open_test_file('template.json'), status: 200)
client.get_template('my-template', 'default')
assert_requested(:get, expected_url, times: 1)
end

def test_no_processedtemplates_methods
stub_request(:get, %r{/apis/template\.openshift\.io/v1$}).to_return(
body: open_test_file('template.openshift.io_api_resource_list.json'),
status: 200
)
client = Kubeclient::Client.new('http://localhost:8080/apis/template.openshift.io', 'v1')
client.discover

refute_respond_to(client, :get_processedtemplates)
refute_respond_to(client, :get_processedtemplate)
refute_respond_to(client, :get_processed_templates)
refute_respond_to(client, :get_processed_template)
end
end

0 comments on commit 60e0a5f

Please sign in to comment.