np-guard / netpol-analyzer

A Golang library for analyzing k8s connectivity-configuration resources (a.k.a. network policies)
Apache License 2.0
9 stars 2 forks source link

diff dot output enhancements #246

Closed shireenf-ibm closed 1 year ago

shireenf-ibm commented 1 year ago

243

shireenf-ibm commented 1 year ago

This is the const legend section which is added to all dot graphs :

nodesep=0.5
subgraph cluster_legend {
  label="Legend"
  fontsize = 10
  margin=0
  a [style=invis height=0 width=0]
  b [style=invis height=0 width=0]
  c [style=invis height=0 width=0]
  d [style=invis height=0 width=0]
  e [style=invis height=0 width=0]
  f [style=invis height=0 width=0]
  g [style=invis height=0 width=0]
  h [style=invis height=0 width=0]
  {rank=source a b c d}
  {rank=same e f g h}
  a -> b [label="added connection", color="#008000" fontcolor="#008000" fontsize = 10 arrowsize=0.2]
  c -> d [label="removed connection", color="red2" fontcolor="red2" fontsize = 10 arrowsize=0.2]
  e -> f [label="changed connection", color="magenta" fontcolor="magenta" fontsize = 10 arrowsize=0.2]
  g -> h [label="non-changed connection", color="grey" fontcolor="grey" fontsize = 10 arrowsize=0.2]
  np [label="new peer" color="#008000" fontcolor="#008000" fontsize = 10]
  lp [label="lost peer" color="red" fontcolor="red" fontsize = 10]
  pp [label="persistent peer" color="blue" fontcolor="blue" fontsize = 10]
  {rank=sink np lp pp}
  np->lp [style=invis]
  lp->pp [style=invis]
}

In code wrote it using some const variables and funcs to avoid lint errors and for easy changes to be made if needed in future