Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelis committed Apr 11, 2024
1 parent c183e19 commit 1e3e6d6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions reconcile/saas_auto_promotions_manager/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ def fetch_commit_shas_and_deployment_info(
saas_file=promotion_data.saas_file,
target_config_hash=promotion_data.target_config_hash,
)

def __repr__(self):
return f"{self.saas_name}/{self.resource_template_name}/{self.target_name}/{self.cluster_name}/{self.namespace_name}"
3 changes: 3 additions & 0 deletions reconcile/saas_auto_promotions_manager/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,6 @@ def combined_content_hash(subscribers: Iterable["Subscriber"]) -> str:
"""
m.update(msg.encode("utf-8"))
return m.hexdigest()[:CONTENT_HASH_LENGTH]

def __repr__(self):
return f"{self.saas_name}/{self.resource_template_name}/{self.target_name}/{self.cluster_name}/{self.namespace_name}"
41 changes: 41 additions & 0 deletions tools/qontract_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
dnsutils,
gql,
)
from reconcile.saas_auto_promotions_manager.utils.saas_files_inventory import (
SaasFilesInventory,
)
from reconcile.utils.aws_api import AWSApi
from reconcile.utils.early_exit_cache import (
CacheKey,
Expand Down Expand Up @@ -239,6 +242,44 @@ def clusters(ctx, name):
columns = ["name", "consoleUrl", "prometheusUrl", "sshuttle"]
print_output(ctx.obj["options"], clusters, columns)

@get.command()
@click.argument("app")
@click.pass_context
def promotions_mermaid(ctx, app):
saas_files = get_saas_files(app_name=app)
subscribers = defaultdict(list)
publishers = defaultdict(list)

print("""graph LR
classDef gate fill:#fff3d1,stroke:#ffe59e;
classDef soak fill:#daf7e2,stroke:#73bf7c;""")

for s in saas_files:
for rt in s.resource_templates:
for t in rt.targets:
if t.promotion is None:
continue
cluster = t.namespace.cluster.name
namespace = t.namespace.name

node = f"{s.name}/{rt.name}/{t.name}/{cluster}/{namespace}"
node += f"[\"{s.name}/{rt.name}{t.name}<br/>on {cluster}/{namespace}\"]"
if s.publish_job_logs:
node += ":::gate"

if t.promotion.publish:
for chan in t.promotion.publish:
publishers[chan].append(node)

if t.promotion.subscribe:
for chan in t.promotion.subscribe:
subscribers[chan].append(node)

for chan, nodes in publishers.items():
for subscriber in subscribers[chan]:
for publisher in nodes:
print(f" {publisher} --> {subscriber};")


@get.command()
@click.argument("name", default="")
Expand Down

0 comments on commit 1e3e6d6

Please sign in to comment.