From ff46c7055280d7b9a66086958e7f116ca03ea7c2 Mon Sep 17 00:00:00 2001 From: Samuel Liu Date: Thu, 27 Jun 2024 16:34:10 -0400 Subject: [PATCH] add parse_annotations method --- .../inventory/parser/container_manager.rb | 19 +++++++++++++------ .../definitions/container_collections.rb | 8 ++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/models/manageiq/providers/kubernetes/inventory/parser/container_manager.rb b/app/models/manageiq/providers/kubernetes/inventory/parser/container_manager.rb index 607e8b0c90..d0e8a69bf5 100644 --- a/app/models/manageiq/providers/kubernetes/inventory/parser/container_manager.rb +++ b/app/models/manageiq/providers/kubernetes/inventory/parser/container_manager.rb @@ -317,6 +317,7 @@ def parse_node(node) labels = parse_labels(node) tags = map_labels('ContainerNode', labels) + annotations = parse_annotations(node) new_result.merge!( :identity_infra => node.spec.providerID, @@ -360,7 +361,7 @@ def parse_node(node) container_conditions(container_node, container_conditions) node_computer_systems(container_node, computer_system) - custom_attributes(container_node, :labels => labels) + custom_attributes(container_node, :labels => labels, :annotations => annotations) taggings(container_node, tags) container_node @@ -398,9 +399,10 @@ def parse_service(service) # Typically this happens for kubernetes services new_result[:ems_ref] = "#{new_result[:namespace]}_#{new_result[:name]}" if new_result[:ems_ref].nil? - labels = parse_labels(service) - tags = map_labels('ContainerService', labels) - selector_parts = parse_selector_parts(service) + labels = parse_labels(service) + tags = map_labels('ContainerService', labels) + selector_parts = parse_selector_parts(service) + annotations = parse_annotations(service) new_result.merge!( :container_project => lazy_find_project(:name => new_result[:namespace]), @@ -429,7 +431,7 @@ def parse_service(service) container_service = persister.container_services.build(new_result) container_service_port_configs(container_service, container_service_port_configs) - custom_attributes(container_service, :labels => labels, :selectors => selector_parts) + custom_attributes(container_service, :labels => labels, :selectors => selector_parts, :annotations => annotations) taggings(container_service, tags) container_service @@ -496,6 +498,7 @@ def parse_pod(pod) labels = parse_labels(pod) tags = map_labels('ContainerGroup', labels) + annotations = parse_annotations(pod) node_selector_parts = parse_node_selector_parts(pod) container_volumes = parse_volumes(pod) @@ -505,7 +508,7 @@ def parse_pod(pod) containers(container_group, containers) container_conditions(container_group, container_conditions) container_volumes(container_group, container_volumes) - custom_attributes(container_group, :labels => labels, :node_selectors => node_selector_parts) + custom_attributes(container_group, :labels => labels, :node_selectors => node_selector_parts, :annotations => annotations) taggings(container_group, tags) container_group @@ -740,6 +743,10 @@ def parse_labels(entity) parse_identifying_attributes(entity.metadata.labels, 'labels') end + def parse_annotations(entity) + parse_identifying_attributes(entity.metadata.annotations, 'annotations') + end + def parse_selector_parts(entity) parse_identifying_attributes(entity.spec.selector, 'selectors') end diff --git a/app/models/manageiq/providers/kubernetes/inventory/persister/definitions/container_collections.rb b/app/models/manageiq/providers/kubernetes/inventory/persister/definitions/container_collections.rb index f7f4e09009..1192448208 100644 --- a/app/models/manageiq/providers/kubernetes/inventory/persister/definitions/container_collections.rb +++ b/app/models/manageiq/providers/kubernetes/inventory/persister/definitions/container_collections.rb @@ -58,23 +58,23 @@ def initialize_container_conditions def initialize_custom_attributes %i(container_nodes container_projects).each do |name| - add_custom_attributes(name, %w(labels additional_attributes)) + add_custom_attributes(name, %w(labels additional_attributes annotations)) end %i(container_groups).each do |name| - add_custom_attributes(name, %w(labels node_selectors)) + add_custom_attributes(name, %w(labels node_selectors annotations)) end %i(container_replicators container_services).each do |name| - add_custom_attributes(name, %w(labels selectors)) + add_custom_attributes(name, %w(labels selectors annotations)) end %i(container_builds container_build_pods container_routes container_templates).each do |name| - add_custom_attributes(name, %w(labels)) + add_custom_attributes(name, %w(labels annotations)) end end