mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
up: do not warn on successful optional dependency complete (#10870)
If an optional dependency exits successfully (exit code of 0), with a service condition of `service_completed_successfully`, don't log a warning. Signed-off-by: Milas Bowman <milas.bowman@docker.com>
This commit is contained in:
parent
80856eacaf
commit
c350f80d4b
@ -294,7 +294,7 @@ func containerEvents(containers Containers, eventFunc func(string) progress.Even
|
|||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
func containerSkippedEvents(containers Containers, eventFunc func(string, string) progress.Event, reason string) []progress.Event {
|
func containerReasonEvents(containers Containers, eventFunc func(string, string) progress.Event, reason string) []progress.Event {
|
||||||
events := []progress.Event{}
|
events := []progress.Event{}
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
events = append(events, eventFunc(getContainerProgressName(container), reason))
|
events = append(events, eventFunc(getContainerProgressName(container), reason))
|
||||||
@ -334,7 +334,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
|
|||||||
healthy, err := s.isServiceHealthy(ctx, waitingFor, true)
|
healthy, err := s.isServiceHealthy(ctx, waitingFor, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !config.Required {
|
if !config.Required {
|
||||||
w.Events(containerSkippedEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %q is not running or is unhealthy", dep)))
|
w.Events(containerReasonEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %q is not running or is unhealthy", dep)))
|
||||||
logrus.Warnf("optional dependency %q is not running or is unhealthy: %s", dep, err.Error())
|
logrus.Warnf("optional dependency %q is not running or is unhealthy: %s", dep, err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
|
|||||||
healthy, err := s.isServiceHealthy(ctx, waitingFor, false)
|
healthy, err := s.isServiceHealthy(ctx, waitingFor, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !config.Required {
|
if !config.Required {
|
||||||
w.Events(containerSkippedEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %q failed to start", dep)))
|
w.Events(containerReasonEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %q failed to start", dep)))
|
||||||
logrus.Warnf("optional dependency %q failed to start: %s", dep, err.Error())
|
logrus.Warnf("optional dependency %q failed to start: %s", dep, err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -365,17 +365,22 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if exited {
|
if exited {
|
||||||
logMessageSuffix := fmt.Sprintf("%q didn't complete successfully: exit %d", dep, code)
|
if code == 0 {
|
||||||
if !config.Required {
|
w.Events(containerEvents(waitingFor, progress.Exited))
|
||||||
w.Events(containerSkippedEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %s", logMessageSuffix)))
|
|
||||||
logrus.Warnf("optional dependency %s", logMessageSuffix)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
w.Events(containerEvents(waitingFor, progress.Exited))
|
|
||||||
if code != 0 {
|
messageSuffix := fmt.Sprintf("%q didn't complete successfully: exit %d", dep, code)
|
||||||
return fmt.Errorf("service %q didn't complete successfully: exit %d", dep, code)
|
if !config.Required {
|
||||||
|
// optional -> mark as skipped & don't propagate error
|
||||||
|
w.Events(containerReasonEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %s", messageSuffix)))
|
||||||
|
logrus.Warnf("optional dependency %s", messageSuffix)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
msg := fmt.Sprintf("service %s", messageSuffix)
|
||||||
|
w.Events(containerReasonEvents(waitingFor, progress.ErrorMessageEvent, msg))
|
||||||
|
return errors.New(msg)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
logrus.Warnf("unsupported depends_on condition: %s", config.Condition)
|
logrus.Warnf("unsupported depends_on condition: %s", config.Condition)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user