-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
updater.go
51 lines (48 loc) · 1.29 KB
/
updater.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package progress
import (
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
)
func UpdateProgress(wf *wfv1.Workflow) {
wf.Status.Progress = "0/0"
for nodeID, node := range wf.Status.Nodes {
if node.Type != wfv1.NodeTypePod {
continue
}
progress := wfv1.Progress("0/1")
if node.Fulfilled() {
progress = "1/1"
}
node.Progress = progress
wf.Status.Nodes[nodeID] = node
wf.Status.Progress = wf.Status.Progress.Add(progress)
}
for nodeID, node := range wf.Status.Nodes {
if node.Type == wfv1.NodeTypePod {
continue
}
progress := sumProgress(wf, node, make(map[string]bool))
if progress.IsValid() && node.Progress != progress {
node.Progress = progress
wf.Status.Nodes[nodeID] = node
}
}
}
func sumProgress(wf *wfv1.Workflow, node wfv1.NodeStatus, visited map[string]bool) wfv1.Progress {
progress := wfv1.Progress("0/0")
for _, childNodeID := range node.Children {
if visited[childNodeID] {
continue
}
visited[childNodeID] = true
// this will tolerate missing child (will be "") and therefore ignored
child := wf.Status.Nodes[childNodeID]
progress = progress.Add(sumProgress(wf, child, visited))
if child.Type == wfv1.NodeTypePod {
v := child.Progress
if v.IsValid() {
progress = progress.Add(v)
}
}
}
return progress
}