-
Notifications
You must be signed in to change notification settings - Fork 897
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
Handle nil dockerImageManifest and nil dockerImageMetadata in openshift images #13263
Conversation
@enoodle I couldnt find the description of these fields under openshift, can you point me towards the |
So both are |
@zeari Also |
@@ -176,25 +176,29 @@ def parse_openshift_image(openshift_image) | |||
ref = ContainerImage::DOCKER_PULLABLE_PREFIX + id |
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.
dockerImageReference
Could also be empty.
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 Done
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.
@zeari I am sorry but on second thought maybe this is not enough also. without id and ref there is not much meaning to parser_container_image
. Maybe we should also try to get the name from the "regular" metadata, which also might be empty.
id = openshift_image[:dockerImageReference] || openshift_image[:metadata][:name] || ""
also anyway the field name should start with a lowercase d IIUC
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.
Also done
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.
So if id ends up being ""
, ref ends up being "docker-pullable://"
,
does parser_container_image
which calls parse_image_name
all work?
Can you add some unit test where at least some of these things are missing?
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.
why not the following:
id = openshift_image[:dockerImageReference] || openshift_image[:metadata][:name]
ref = "ContainerImage::DOCKER_PULLABLE_PREFIX#{id}"
or
id = openshift_image[:dockerImageReference] || openshift_image[:metadata][:name]
ref = ContainerImage::DOCKER_PULLABLE_PREFIX + id.to_s
In other words, make creation of the ref
defensive.
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 am not sure what is the meaning of an image without a name... also parse_container_image
might return weird results.
Maybe we should find a way to ignore this "image" if that happens?
5217e6c
to
06b597b
Compare
@@ -176,25 +176,29 @@ def parse_openshift_image(openshift_image) | |||
ref = ContainerImage::DOCKER_PULLABLE_PREFIX + id |
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.
@zeari I am sorry but on second thought maybe this is not enough also. without id and ref there is not much meaning to parser_container_image
. Maybe we should also try to get the name from the "regular" metadata, which also might be empty.
id = openshift_image[:dockerImageReference] || openshift_image[:metadata][:name] || ""
also anyway the field name should start with a lowercase d IIUC
06b597b
to
297fa43
Compare
BTW if you need live data examples, here is another one from Einat's OSE 3.3: |
@@ -172,29 +172,33 @@ def parse_env_variables(env_variables) | |||
end | |||
|
|||
def parse_openshift_image(openshift_image) | |||
id = openshift_image[:dockerImageReference] | |||
id = openshift_image[:dockerImageReference] || openshift_image[:metadata][:name] || "" |
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.
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 agree, Maybe we should abort the processing of that image in this case. There is not much meaning to an image without a name.
297fa43
to
356b041
Compare
@enoodle @simon3z We shouldnt have empty ids, so this version should be ok.
@chessbyte I went with this option |
@smarterclayton @deads2k can you confirm that When reading objects from the Since all objects are identified by their |
Correct.
Correct. Names are generated before the object is stored, so an API client can never observe an API object without a name. |
@zeari overall looks good but I think we need to unit-test |
356b041
to
5520b2f
Compare
:tag => "abcdefg" | ||
}) | ||
end | ||
|
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.
5520b2f
to
aaf317b
Compare
Done. |
ping @simon3z is there something missing here? |
LGTM 👍 cc @chessbyte @miq-bot assign chessbyte |
id = openshift_image[:dockerImageReference] | ||
ref = ContainerImage::DOCKER_PULLABLE_PREFIX + id | ||
id = openshift_image[:dockerImageReference] || openshift_image[:metadata][:name] | ||
ref = ContainerImage::DOCKER_PULLABLE_PREFIX + id.to_s |
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.
Prefer interpolation over +
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.
Agree. Prefer:
ref = "ContainerImage::DOCKER_PULLABLE_PREFIX#{id}"
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.
oops, should be:
ref = "#{ContainerImage::DOCKER_PULLABLE_PREFIX}#{id}"
json = JSON.parse(openshift_image[:dockerImageManifest]) | ||
new_result[:tag] ||= json["tag"] if json.keys.include?("tag") | ||
if openshift_image[:dockerImageManifest].present? | ||
json = JSON.parse(openshift_image[:dockerImageManifest]) |
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 it possible this could be a "bad" JSON payload? If so, does it need to be handled?
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 dont think the json can be malformed but it can be nil
(which i check for).
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.
@zeari @Fryguy I agree that the JSON payload can hardly be malformed but this part is so critical (not crashing the inventory refresh) that it may deserve some extra care (so that we won't have to deal with this in the future).
In case we can't parse the JSON string we could log an error and continue.
de52589
to
077f707
Compare
Checked commit zeari@077f707 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1 |
ping @Fryguy, I added a |
@gtanzillo @blomquisg Can you guys take a look? 😅 |
@chessbyte we need a backport for euwe. |
Handle nil dockerImageManifest and nil dockerImageMetadata in openshift images (cherry picked from commit 5ea1153) https://bugzilla.redhat.com/show_bug.cgi?id=1412312
Euwe backport details:
|
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1405937
dockerImageManifest/dockerImageMetadata could be nil when parsing openshift image data.
@enoodle @simon3z Please review
@miq-bot add_label providers/containers, bug