Skip to content

Commit c350f80

Browse files
authored
up: do not warn on successful optional dependency complete (docker#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 <[email protected]>
1 parent 80856ea commit c350f80

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

pkg/compose/convergence.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func containerEvents(containers Containers, eventFunc func(string) progress.Even
294294
return events
295295
}
296296

297-
func containerSkippedEvents(containers Containers, eventFunc func(string, string) progress.Event, reason string) []progress.Event {
297+
func containerReasonEvents(containers Containers, eventFunc func(string, string) progress.Event, reason string) []progress.Event {
298298
events := []progress.Event{}
299299
for _, container := range containers {
300300
events = append(events, eventFunc(getContainerProgressName(container), reason))
@@ -334,7 +334,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
334334
healthy, err := s.isServiceHealthy(ctx, waitingFor, true)
335335
if err != nil {
336336
if !config.Required {
337-
w.Events(containerSkippedEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %q is not running or is unhealthy", dep)))
337+
w.Events(containerReasonEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %q is not running or is unhealthy", dep)))
338338
logrus.Warnf("optional dependency %q is not running or is unhealthy: %s", dep, err.Error())
339339
return nil
340340
}
@@ -348,7 +348,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
348348
healthy, err := s.isServiceHealthy(ctx, waitingFor, false)
349349
if err != nil {
350350
if !config.Required {
351-
w.Events(containerSkippedEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %q failed to start", dep)))
351+
w.Events(containerReasonEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %q failed to start", dep)))
352352
logrus.Warnf("optional dependency %q failed to start: %s", dep, err.Error())
353353
return nil
354354
}
@@ -365,17 +365,22 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
365365
return err
366366
}
367367
if exited {
368-
logMessageSuffix := fmt.Sprintf("%q didn't complete successfully: exit %d", dep, code)
369-
if !config.Required {
370-
w.Events(containerSkippedEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %s", logMessageSuffix)))
371-
logrus.Warnf("optional dependency %s", logMessageSuffix)
368+
if code == 0 {
369+
w.Events(containerEvents(waitingFor, progress.Exited))
372370
return nil
373371
}
374-
w.Events(containerEvents(waitingFor, progress.Exited))
375-
if code != 0 {
376-
return fmt.Errorf("service %q didn't complete successfully: exit %d", dep, code)
372+
373+
messageSuffix := fmt.Sprintf("%q didn't complete successfully: exit %d", dep, code)
374+
if !config.Required {
375+
// optional -> mark as skipped & don't propagate error
376+
w.Events(containerReasonEvents(waitingFor, progress.SkippedEvent, fmt.Sprintf("optional dependency %s", messageSuffix)))
377+
logrus.Warnf("optional dependency %s", messageSuffix)
378+
return nil
377379
}
378-
return nil
380+
381+
msg := fmt.Sprintf("service %s", messageSuffix)
382+
w.Events(containerReasonEvents(waitingFor, progress.ErrorMessageEvent, msg))
383+
return errors.New(msg)
379384
}
380385
default:
381386
logrus.Warnf("unsupported depends_on condition: %s", config.Condition)

0 commit comments

Comments
 (0)