/
dependencies.go
53 lines (48 loc) · 1.14 KB
/
dependencies.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
52
53
package crane
// Dependencies contains 4 fields:
// all: contains all dependencies
// link: containers linked to
// volumesFrom: containers that provide volumes
// net: container the net stack is shared with
type Dependencies struct {
All []string
Link []string
VolumesFrom []string
Net string
}
// includes checks whether the given needle is
// included in the dependency list
func (d *Dependencies) includes(needle string) bool {
for _, name := range d.All {
if name == needle {
return true
}
}
return false
}
// requireStarted checks whether the given needle needs
// to be running in order to be satisfied.
func (d *Dependencies) requireStarted(needle string) bool {
if needle == d.Net {
return true
}
for _, name := range d.Link {
if name == needle {
return true
}
}
return false
}
// satisfied is true when there are no
// dependencies left.
func (d *Dependencies) satisfied() bool {
return len(d.All) == 0
}
// remove removes the given name from All
func (d *Dependencies) remove(resolved string) {
for i, name := range d.All {
if name == resolved {
d.All = append(d.All[:i], d.All[i+1:]...)
}
}
}