Skip to content

Commit

Permalink
[plugins/aws][fix] Find dangling plugin roots in graph and sanitize t…
Browse files Browse the repository at this point in the history
…hem (#1895)

* [plugins/aws][fix] Find dangling plugin roots in graph and sanitize them

* Remove cloud var
  • Loading branch information
lloesche authored Feb 2, 2024
1 parent 2f3cb40 commit 175f54b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions plugins/aws/resoto_plugin_aws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ def collect_aws(self) -> None:
log.debug("plugin: AWS collecting resources")
aws_config: AwsConfig = Config.aws
assert self.core_feedback, "core_feedback is not set"
cloud = Cloud(id=self.cloud, name="AWS")

accounts = get_accounts(self.core_feedback.with_context(cloud.id))
accounts = get_accounts(self.core_feedback.with_context(self.root.id))
if len(accounts) == 0:
log.error("No accounts found")
return
Expand Down Expand Up @@ -123,8 +122,8 @@ def collect_aws(self) -> None:
self.regions(profile=account.profile, partition=account.partition),
ArgumentParser.args,
Config.running_config,
self.core_feedback.with_context(cloud.id, account.dname),
cloud,
self.core_feedback.with_context(self.root.id, account.dname),
self.root,
self.task_data or {},
)
for account in accounts
Expand Down
16 changes: 16 additions & 0 deletions resotolib/resotolib/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,22 @@ def sanitize(graph: Graph, maybe_root: Optional[GraphRoot] = None) -> None:
else:
log.debug(f"Found unknown node {node.id} of type {node.kind}")

for node in list(graph.nodes):
if (
isinstance(node, Cloud)
and node not in plugin_roots.values()
and len(list(graph.predecessors(node))) == 0
and node.id in plugin_roots
):
log.debug(
f"Found unconnected plugin root {node.id} with same id as existing plugin root"
" - moving child nodes to existing plugin root and removing unconnected plugin root"
)
for node_child in list(graph.successors(node)):
graph.add_edge(plugin_roots[node.id], node_child)
graph.remove_edge(node, node_child)
graph.remove_node(node)

if len(graph_roots) > 0:
for graph_root in graph_roots:
log.debug(f"Moving children of graph root {graph_root.id}")
Expand Down

0 comments on commit 175f54b

Please sign in to comment.