mirror of
https://github.com/docker/compose.git
synced 2026-11-19 22:50:08 +00:00
fix(reconcile): fail start only when the project has no container at all
startService received the whole project's container list, so "no container to start" held only for a project without any container. A service without a container next to existing ones was a no-op and the others still started; the plan failed the whole start instead. Plan the error only when nothing is observed in the project, orphans included. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
13b2300bf3
commit
bf5edcdcf7
1 changed files with 21 additions and 4 deletions
|
|
@ -1553,6 +1553,20 @@ func (r *reconciler) planProviderRelayRestart(service types.ServiceConfig, deps
|
|||
return chainEnd
|
||||
}
|
||||
|
||||
// observedAnyContainer reports whether the project owns at least one container
|
||||
// on the daemon, orphans included.
|
||||
func (r *reconciler) observedAnyContainer() bool {
|
||||
if len(r.observed.Orphans) > 0 {
|
||||
return true
|
||||
}
|
||||
for _, ctrs := range r.observed.Containers {
|
||||
if len(ctrs) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *reconciler) planServiceStart(service types.ServiceConfig) error {
|
||||
if service.Provider != nil {
|
||||
return r.planProviderStart(service)
|
||||
|
|
@ -1577,10 +1591,13 @@ func (r *reconciler) planServiceStart(service types.ServiceConfig) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(replicas) == 0 && !anyRunning && r.options.Scope == ScopeStart && service.GetScale() > 0 {
|
||||
// imperative parity (startService): a scale>0 service with no
|
||||
// container at all cannot be started — only reachable under scope
|
||||
// Start, since CreateStart would have planned the missing creates
|
||||
if len(replicas) == 0 && !anyRunning && r.options.Scope == ScopeStart && service.GetScale() > 0 && !r.observedAnyContainer() {
|
||||
// imperative parity (startService): the "no container to start" check
|
||||
// is project-wide -- it receives the whole project's container list,
|
||||
// so a service without a container next to existing ones is a no-op
|
||||
// and only a project with no container at all fails. Only reachable
|
||||
// under scope Start, since CreateStart would have planned the
|
||||
// missing creates
|
||||
return errNoContainerToStart(service.Name)
|
||||
}
|
||||
if len(replicas) == 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue