Skip to content

Commit

Permalink
Explicit lookup by namespace string rather than indirectly by project
Browse files Browse the repository at this point in the history
Avoids dependence on internal detail that objects are constructed
with project being itself a lazy_find by_name.
  • Loading branch information
cben committed Jul 4, 2017
1 parent a004c9d commit 4a5b2a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ def initialize_inventory_collections(ems)

@inv_collections[:container_groups] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerGroup,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_groups,
:secondary_refs => {:by_project_and_name => [:container_project, :name]},
:model_class => ContainerGroup,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_groups,
:secondary_refs => {:by_namespace_and_name => [:namespace, :name]},
:attributes_blacklist => [:namespace],
)
initialize_container_conditions_collection(ems.container_groups)
initialize_custom_attributes_collections(ems.container_groups, %w(labels node_selectors))
Expand Down Expand Up @@ -146,21 +147,23 @@ def initialize_inventory_collections(ems)

@inv_collections[:container_replicators] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerReplicator,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_replicators,
:secondary_refs => {:by_project_and_name => [:container_project, :name]},
:model_class => ContainerReplicator,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_replicators,
:secondary_refs => {:by_namespace_and_name => [:namespace, :name]},
:attributes_blacklist => [:namespace],
)
initialize_custom_attributes_collections(ems.container_replicators, %w(labels selectors))

@inv_collections[:container_services] =
::ManagerRefresh::InventoryCollection.new(
:model_class => ContainerService,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_services,
:secondary_refs => {:by_project_and_name => [:container_project, :name]},
:model_class => ContainerService,
:parent => ems,
:builder_params => {:ems_id => ems.id},
:association => :container_services,
:secondary_refs => {:by_namespace_and_name => [:namespace, :name]},
:attributes_blacklist => [:namespace],
)
initialize_custom_attributes_collections(ems.container_services, %w(labels selectors))
@inv_collections[:container_service_port_configs] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ def get_replication_controllers_graph(inv)

h.except!(:tags)

namespace = h.delete(:namespace)
h[:container_project] = lazy_find_project(:name => namespace)
h[:container_project] = lazy_find_project(:name => h[:namespace])
custom_attrs = h.extract!(:labels, :selector_parts)

container_replicator = collection.build(h)
Expand Down Expand Up @@ -381,7 +380,7 @@ def get_pods_graph(inv)

h.except!(:tags)

h[:container_project] = lazy_find_project(:name => h.delete(:namespace))
h[:container_project] = lazy_find_project(:name => h[:namespace])
h[:container_node] = lazy_find_node(:name => h.delete(:container_node_name))
h[:container_replicator] = lazy_find_replicator(h.delete(:container_replicator_ref))
_build_pod_name = h.delete(:build_pod_name)
Expand Down Expand Up @@ -486,7 +485,7 @@ def get_endpoints_and_services_graph(inv)

h[:container_groups] = cgs_by_namespace_and_name.fetch_path(h[:namespace], h[:name])

h.except!(:tags, :namespace)
h.except!(:tags)

container_service = collection.build(h)

Expand Down Expand Up @@ -1265,18 +1264,14 @@ def lazy_find_node(name:)

def lazy_find_replicator(hash)
return nil if hash.nil?
# Subtle: we can match replicators by project name - instead of project ems_ref -
# because when indexed their :container_project a itself lazy_find :by_name,
# so its .to_s is the project name.
# Could maybe even do lazy_find_by but it's complicated enough as is...
index = "#{hash[:namespace]}__#{hash[:name]}"
@inv_collections[:container_replicators].lazy_find(index, :ref => :by_project_and_name)
@inv_collections[:container_replicators].lazy_find(index, :ref => :by_namespace_and_name)
end

def lazy_find_container_group(hash)
return nil if hash.nil?
index = "#{hash[:namespace]}__#{hash[:name]}"
@inv_collections[:container_groups].lazy_find(index, :ref => :by_project_and_name)
@inv_collections[:container_groups].lazy_find(index, :ref => :by_namespace_and_name)
end

def lazy_find_image(hash)
Expand Down

0 comments on commit 4a5b2a0

Please sign in to comment.