diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2019-08-13 13:06:37 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2019-08-21 17:28:30 +0200 |
commit | 56a65cffac2cee3132c950d49ea8a5b46eabbff1 (patch) | |
tree | c7353580fc33d03c05ade690717980c72630b691 /libpod/container_graph.go | |
parent | a33e4a89ca4f689096f417ebddfe5b992470e54d (diff) | |
download | podman-56a65cffac2cee3132c950d49ea8a5b46eabbff1.tar.gz podman-56a65cffac2cee3132c950d49ea8a5b46eabbff1.tar.bz2 podman-56a65cffac2cee3132c950d49ea8a5b46eabbff1.zip |
generate systemd: support pods and geneartig files
Support generating systemd unit files for a pod. Podman generates one
unit file for the pod including the PID file for the infra container's
conmon process and one unit file for each container (excluding the infra
container).
Note that this change implies refactorings in the `pkg/systemdgen` API.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/container_graph.go')
-rw-r--r-- | libpod/container_graph.go | 24 |
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 |