-
Notifications
You must be signed in to change notification settings - Fork 167
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
Recurse over arrays for watch notices #279
Recurse over arrays for watch notices #279
Conversation
@moolitayer @cben can you review? |
👍 good catch, recurse_over_arrays is desired and consistent with rest of kubeclient. Is there any backward-compatibility concern? |
test/test_watch_notice.rb
Outdated
notice = Kubeclient::Common::WatchNotice.new(json) | ||
assert_kind_of(Array, notice.object.status.addresses) | ||
notice.object.status.addresses.each do |address| | ||
assert_kind_of(OpenStruct, address) |
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.
s/OpenStruct/RecursiveOpenStruct/
Will be helpful to do the same in the commit message
Look good, one nit. Agree with @cben this can be considered backward compatible |
Maybe we cab add a simple test for the array access compat? |
Thanks for your review @cben and @moolitayer. I have added the backwards compatibility test as you suggested. |
Currently the elements of arrays inside watch notices aren't converted to intances of `RecursiveOpenStruct`, they are converted to instances of `Hash` instead. This mean that accessing certain fields works differently for objects retrieved directly than for objects received in a notice. For example, to extract the internal IP address of a node retrieved directly the code is like this: ```ruby ip = node.status.addresses.detect { |x| x.type == 'InternalIP' }.address ``` But for a notice it is like this: ```ruby ip = node.status.addresses.detect { |x| x['type'] == 'InternalIP' }['address'] ``` This complicates code that needs to treat objects in the same way, regardless of how they have been retrieved. To avoid that this patch changes the `WatchNotice` class so that the constructor adds the RecursiveOpenStruct `:recurse_over_arrays` option.
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 👍
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
@simon3z thanks for merging this. When can we expect a new release of the gem containing the fix? |
@abonas who is currently responsible for doing releases of the gem? |
This is patch adds a temporary hack to solve an issue with the `kubeclient` gem. See the following pull request for details: Recurse over arrays for watch notices ManageIQ/kubeclient#279 Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
…_watch_notices Recurse over arrays for watch notices
…_watch_notices Recurse over arrays for watch notices
…_watch_notices Recurse over arrays for watch notices (cherry picked from commit 8933375)
…_watch_notices Recurse over arrays for watch notices (cherry picked from commit 8933375)
Currently the elements of arrays inside watch notices aren't converted
to intances of
RecursiveOpenStruct
, they are converted to instances ofHash
instead. This mean that accessing certain fields works differently for
objects retrieved directly than for objects received in a notice. For
example, to extract the internal IP address of a node retrieved directly
the code is like this:
But for a notice it is like this:
This complicates code that needs to treat objects in the same way,
regardless of how they have been retrieved.
To avoid that this patch changes the
WatchNotice
class so that theconstructor adds the RecursiveOpenStruct
:recurse_over_arrays
option.