Просмотр исходного кода

Fix service initial status in graph, in order to fix compose down duplicate removal of container (example : awesome-compose ELK stack)

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 5 лет назад
Родитель
Сommit
9d918a8ceb
1 измененных файлов с 10 добавлено и 10 удалено
  1. 10 10
      local/dependencies.go

+ 10 - 10
local/dependencies.go

@@ -64,16 +64,16 @@ var (
 
 
 // InDependencyOrder applies the function to the services of the project taking in account the dependency order
 // InDependencyOrder applies the function to the services of the project taking in account the dependency order
 func InDependencyOrder(ctx context.Context, project *types.Project, fn func(context.Context, types.ServiceConfig) error) error {
 func InDependencyOrder(ctx context.Context, project *types.Project, fn func(context.Context, types.ServiceConfig) error) error {
-	return visit(ctx, project, upDirectionTraversalConfig, fn)
+	return visit(ctx, project, upDirectionTraversalConfig, fn, ServiceStopped)
 }
 }
 
 
 // InReverseDependencyOrder applies the function to the services of the project in reverse order of dependencies
 // InReverseDependencyOrder applies the function to the services of the project in reverse order of dependencies
 func InReverseDependencyOrder(ctx context.Context, project *types.Project, fn func(context.Context, types.ServiceConfig) error) error {
 func InReverseDependencyOrder(ctx context.Context, project *types.Project, fn func(context.Context, types.ServiceConfig) error) error {
-	return visit(ctx, project, downDirectionTraversalConfig, fn)
+	return visit(ctx, project, downDirectionTraversalConfig, fn, ServiceStarted)
 }
 }
 
 
-func visit(ctx context.Context, project *types.Project, traversalConfig graphTraversalConfig, fn func(context.Context, types.ServiceConfig) error) error {
-	g := NewGraph(project.Services)
+func visit(ctx context.Context, project *types.Project, traversalConfig graphTraversalConfig, fn func(context.Context, types.ServiceConfig) error, initialStatus ServiceStatus) error {
+	g := NewGraph(project.Services, initialStatus)
 	if b, err := g.HasCycles(); b {
 	if b, err := g.HasCycles(); b {
 		return err
 		return err
 	}
 	}
@@ -155,14 +155,14 @@ func (v *Vertex) GetChildren() []*Vertex {
 }
 }
 
 
 // NewGraph returns the dependency graph of the services
 // NewGraph returns the dependency graph of the services
-func NewGraph(services types.Services) *Graph {
+func NewGraph(services types.Services, initialStatus ServiceStatus) *Graph {
 	graph := &Graph{
 	graph := &Graph{
 		lock:     sync.RWMutex{},
 		lock:     sync.RWMutex{},
 		Vertices: map[string]*Vertex{},
 		Vertices: map[string]*Vertex{},
 	}
 	}
 
 
 	for _, s := range services {
 	for _, s := range services {
-		graph.AddVertex(s.Name, s)
+		graph.AddVertex(s.Name, s, initialStatus)
 	}
 	}
 
 
 	for _, s := range services {
 	for _, s := range services {
@@ -175,22 +175,22 @@ func NewGraph(services types.Services) *Graph {
 }
 }
 
 
 // NewVertex is the constructor function for the Vertex
 // NewVertex is the constructor function for the Vertex
-func NewVertex(key string, service types.ServiceConfig) *Vertex {
+func NewVertex(key string, service types.ServiceConfig, initialStatus ServiceStatus) *Vertex {
 	return &Vertex{
 	return &Vertex{
 		Key:      key,
 		Key:      key,
 		Service:  service,
 		Service:  service,
-		Status:   ServiceStopped,
+		Status:   initialStatus,
 		Parents:  map[string]*Vertex{},
 		Parents:  map[string]*Vertex{},
 		Children: map[string]*Vertex{},
 		Children: map[string]*Vertex{},
 	}
 	}
 }
 }
 
 
 // AddVertex adds a vertex to the Graph
 // AddVertex adds a vertex to the Graph
-func (g *Graph) AddVertex(key string, service types.ServiceConfig) {
+func (g *Graph) AddVertex(key string, service types.ServiceConfig, initialStatus ServiceStatus) {
 	g.lock.Lock()
 	g.lock.Lock()
 	defer g.lock.Unlock()
 	defer g.lock.Unlock()
 
 
-	v := NewVertex(key, service)
+	v := NewVertex(key, service, initialStatus)
 	g.Vertices[key] = v
 	g.Vertices[key] = v
 }
 }