mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-23 07:13:23 +00:00
Add depends_on field for core service ordering
* Adds depends_on fields to compose YAML * Updates parsing code to copy across depends_on field to openfaas service from compose service definition * Adds algorithm and unit tests for finding order * Applies order to up.go command * Makes unit testing on MacOS possible through build directives Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
db5312158c
commit
2b9efd29a0
35
pkg/depends_on.go
Normal file
35
pkg/depends_on.go
Normal file
@ -0,0 +1,35 @@
|
||||
package pkg
|
||||
|
||||
import "fmt"
|
||||
|
||||
func buildInstallOrder(svcs []Service) []string {
|
||||
graph := Graph{nodes: []*Node{}}
|
||||
|
||||
nodeMap := map[string]*Node{}
|
||||
for _, s := range svcs {
|
||||
n := &Node{Name: s.Name}
|
||||
nodeMap[s.Name] = n
|
||||
graph.nodes = append(graph.nodes, n)
|
||||
}
|
||||
|
||||
for _, s := range svcs {
|
||||
for _, d := range s.DependsOn {
|
||||
nodeMap[s.Name].Edges = append(nodeMap[s.Name].Edges, nodeMap[d])
|
||||
}
|
||||
}
|
||||
|
||||
resolved := &Graph{}
|
||||
unresolved := &Graph{}
|
||||
for _, g := range graph.nodes {
|
||||
resolve(g, resolved, unresolved)
|
||||
}
|
||||
|
||||
fmt.Printf("Installation order:\n")
|
||||
order := []string{}
|
||||
for _, node := range resolved.nodes {
|
||||
fmt.Printf("- %s\n", node.Name)
|
||||
order = append(order, node.Name)
|
||||
}
|
||||
|
||||
return order
|
||||
}
|
Reference in New Issue
Block a user