Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try uncached api_resources before raising K8s::Error::UndefinedResource #83

Merged
merged 3 commits into from
Jan 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/k8s/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ def api_resources
# @return [K8s::API::MetaV1::APIResource]
def find_api_resource(resource_name)
found_resource = api_resources.find{ |api_resource| api_resource.name == resource_name }
found_resource ||= api_resources!.find{ |api_resource| api_resource.name == resource_name }
raise K8s::Error::UndefinedResource, "Unknown resource #{resource_name} for #{@api_version}" unless found_resource

found_resource
end

# @param resource_name [String]
# @param namespace [String, nil]
# @raise [K8s::Error] unknown resource
# @raise [K8s::Error::UndefinedResource]
# @return [K8s::ResourceClient]
def resource(resource_name, namespace: nil)
ResourceClient.new(@transport, self, find_api_resource(resource_name), namespace: namespace)
end

# @param resource [K8s::Resource]
# @param namespace [String, nil] default if resource is missing namespace
# @raise [K8s::Error::NotFound] API Group does not exist
# @raise [K8s::Error::UndefinedResource]
# @return [K8s::ResourceClient]
def client_for_resource(resource, namespace: nil)
Expand All @@ -83,10 +83,10 @@ def client_for_resource(resource, namespace: nil)
end

found_resource = api_resources.find{ |api_resource| api_resource.kind == resource.kind }
found_resource ||= api_resources!.find{ |api_resource| api_resource.kind == resource.kind }
raise K8s::Error::UndefinedResource, "Unknown resource kind=#{resource.kind} for #{@api_version}" unless found_resource

ResourceClient.new(@transport, self, found_resource,
namespace: resource.metadata.namespace || namespace)
ResourceClient.new(@transport, self, found_resource, namespace: resource.metadata.namespace || namespace)
end

# TODO: skip non-namespaced resources if namespace is given, or ignore namespace?
Expand Down