Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions d3fendtools/as_mermaid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class RDF2Mermaid:
K8S.Namespace,
K8S.Registry,
K8S.Application,
K8S.Service,
# DC are groups.
K8S.DeploymentConfig,
K8S.Deployment,
Expand Down Expand Up @@ -333,11 +334,11 @@ def render(self):
return ret

@staticmethod
def create_tree(tree):
def create_tree(tree: dict):
"""Create a tree of subgraphs according to mermaid syntax."""
rendered = set()

def _render_tree(parent, data):
def _render_tree(parent, data, is_namespace=False):
label = data.get("label") or ""
parent_type = data.get("type")
children = data.get("children") or []
Expand All @@ -352,7 +353,7 @@ def _render_tree(parent, data):
continue
if child == parent:
continue
if parent_type == K8S.Namespace:
if (is_namespace, parent_type) == (False, K8S.Namespace):
# Namespace should be processed last.
# Deployment* and Service* should be processed
# under Application.
Expand Down Expand Up @@ -402,5 +403,7 @@ def _render_tree(parent, data):
tree_namespace.append((parent, data))
continue
yield from _render_tree(parent, data)

# Render namespaces last.
for parent, data in tree_namespace:
yield from _render_tree(parent, data)
yield from _render_tree(parent, data, is_namespace=True)
2 changes: 1 addition & 1 deletion d3fendtools/as_mermaid/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@click.command()
@click.argument("files", nargs=-1, type=click.Path(exists=True))
@click.argument("files", nargs=-1, type=click.Path(exists=True), required=True)
@click.option("--output", "-o", help="Output markdown file")
def main(files, output):
output_md = Path(output)
Expand Down
3 changes: 3 additions & 0 deletions d3fendtools/kuberdf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def __init__(self, manifest: dict | None = None, ns: str = None) -> None:
self.kind = manifest["kind"]
self.metadata = manifest["metadata"]
self.name = self.metadata["name"]
from urllib.parse import quote

self.name = quote(self.name, safe="")
self.namespace = manifest["metadata"].get("namespace", ns or "default")
self.ns = URIRef(f"https://k8s.local/{self.namespace}")
self.spec = manifest.get("spec", {})
Expand Down
Loading