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

Recurse over arrays for watch notices #279

Merged
merged 1 commit into from
Dec 17, 2017
Merged

Recurse over arrays for watch notices #279

merged 1 commit into from
Dec 17, 2017

Conversation

jhernand
Copy link
Contributor

@jhernand jhernand commented Dec 15, 2017

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:

ip = node.status.addresses.detect { |x| x.type == 'InternalIP' }.address

But for a notice it is like this:

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.

@jhernand
Copy link
Contributor Author

@abonas @simon3z @masayag please review.

@simon3z
Copy link
Collaborator

simon3z commented Dec 15, 2017

@moolitayer @cben can you review?

@cben
Copy link
Collaborator

cben commented Dec 16, 2017

👍 good catch, recurse_over_arrays is desired and consistent with rest of kubeclient.

Is there any backward-compatibility concern?
I think not as a RecursiveOpenStruct is nearly drop-in compatible with a hash.

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)
Copy link
Collaborator

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

@moolitayer
Copy link
Collaborator

Look good, one nit. Agree with @cben this can be considered backward compatible

@moolitayer
Copy link
Collaborator

Maybe we cab add a simple test for the array access compat?
Silly really since we all know it works but I would add one anyway

@jhernand
Copy link
Contributor Author

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.
Copy link
Collaborator

@moolitayer moolitayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Collaborator

@cben cben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@simon3z simon3z merged commit 8933375 into ManageIQ:master Dec 17, 2017
@jhernand
Copy link
Contributor Author

jhernand commented Dec 17, 2017

@simon3z thanks for merging this. When can we expect a new release of the gem containing the fix?

@simon3z
Copy link
Collaborator

simon3z commented Dec 18, 2017

@simon3z thanks for merging this. When can we expect a new release of the gem containing the fix?

@jhernand you're welcome, the PR was reviewed and approved by @cben and @moolitayer so merging was just bookkeeping.

@abonas @bazulay any plans around the gem release?

@jhernand jhernand deleted the recurse_over_arrays_for_watch_notices branch December 18, 2017 10:51
@abonas
Copy link
Member

abonas commented Dec 18, 2017

@abonas @bazulay any plans around the gem release?

no plans from my side, I am not focusing at this gem development at the moment

@jhernand
Copy link
Contributor Author

@abonas who is currently responsible for doing releases of the gem?

@abonas
Copy link
Member

abonas commented Dec 18, 2017

@jhernand I suggest asking @simon3z and @bazulay

masayag pushed a commit to masayag/manageiq-providers-kubevirt that referenced this pull request Dec 19, 2017
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>
cben pushed a commit to cben/kubeclient that referenced this pull request Jan 22, 2018
…_watch_notices

Recurse over arrays for watch notices
cben pushed a commit to cben/kubeclient that referenced this pull request Jan 25, 2018
…_watch_notices

Recurse over arrays for watch notices
moolitayer pushed a commit to moolitayer/kubeclient that referenced this pull request Feb 4, 2018
…_watch_notices

Recurse over arrays for watch notices

(cherry picked from commit 8933375)
moolitayer pushed a commit to moolitayer/kubeclient that referenced this pull request Feb 4, 2018
…_watch_notices

Recurse over arrays for watch notices

(cherry picked from commit 8933375)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants