Skip to content

Commit 286fdaa

Browse files
author
Scott Nichols
committed
color the edges too.
1 parent 2844101 commit 286fdaa

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

pkg/graph/graph.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func (g *Graph) AddInMemoryChannel(channel messagingv1alpha1.InMemoryChannel) {
105105
func (g *Graph) AddSubscription(subscription eventingv1alpha1.Subscription) {
106106
sk := subscriptionKey(subscription.Name)
107107
sn := dot.NewNode("Subscription " + subscription.Name)
108+
setNodeColorForStatus(sn, subscription.Status.Status)
108109

109110
ck := gvkKey(subscription.Spec.Channel.GroupVersionKind(), subscription.Spec.Channel.Name)
110111
if cg, ok := g.subgraphs[ck]; !ok {
@@ -117,6 +118,7 @@ func (g *Graph) AddSubscription(subscription eventingv1alpha1.Subscription) {
117118
if sub := g.getOrCreateSubscriber(subscription.Spec.Subscriber); sub != nil {
118119
e := dot.NewEdge(sn, sub)
119120
_ = e.Set("dir", "both")
121+
setEdgeColorForStatus(e, subscription.Status.Status)
120122
g.AddEdge(e)
121123
}
122124

@@ -134,6 +136,7 @@ func (g *Graph) AddBroker(broker eventingv1alpha1.Broker) {
134136
bn := dot.NewNode("Broker " + dns)
135137
_ = bn.Set("shape", "oval")
136138
_ = bn.Set("label", "Ingress")
139+
setNodeColorForStatus(bn, broker.Status.Status)
137140

138141
g.nodes[key] = bn
139142
g.dnsToKey[dns] = key
@@ -174,6 +177,7 @@ func (g *Graph) AddSource(source duckv1alpha1.SourceType) {
174177
}
175178

176179
e := dot.NewEdge(sn, bn)
180+
setEdgeColorForStatus(e, source.Status.Status)
177181
if sg, ok := g.subgraphs[bk]; ok {
178182
// This is not working.
179183
_ = e.Set("lhead", sg.Name())
@@ -213,6 +217,7 @@ func (g *Graph) AddTrigger(trigger eventingv1alpha1.Trigger) {
213217
if sub := g.getOrCreateSubscriber(trigger.Spec.Subscriber); sub != nil {
214218
e := dot.NewEdge(tn, sub)
215219
_ = e.Set("dir", "both")
220+
setEdgeColorForStatus(e, trigger.Status.Status)
216221
fmt.Println("sub", sub, e)
217222
g.AddEdge(e)
218223
}
@@ -280,6 +285,7 @@ func (g *Graph) AddKnService(service servingv1alpha1.Service) {
280285
// Assume full dns name.
281286
target := g.getOrCreateSink(env.Value)
282287
e := dot.NewEdge(svc, target)
288+
setEdgeColorForStatus(e, service.Status.Status)
283289
g.AddEdge(e)
284290
}
285291
}
@@ -320,10 +326,12 @@ func (g *Graph) AddSequence(seq messagingv1alpha1.Sequence) {
320326
if sub := g.getOrCreateSubscriber(&step); sub != nil {
321327
e := dot.NewEdge(stepn, sub)
322328
_ = e.Set("dir", "both")
329+
setEdgeColorForStatus(e, seq.Status.Status)
323330
g.AddEdge(e)
324331
}
325332

326333
e := dot.NewEdge(previousNode, stepn)
334+
setEdgeColorForStatus(e, seq.Status.Status)
327335
g.AddEdge(e)
328336
previousNode = stepn
329337
}
@@ -337,11 +345,13 @@ func (g *Graph) AddSequence(seq messagingv1alpha1.Sequence) {
337345

338346
// TODO where this points.
339347
e := dot.NewEdge(previousNode, replyn)
348+
setEdgeColorForStatus(e, seq.Status.Status)
340349
g.AddEdge(e)
341350

342351
rk := gvkKey(seq.Spec.Reply.GroupVersionKind(), seq.Spec.Reply.Name)
343352
if rn, ok := g.nodes[rk]; ok {
344353
e := dot.NewEdge(replyn, rn)
354+
setEdgeColorForStatus(e, seq.Status.Status)
345355
g.AddEdge(e)
346356
}
347357
}
@@ -360,19 +370,33 @@ func setNodeShapeForKind(node *dot.Node, kind, apiVersion string) {
360370
}
361371
}
362372

363-
func setNodeColorForStatus(node *dot.Node, status duckv1beta1.Status) {
373+
func getColorMapForStatus(status duckv1beta1.Status) map[string]string {
364374
cond := status.GetCondition(apis.ConditionReady)
365-
_ = node.Set("fillcolor", "white")
366-
_ = node.Set("style", "filled")
375+
attrs := make(map[string]string)
367376
if cond.IsTrue() {
368-
_ = node.Set("color", "black")
369-
_ = node.Set("tooltip", fmt.Sprintf("Ready as of %s", cond.LastTransitionTime.Inner.String()))
377+
attrs["color"] = "black"
378+
attrs["tooltip"] = fmt.Sprintf("Ready as of %s", cond.LastTransitionTime.Inner.String())
370379
} else if cond.IsUnknown() {
371-
_ = node.Set("color", "goldenrod")
372-
_ = node.Set("tooltip", fmt.Sprintf("[%s] %s: %s", cond.Status, cond.Reason, cond.Message))
380+
attrs["color"] = "darkorange2"
381+
attrs["tooltip"] = fmt.Sprintf("[%s] %s: %s", cond.Status, cond.Reason, cond.Message)
373382
} else if cond.IsFalse() {
374-
_ = node.Set("color", "deeppink")
375-
_ = node.Set("tooltip", fmt.Sprintf("[%s] %s: %s", cond.Status, cond.Reason, cond.Message))
383+
attrs["color"] = "deeppink"
384+
attrs["tooltip"] = fmt.Sprintf("[%s] %s: %s", cond.Status, cond.Reason, cond.Message)
385+
}
386+
return attrs
387+
}
388+
389+
func setNodeColorForStatus(node *dot.Node, status duckv1beta1.Status) {
390+
_ = node.Set("fillcolor", "white")
391+
_ = node.Set("style", "filled")
392+
for name, value := range getColorMapForStatus(status) {
393+
_ = node.Set(name, value)
394+
}
395+
}
396+
397+
func setEdgeColorForStatus(edge *dot.Edge, status duckv1beta1.Status) {
398+
for name, value := range getColorMapForStatus(status) {
399+
_ = edge.Set(name, value)
376400
}
377401
}
378402

0 commit comments

Comments
 (0)