summaryrefslogtreecommitdiff
path: root/libpod/container_graph.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-08-22 19:08:08 +0200
committerGitHub <noreply@github.com>2019-08-22 19:08:08 +0200
commitb263dd9e81bcadd3be5c7420fca9e53ecc8aef7c (patch)
treea88e48dfe6c6893d793c2f35318907fe9418b1c4 /libpod/container_graph.go
parent34002f92ffa2c71c3f5190b6b73617f14652d674 (diff)
parent56a65cffac2cee3132c950d49ea8a5b46eabbff1 (diff)
downloadpodman-b263dd9e81bcadd3be5c7420fca9e53ecc8aef7c.tar.gz
podman-b263dd9e81bcadd3be5c7420fca9e53ecc8aef7c.tar.bz2
podman-b263dd9e81bcadd3be5c7420fca9e53ecc8aef7c.zip
Merge pull request #3800 from vrothberg/generate-pod
generate systemd pod
Diffstat (limited to 'libpod/container_graph.go')
-rw-r--r--libpod/container_graph.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/libpod/container_graph.go b/libpod/container_graph.go
index 5aa51bc2f..f6988e1ac 100644
--- a/libpod/container_graph.go
+++ b/libpod/container_graph.go
@@ -16,14 +16,30 @@ type containerNode struct {
dependedOn []*containerNode
}
-type containerGraph struct {
+// ContainerGraph is a dependency graph based on a set of containers.
+type ContainerGraph struct {
nodes map[string]*containerNode
noDepNodes []*containerNode
notDependedOnNodes map[string]*containerNode
}
-func buildContainerGraph(ctrs []*Container) (*containerGraph, error) {
- graph := new(containerGraph)
+// DependencyMap returns the dependency graph as map with the key being a
+// container and the value being the containers the key depends on.
+func (cg *ContainerGraph) DependencyMap() (dependencies map[*Container][]*Container) {
+ dependencies = make(map[*Container][]*Container)
+ for _, node := range cg.nodes {
+ dependsOn := make([]*Container, len(node.dependsOn))
+ for i, d := range node.dependsOn {
+ dependsOn[i] = d.container
+ }
+ dependencies[node.container] = dependsOn
+ }
+ return dependencies
+}
+
+// BuildContainerGraph builds a dependency graph based on the container slice.
+func BuildContainerGraph(ctrs []*Container) (*ContainerGraph, error) {
+ graph := new(ContainerGraph)
graph.nodes = make(map[string]*containerNode)
graph.notDependedOnNodes = make(map[string]*containerNode)
@@ -78,7 +94,7 @@ func buildContainerGraph(ctrs []*Container) (*containerGraph, error) {
// Detect cycles in a container graph using Tarjan's strongly connected
// components algorithm
// Return true if a cycle is found, false otherwise
-func detectCycles(graph *containerGraph) (bool, error) {
+func detectCycles(graph *ContainerGraph) (bool, error) {
type nodeInfo struct {
index int
lowLink int