diff --git a/app/models/manageiq/providers/kubernetes/container_manager/refresh_parser.rb b/app/models/manageiq/providers/kubernetes/container_manager/refresh_parser.rb index 6eb064f339..c3bdb5f936 100644 --- a/app/models/manageiq/providers/kubernetes/container_manager/refresh_parser.rb +++ b/app/models/manageiq/providers/kubernetes/container_manager/refresh_parser.rb @@ -1100,7 +1100,8 @@ def parse_container_state(state_hash) res end - def parse_container_image(image, imageID) + # may return nil if store_new_images = false + def parse_container_image(image, imageID, store_new_images: true) container_image, container_image_registry = parse_image_name(image, imageID) host_port = nil @@ -1124,6 +1125,7 @@ def parse_container_image(image, imageID) :container_image, :by_digest, container_image_identity) if stored_container_image.nil? + return nil unless store_new_images @data_index.store_path( :container_image, :by_digest, container_image_identity, container_image diff --git a/spec/models/manageiq/providers/kubernetes/container_manager/refresh_parser_spec.rb b/spec/models/manageiq/providers/kubernetes/container_manager/refresh_parser_spec.rb index f9f900bfec..ad3c62924d 100644 --- a/spec/models/manageiq/providers/kubernetes/container_manager/refresh_parser_spec.rb +++ b/spec/models/manageiq/providers/kubernetes/container_manager/refresh_parser_spec.rb @@ -658,6 +658,15 @@ expect(first_obj).to be(second_obj) end end + + it "returns existing image or nil with store_new_images=false" do + obj1 = parser.parse_container_image(shared_image_without_host, shared_ref) + obj2 = parser.parse_container_image(shared_image_without_host, shared_ref, :store_new_images => false) + obj3 = parser.parse_container_image(shared_image_without_host, unique_ref, :store_new_images => false) + expect(obj1).not_to be nil + expect(obj2).to be obj2 + expect(obj3).to be nil + end end describe "cross_link_node" do