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
Container Provider Refresh Refactor Image Registries Collection #13724
Container Provider Refresh Refactor Image Registries Collection #13724
Conversation
cc @zeari |
@miq-bot add_label bug, providers/containers |
an alternative solution could be to move the collection of openshift images to happen before the kubernetes parsing ( in |
@enoodle do we have a bug for this and clear steps to know what was the problem, how to reproduce, etc.? I am sure we'll be asked all these info anyway. |
@simon3z I opened a BZ and added to the description |
@miq-bot add_label euwe/yes |
a15dc70
to
cdfe211
Compare
I refactored the solution to collect container image registries the moment that we identify them instead of later in a collection function. |
@@ -692,6 +686,8 @@ def parse_container_image(image, imageID) | |||
if stored_container_image_registry.nil? | |||
@data_index.store_path( | |||
:container_image_registry, :by_host_and_port, host_port, container_image_registry) | |||
@data[:container_image_registries] ||= [] | |||
@data[:container_image_registries] << container_image_registry |
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.
@Fryguy @blomquisg this LGTM but I don't know if there's any implication on not using process_collection
for this data (should be OK for as much as I know).
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.
@simon3z an alternative can be using:
process_collection_item(container_image_registry, :container_image_registries) { |r| r }
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.
@enoodle it depends on where you'll put that line. Can you update the PR so we'll see how it looks like.
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.
@simon3z I palced that line and move the initialization to the initialize
function. PTAL
LGTM 👍 @miq-bot assign Fryguy |
@@ -692,6 +686,8 @@ def parse_container_image(image, imageID) | |||
if stored_container_image_registry.nil? | |||
@data_index.store_path( | |||
:container_image_registry, :by_host_and_port, host_port, container_image_registry) | |||
@data[:container_image_registries] ||= [] |
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.
@enoodle maybe we can move this initialization somewhere else?
There's an edge-case where all the images have no registry where this may remain nil
, right? (As we'll never hit this code).
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.
we can move this to initialize
9eb015c
to
45d842f
Compare
@@ -9,6 +9,7 @@ def self.ems_inv_to_hashes(inventory) | |||
|
|||
def initialize | |||
@data = {} | |||
@data[:container_image_registries] ||= [] |
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.
@enoodle for sure no need for the ||
you just defined it above. Maybe you can even do:
@data = {
# >>> Here you need a meaningful comment that explains this exception <<<
:container_image_registries => []
}
Maybe you can even add a test... a refresh with no registries would it fail if it is nil
instead of []
(if not we don't even need to initialize).
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.
@simon3z I tested this and there is no need to initialize this in case no registries are found.
In case no registries are found then @data[:container_image_registries]
will return nil, and then hashes[:container_image_registries]
in [1] will be nil and in [2] we will return without a failure.
[1]https://github.com/ManageIQ/manageiq/blob/master/app/models/ems_refresh/save_inventory_container.rb#L13
[2]https://github.com/ManageIQ/manageiq/blob/master/app/models/ems_refresh/save_inventory_container.rb#L325
45d842f
to
2f223e3
Compare
expect(parser.instance_variable_get('@data')[:container_image_registries].size).to eq(1) | ||
end | ||
|
||
it "collects image registries from openshift images" do |
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.
@enoodle what is this testing? Maybe I am missing something or the description can be improved.
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.
@simon3z it uses the :after
clause to test, this makes sure that if an image registry is defined only from an image found from Openshift, this image registry will be collected.
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.
@enoodle then it should probably be something more explanatory than "collects image registries from openshift images"
which is not fully reflecting what you're testing here.
@enoodle much better now! Really nice! |
2f223e3
to
fcd248b
Compare
I changed the spec name to "collects image registries from openshift images that are not also running pods images", also squashed the commits. @simon3z PTAL |
@enoodle have you verified that this works also without any registry? ( |
@simon3z Yes, I run it while manually disabling image/pod collection disabled and saw that in |
@enoodle OK thanks. Then waiting for (review/)merge from @Fryguy @chessbyte 👍 |
@@ -166,6 +166,32 @@ | |||
parser.instance_variable_get('@data_index')[:container_image][:by_ref_and_registry_host_port].values[0]) | |||
expect(parser.instance_variable_get('@data')[:container_images][0][:architecture]).to eq('amd64') | |||
end | |||
|
|||
context "image registries from openshift images" do | |||
after :each do |
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.
:each
here is redundant and not needed.
|
||
context "image registries from openshift images" do | ||
after :each do | ||
inventory = {"image" => [image_from_openshift,]} |
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.
Is that trailing comma expected? It doesn't do anything, so I think it should be removed
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.
fixed
|
||
parser.get_openshift_images(inventory) | ||
expect(parser.instance_variable_get('@data_index')[:container_image_registry][:by_host_and_port].size).to eq(1) | ||
expect(parser.instance_variable_get('@data')[:container_image_registries].size).to eq(1) |
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.
Doing expectations in an after
is very strange, as after
is meant for cleanup/teardown, and it especially makes the it
on line 179 very strange as it's empty. If you want to bunch these together to DRY it up, prefer a regular Ruby method that is called from each it
, or perhaps even better, use RSpec shared_examples
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.
I changed to a single function parse_single_openshift_image_with_registry
as shared_examples seems like something to share between different objects and less between different functions.
fcd248b
to
8e2e70c
Compare
This will allow image registries collected from both running pods and openshift images to be collected.
8e2e70c
to
dc816de
Compare
Checked commit enoodle@dc816de with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@Fryguy I made the changes, PTAL |
…age_registries Container Provider Refresh Refactor Image Registries Collection (cherry picked from commit 82b0db1) https://bugzilla.redhat.com/show_bug.cgi?id=1419680
Euwe backport details:
|
After collecting images from Openshift new image registries are added
and should be collected. The previous registries are also cleared to
prevent duplicates.
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1418590