Skip to content

Commit

Permalink
Merge pull request ManageIQ#94 from agrare/skip_invalid_image_names
Browse files Browse the repository at this point in the history
Skip invalid container_images

(cherry picked from commit f006a2572c257c8545aa29bfa621688b404e76e0)
  • Loading branch information
simon3z authored and agrare committed Sep 22, 2017
1 parent 1bc5eb4 commit 9e416da
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,13 @@ def parse_pod(pod)
containers = pod.spec.containers
unless pod.status.nil? || pod.status.containerStatuses.nil?
pod.status.containerStatuses.each do |cn|
containers_index[cn.name] = parse_container(cn, pod.metadata.uid)
container = parse_container(cn, pod.metadata.uid)
if container.nil?
_log.error("Invalid container: pod - [#{pod.metadata.uid}] container - [#{cn}]")
next
end

containers_index[cn.name] = container
end
end

Expand Down Expand Up @@ -642,13 +648,16 @@ def parse_container_definition(container_def, pod_id)
end

def parse_container(container, pod_id)
container_image = parse_container_image(container.image, container.imageID)
return if container_image.nil?

h = {
:type => 'ManageIQ::Providers::Kubernetes::ContainerManager::Container',
:ems_ref => "#{pod_id}_#{container.name}_#{container.image}",
:name => container.name,
:restart_count => container.restartCount,
:backing_ref => container.containerID,
:container_image => parse_container_image(container.image, container.imageID)
:container_image => container_image
}
state_attributes = parse_container_state container.lastState
state_attributes.each { |key, val| h[key.to_s.prepend('last_').to_sym] = val } if state_attributes
Expand All @@ -669,6 +678,8 @@ def parse_container_state(state_hash)

def parse_container_image(image, imageID)
container_image, container_image_registry = parse_image_name(image, imageID)
return if container_image.nil?

host_port = nil

unless container_image_registry.nil?
Expand Down Expand Up @@ -768,8 +779,18 @@ def parse_image_name(image, image_ref)
(?<digest>(sha256:)?.+)?
\z
}x

image_parts = docker_pullable_re.match(image)
if image_parts.nil?
_log.error("Invalid image #{image}")
return
end

image_ref_parts = docker_pullable_re.match(image_ref) || docker_daemon_re.match(image_ref)
if image_ref_parts.nil?
_log.error("Invalid image_ref #{image_ref}")
return
end

if image_ref.start_with?(ContainerImage::DOCKER_PULLABLE_PREFIX)
hostname = image_ref_parts[:host] || image_ref_parts[:host2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@
:image_ref => example_ref,
:image => {:name => "example", :tag => nil, :digest => "sha256:1234567abcdefg",
:image_ref => "docker://example@sha256:1234567abcdefg"},
:registry => nil},

{:image_name => "localhost:1234/name",
:image_ref => nil,
:image => nil,
:registry => nil},

{:image_name => nil,
:image_ref => example_ref,
:image => nil,
:registry => nil}]

example_images.each do |ex|
Expand Down

0 comments on commit 9e416da

Please sign in to comment.