Skip to content

Commit

Permalink
Skip invalid container_images
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Aug 23, 2017
1 parent c333fe0 commit 7a49bf0
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,14 @@ def parse_pod(pod)

unless pod.status.nil? || pod.status.containerStatuses.nil?
pod.status.containerStatuses.each do |cn|
container_status = parse_container_status(cn, pod.metadata.uid)
if container_status.nil?
_log.warn("Invalid container status: pod [#{pod.metadata.uid}] container [#{cn}]")
next
end

containers_index[cn.name] ||= {}
containers_index[cn.name].merge!(parse_container_status(cn, pod.metadata.uid))
containers_index[cn.name].merge!(container_status)
end
end

Expand Down Expand Up @@ -1077,11 +1083,14 @@ def parse_quantity(resource) # parse a string with a suffix into a int\float
end

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

h = {
:type => 'ManageIQ::Providers::Kubernetes::ContainerManager::Container',
: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 @@ -1102,6 +1111,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 @@ -1199,8 +1210,18 @@ def parse_image_name(image, image_ref)
(?<digest>(sha256:)?.+)?
\z
}x

image_parts = docker_pullable_re.match(image)
if image_parts.nil?
_log.warn("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.warn("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

0 comments on commit 7a49bf0

Please sign in to comment.