Skip to content

Commit

Permalink
collect container defninition limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Zellner committed May 28, 2017
1 parent 4ea2250 commit 25b7caf
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,11 @@ def parse_container_definition(container_def, pod_id)
:privileged => container_def.securityContext.try(:privileged),
:run_as_user => container_def.securityContext.try(:runAsUser),
:run_as_non_root => container_def.securityContext.try(:runAsNonRoot),
:security_context => parse_security_context(container_def.securityContext)
:security_context => parse_security_context(container_def.securityContext),
:limit_cpu => parse_quantity(container_def.try(:resources).try(:limits).try(:cpu)),
:limit_memory => parse_quantity(container_def.try(:resources).try(:limits).try(:memory)),
:request_cpu => parse_quantity(container_def.try(:resources).try(:requests).try(:cpu)),
:request_memory => parse_quantity(container_def.try(:resources).try(:requests).try(:memory))
}
ports = container_def.ports
new_result[:container_port_configs] = Array(ports).collect do |port_entry|
Expand All @@ -646,6 +650,28 @@ def parse_container_definition(container_def, pod_id)
new_result
end

BINARY_SUFFICES = ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei"].freeze
SI_SUFFICES = ["K", "M", "G", "T", "P", "E"].freeze

def parse_quantity(resource) # convert to bytes\cores
return nil if resource.nil?
suffix = resource[-2..-1]
power = BINARY_SUFFICES.index(suffix)
if power.present?
resource.chomp(suffix).to_f * (1024**power)
else
suffix = resource[-1]
power = SI_SUFFICES.index(suffix)
if power.present?
resource.chomp(suffix).to_f * (1000**(power))
elsif suffix == "m"
resource.chomp("m").to_f / 1000
else
resource.to_i # bytes
end
end
end

def parse_container(container, pod_id)
h = {
:type => 'ManageIQ::Providers::Kubernetes::ContainerManager::Container',
Expand Down

0 comments on commit 25b7caf

Please sign in to comment.