From 6ba09f468f93bce782acb2c2f34c652d0febcde5 Mon Sep 17 00:00:00 2001 From: Beni Cherniavsky-Paskin Date: Sun, 30 Jul 2017 15:32:28 +0300 Subject: [PATCH] Implement container volume parsing --- .../container_manager/inventory_collections.rb | 5 ++++- .../container_manager/refresh_parser.rb | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/models/manageiq/providers/kubernetes/container_manager/inventory_collections.rb b/app/models/manageiq/providers/kubernetes/container_manager/inventory_collections.rb index ced0141318..786763033b 100644 --- a/app/models/manageiq/providers/kubernetes/container_manager/inventory_collections.rb +++ b/app/models/manageiq/providers/kubernetes/container_manager/inventory_collections.rb @@ -317,7 +317,10 @@ def initialize_inventory_collections :parent => manager, :builder_params => {:ems_id => manager.id}, :association => :persistent_volume_claims, - :use_ar_object => true # serialized :capacity attr + :use_ar_object => true, # serialized :capacity attr + # TODO: add container_project_id column to persistent_volume_claims. + :secondary_refs => {:by_namespace_and_name => [:namespace, :name]}, + :attributes_blacklist => [:namespace], ) ) end 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 f1f7bfcaf6..a8baaddd63 100644 --- a/app/models/manageiq/providers/kubernetes/container_manager/refresh_parser.rb +++ b/app/models/manageiq/providers/kubernetes/container_manager/refresh_parser.rb @@ -372,8 +372,6 @@ def get_persistent_volume_claims_graph(inv) inv["persistent_volume_claim"].each do |pvc| h = parse_persistent_volume_claim(pvc) - h.except!(:namespace) - collection.build(h) end end @@ -386,11 +384,8 @@ def get_persistent_volumes_graph(inv) h.except!(:namespace) # TODO: project untested? - _pvc_ref = h.delete(:persistent_volume_claim_ref) - #h[:persistent_volume_claim] = pvc_ref && @data_index.fetch_path( - # path_for_entity("persistent_volume_claim"), - # :by_namespace_and_name, pvc_ref[:namespace], pvc_ref[:name] - # ) + pvc_ref = h.delete(:persistent_volume_claim_ref) + h[:persistent_volume_claim] = lazy_find_persistent_volume_claim(pvc_ref) collection.build(h) end end @@ -416,6 +411,7 @@ def get_pods_graph(inv) get_containers_graph(container_group, children[:containers]) get_container_conditions_graph(container_group, children[:container_conditions]) + get_container_volumes_graph(container_group, children[:container_volumes]) get_custom_attributes_graph(container_group, :labels => custom_attrs[:labels], # The actual section is "node_selectors" @@ -440,6 +436,8 @@ def get_container_volumes_graph(parent, hashes) collection = @inv_collections[:container_volumes] hashes.to_a.each do |h| h = h.merge(:parent => parent) + pvc_ref = h.delete(:persistent_volume_claim_ref) + h[:persistent_volume_claim] = lazy_find_persistent_volume_claim(pvc_ref) collection.build(h) end end @@ -1328,5 +1326,10 @@ def lazy_find_build_pod(hash) return nil if hash.nil? @inv_collections[:container_build_pods].lazy_find_by(hash, :ref => :by_namespace_and_name) end + + def lazy_find_persistent_volume_claim(hash) + return nil if hash.nil? + @inv_collections[:persistent_volume_claims].lazy_find_by(hash, :ref => :by_namespace_and_name) + end end end