Closed felixgao closed 3 years ago
@felixgao
Thanks for posting your code.
Try using xlabel
instead of label
Edge
attributes.
See: https://graphviz.org/docs/attrs/xlabel/
Without Edge
s between the Node
s in the Services Cluster
, the Node
s just get stacked vertically. Add Edge
s between those Node
s and set the penwidth
to 0
so you don't have to see them.
with Diagram("Synchronous Workflow", direction="LR", show=False, graph_attr={}) :
with Cluster("Services", direction="LR"):
with Cluster("Security"):
vault = Vault("vault")
with Cluster("3rd Party"):
google_vision = VisionAPI("OCR")
with Cluster("MXS"):
mxs = Sagemaker("model")
with Cluster(""):
event_bus = Kafka("Event Bus")
s3 = SimpleStorageServiceS3Bucket("Data Lake")
event_bus >> s3
with Cluster("CI/CD"):
github = Github("Repo")
ibp = Custom("Build", "my_resources/jenkins.jpeg")
argo = Argocd("Deploy")
github >> ibp >> argo
with Cluster("K8s", direction="LR"):
with Cluster("Namespace"):
k8s_ingress = Ingress("")
k8s_svc = Service("Apps")
k8s_metrics_svc = Service("metrics")
k8s_rs = ReplicaSet("replica set")
k8s_hpa = HorizontalPodAutoscaler("hpa")
k8s_deployment = Deployment("deploy")
nginx = Nginx("sidecar")
with Cluster("Deployment"):
k8s_pod = Pod("app")
k8s_ingress >> [k8s_svc, k8s_metrics_svc] >> nginx >> k8s_pod << k8s_rs << k8s_deployment << k8s_hpa
switch = Switch("Gateway")
(
vault - Edge(penwidth="0") -
google_vision - Edge(penwidth="0") -
mxs - Edge(penwidth="0") -
event_bus
)
switch >> k8s_ingress
k8s_pod >> Edge(xlabel="get secret", labelloc="b") >> vault
k8s_pod >> Edge(xlabel="get ocr output", labelloc="b") >> google_vision
k8s_pod >> Edge(xlabel="extract data", labelloc="b") >> mxs
k8s_pod >> Edge(xlabel="emit events", style="dotted", labelloc="b") >> event_bus
argo >> k8s_deployment
thanks for the reply @clayms and that works out really good. I have a follow up question, is there a way to move the Services
cluster to align to the middle of the K8s
cluster?
You'll have to play around with the Edge
attributes minlen
and/or constraint
.
https://graphviz.org/docs/attrs/minlen/ https://graphviz.org/docs/attrs/constraint/
See the following. I also changed the splines
from ortho
(default in this library) to spline
and made the label
a headlabel
so I could have more fine control over the placement with labelangle
and labeldistance
.
https://graphviz.org/docs/attrs/splines/ https://graphviz.org/docs/attrs/headlabel/ https://graphviz.org/docs/attrs/labelangle/ https://graphviz.org/docs/attrs/labeldistance/
from diagrams.onprem.ci import Jenkins
graph_attr={
"splines": "spline"
}
with Diagram("Synchronous Workflow", direction="LR", show=False, graph_attr=graph_attr):
with Cluster("Services", direction="LR"):
with Cluster("Security"):
vault = Vault("vault")
with Cluster("3rd Party"):
google_vision = VisionAPI("OCR")
with Cluster("MXS"):
mxs = Sagemaker("model")
with Cluster(""):
event_bus = Kafka("Event Bus")
s3 = SimpleStorageServiceS3Bucket("Data Lake")
event_bus >> s3
with Cluster("CI/CD"):
github = Github("Repo")
ibp = Jenkins("Build")
argo = Argocd("Deploy")
github >> ibp >> argo
with Cluster("K8s", direction="LR"):
with Cluster("Namespace"):
k8s_ingress = Ingress("")
k8s_svc = Service("Apps")
k8s_metrics_svc = Service("metrics")
k8s_rs = ReplicaSet("replica set")
k8s_hpa = HorizontalPodAutoscaler("hpa")
k8s_deployment = Deployment("deploy")
nginx = Nginx("sidecar")
with Cluster("Deployment"):
k8s_pod = Pod("app")
k8s_ingress >> [k8s_svc, k8s_metrics_svc] >> nginx >> k8s_pod << k8s_rs << k8s_deployment << k8s_hpa
switch = Switch("Gateway")
(
vault - Edge(penwidth="0") -
google_vision - Edge(penwidth="0") -
mxs - Edge(penwidth="0") -
event_bus
)
switch >> k8s_ingress
switch - Edge(minlen="2", penwidth="0") - vault
switch - Edge(minlen="1", penwidth="0") - github
k8s_pod >> Edge(headlabel="get\nsecret", labelangle="0", labeldistance="14", constraint="False") >> vault
k8s_pod >> Edge(headlabel="get ocr\noutput", labelangle="0", labeldistance="12", constraint="False") >> google_vision
k8s_pod >> Edge(headlabel="extract\ndata", labelangle="0", labeldistance="15", constraint="False") >> mxs
k8s_pod >> Edge(headlabel="emit\nevents", labelangle="0", labeldistance="12", constraint="False", style="dotted") >> event_bus
argo >> k8s_deployment
I have my diagram defined as following, using 0.20.0 version of the software
The image generate looked like
notice the label for
extract data
is suppose to be on the line going to a model but ended up on the line pointing toOCR
Another problem is all the other diagrams seems to be honoring the direction of
LR
but theServices
seems to be doing aTB
instead. I am not sure if there is a way to organize the position of each diagram withinServices
it doesn't seems to follow the order of the definition or the order of the link within the code.