From 25b7cafebdc1772be3a1fdd016593b8d11567f74 Mon Sep 17 00:00:00 2001 From: Ari Zellner Date: Mon, 22 May 2017 14:57:50 +0300 Subject: [PATCH] collect container defninition limits --- .../container_manager/refresh_parser.rb | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 1ecf3539d9..3f7fac2d94 100644 --- a/app/models/manageiq/providers/kubernetes/container_manager/refresh_parser.rb +++ b/app/models/manageiq/providers/kubernetes/container_manager/refresh_parser.rb @@ -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| @@ -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',