-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix Client#get_resources for custom resources that are not yet defined #14
Conversation
Note that the
This fix relies on the |
The behavior of the fixed resources.map{|resource|
begin
client.get_resource(resource)
rescue K8s::Error::NotFound
nil
end
} This is because the same Without this fix, |
# Hash{arg => value} | ||
value_map = Hash[func_args.zip(values)] | ||
|
||
args.map{|arg| value_map[arg] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of how the hash is used, any duplicate args will map to the same return value... shouldn't be a problem when used with idempotent methods like GET
requests, but it's a limitation.
lib/k8s/client.rb
Outdated
responses = @transport.requests(*requests, skip_missing: true) | ||
|
||
# map non-nil requests to response objects, or nil for nil request options | ||
Util.compact_map(requests) { |requests| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is shadowing outer local variable .. usually bad practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Tested to (still) fix kontena/pharos-cluster#523 with git 6d2f7ae... note the initial pipelined 404 -> the new
|
Fixes #13
Client#get_resources
usesapis(prefetch_resources: true, skip_missing: true)
to handleGET /apis/certmanager.k8s.io/v1alpha1 => HTTP 404
error cases from the prefetched api_resources and skip theGET
requests for those undefined custom resources. Resources that are not yet defined cannot yet exist, so it's valid to returnnil
for those undefined resources.There's some complexity around the new
Util.compact_map
implementation becauseget_resources
must return an array matching theresources
argument while also skipping over some requests, but this should all have complete spec coverage.