Skip to content

Commit d70bb8c

Browse files
ndeloofglours
authored andcommitted
distinguish event (short) status text and details
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent bff3d35 commit d70bb8c

27 files changed

+255
-244
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ bin/
33
coverage.out
44
covdatafiles/
55
.DS_Store
6+
pkg/e2e/*.tar

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ require (
6363

6464
require (
6565
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
66+
github.com/BurntSushi/toml v1.4.0 // indirect
6667
github.com/Masterminds/semver/v3 v3.4.0 // indirect
6768
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
6869
github.com/aws/aws-sdk-go-v2 v1.30.3 // indirect

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkk
44
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
55
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
66
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
7-
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
87
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
8+
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
9+
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
910
github.com/DefangLabs/secret-detector v0.0.0-20250403165618-22662109213e h1:rd4bOvKmDIx0WeTv9Qz+hghsgyjikFiPrseXHlKepO0=
1011
github.com/DefangLabs/secret-detector v0.0.0-20250403165618-22662109213e/go.mod h1:blbwPQh4DTlCZEfk1BLU4oMIhLda2U+A840Uag9DsZw=
1112
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=

pkg/compose/commit.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,18 @@ func (s *composeService) commit(ctx context.Context, projectName string, options
4141
}
4242

4343
name := getCanonicalContainerName(ctr)
44-
msg := fmt.Sprintf("Commit %s", name)
4544

4645
s.events.On(progress.Event{
47-
ID: name,
48-
Text: msg,
49-
Status: progress.Working,
50-
StatusText: "Committing",
46+
ID: name,
47+
Status: progress.Working,
48+
Text: progress.StatusCommitting,
5149
})
5250

5351
if s.dryRun {
5452
s.events.On(progress.Event{
55-
ID: name,
56-
Text: msg,
57-
Status: progress.Done,
58-
StatusText: "Committed",
53+
ID: name,
54+
Status: progress.Done,
55+
Text: progress.StatusCommitted,
5956
})
6057

6158
return nil
@@ -73,10 +70,9 @@ func (s *composeService) commit(ctx context.Context, projectName string, options
7370
}
7471

7572
s.events.On(progress.Event{
76-
ID: name,
77-
Text: msg,
78-
Status: progress.Done,
79-
StatusText: fmt.Sprintf("Committed as %s", response.ID),
73+
ID: name,
74+
Text: fmt.Sprintf("Committed as %s", response.ID),
75+
Status: progress.Done,
8076
})
8177

8278
return nil

pkg/compose/convergence.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
504504
logrus.Warnf("optional dependency %q failed to start: %s", dep, err.Error())
505505
return nil
506506
}
507-
s.events.On(containerEvents(waitingFor, progress.ErrorEvent)...)
507+
s.events.On(containerEvents(waitingFor, func(s string) progress.Event {
508+
return progress.ErrorEventf(s, "dependency %s failed to start", dep)
509+
})...)
508510
return fmt.Errorf("dependency failed to start: %w", err)
509511
}
510512
if healthy {
@@ -532,7 +534,9 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
532534
}
533535

534536
msg := fmt.Sprintf("service %s", messageSuffix)
535-
s.events.On(containerReasonEvents(waitingFor, progress.ErrorMessageEvent, msg)...)
537+
s.events.On(containerEvents(waitingFor, func(s string) progress.Event {
538+
return progress.ErrorEventf(s, "service %s", messageSuffix)
539+
})...)
536540
return errors.New(msg)
537541
}
538542
default:
@@ -600,9 +604,9 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
600604
if err != nil {
601605
if ctx.Err() == nil {
602606
s.events.On(progress.Event{
603-
ID: eventName,
604-
Status: progress.Error,
605-
StatusText: err.Error(),
607+
ID: eventName,
608+
Status: progress.Error,
609+
Text: err.Error(),
606610
})
607611
}
608612
return ctr, err
@@ -619,9 +623,9 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
619623
defer func() {
620624
if err != nil && ctx.Err() == nil {
621625
s.events.On(progress.Event{
622-
ID: eventName,
623-
Status: progress.Error,
624-
StatusText: err.Error(),
626+
ID: eventName,
627+
Status: progress.Error,
628+
Text: err.Error(),
625629
})
626630
}
627631
}()

pkg/compose/cp.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,24 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
8686
name := getCanonicalContainerName(ctr)
8787
var msg string
8888
if direction == fromService {
89-
msg = fmt.Sprintf("copy %s:%s to %s", name, srcPath, dstPath)
89+
msg = fmt.Sprintf("%s:%s to %s", name, srcPath, dstPath)
9090
} else {
91-
msg = fmt.Sprintf("copy %s to %s:%s", srcPath, name, dstPath)
91+
msg = fmt.Sprintf("%s to %s:%s", srcPath, name, dstPath)
9292
}
9393
s.events.On(progress.Event{
94-
ID: name,
95-
Text: msg,
96-
Status: progress.Working,
97-
StatusText: "Copying",
94+
ID: name,
95+
Text: progress.StatusCopying,
96+
Details: msg,
97+
Status: progress.Working,
9898
})
9999
if err := copyFunc(ctx, ctr.ID, srcPath, dstPath, options); err != nil {
100100
return err
101101
}
102102
s.events.On(progress.Event{
103-
ID: name,
104-
Text: msg,
105-
Status: progress.Done,
106-
StatusText: "Copied",
103+
ID: name,
104+
Text: progress.StatusCopied,
105+
Details: msg,
106+
Status: progress.Done,
107107
})
108108
return nil
109109
})

pkg/compose/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ func (s *composeService) resolveOrCreateNetwork(ctx context.Context, project *ty
13981398

13991399
resp, err := s.apiClient().NetworkCreate(ctx, n.Name, createOpts)
14001400
if err != nil {
1401-
s.events.On(progress.ErrorEvent(networkEventName))
1401+
s.events.On(progress.ErrorEvent(networkEventName, err.Error()))
14021402
return "", fmt.Errorf("failed to create network %s: %w", n.Name, err)
14031403
}
14041404
s.events.On(progress.CreatedEvent(networkEventName))
@@ -1632,7 +1632,7 @@ func (s *composeService) createVolume(ctx context.Context, volume types.VolumeCo
16321632
DriverOpts: volume.DriverOpts,
16331633
})
16341634
if err != nil {
1635-
s.events.On(progress.ErrorEvent(eventName))
1635+
s.events.On(progress.ErrorEvent(eventName, err.Error()))
16361636
return err
16371637
}
16381638
s.events.On(progress.CreatedEvent(eventName))

pkg/compose/down.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (s *composeService) removeNetwork(ctx context.Context, composeNetworkName s
235235
if errdefs.IsNotFound(err) {
236236
continue
237237
}
238-
s.events.On(progress.ErrorEvent(eventName))
238+
s.events.On(progress.ErrorEvent(eventName, err.Error()))
239239
return fmt.Errorf("failed to remove network %s: %w", name, err)
240240
}
241241
s.events.On(progress.RemovedEvent(eventName))
@@ -317,7 +317,7 @@ func (s *composeService) stopContainer(ctx context.Context, service *types.Servi
317317
timeoutInSecond := utils.DurationSecondToInt(timeout)
318318
err := s.apiClient().ContainerStop(ctx, ctr.ID, containerType.StopOptions{Timeout: timeoutInSecond})
319319
if err != nil {
320-
s.events.On(progress.ErrorMessageEvent(eventName, "Error while Stopping"))
320+
s.events.On(progress.ErrorEvent(eventName, "Error while Stopping"))
321321
return err
322322
}
323323
s.events.On(progress.StoppedEvent(eventName))
@@ -360,7 +360,7 @@ func (s *composeService) stopAndRemoveContainer(ctx context.Context, ctr contain
360360
RemoveVolumes: volumes,
361361
})
362362
if err != nil && !errdefs.IsNotFound(err) && !errdefs.IsConflict(err) {
363-
s.events.On(progress.ErrorMessageEvent(eventName, "Error while Removing"))
363+
s.events.On(progress.ErrorEvent(eventName, "Error while Removing"))
364364
return err
365365
}
366366
s.events.On(progress.RemovedEvent(eventName))

pkg/compose/export.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ func (s *composeService) export(ctx context.Context, projectName string, options
5151
}
5252

5353
name := getCanonicalContainerName(container)
54-
msg := fmt.Sprintf("export %s to %s", name, options.Output)
55-
5654
s.events.On(progress.Event{
57-
ID: name,
58-
Text: msg,
59-
Status: progress.Working,
60-
StatusText: "Exporting",
55+
ID: name,
56+
Text: progress.StatusExporting,
57+
Status: progress.Working,
6158
})
6259

6360
responseBody, err := s.apiClient().ContainerExport(ctx, container.ID)
@@ -67,12 +64,7 @@ func (s *composeService) export(ctx context.Context, projectName string, options
6764

6865
defer func() {
6966
if err := responseBody.Close(); err != nil {
70-
s.events.On(progress.Event{
71-
ID: name,
72-
Text: msg,
73-
Status: progress.Error,
74-
StatusText: fmt.Sprintf("Failed to close response body: %v", err),
75-
})
67+
s.events.On(progress.ErrorEventf(name, "Failed to close response body: %s", err.Error()))
7668
}
7769
}()
7870

@@ -93,10 +85,9 @@ func (s *composeService) export(ctx context.Context, projectName string, options
9385
}
9486

9587
s.events.On(progress.Event{
96-
ID: name,
97-
Text: msg,
98-
Status: progress.Done,
99-
StatusText: "Exported",
88+
ID: name,
89+
Text: progress.StatusExported,
90+
Status: progress.Done,
10091
})
10192

10293
return nil

pkg/compose/kill.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (s *composeService) kill(ctx context.Context, projectName string, options a
6666
s.events.On(progress.KillingEvent(eventName))
6767
err := s.apiClient().ContainerKill(ctx, ctr.ID, options.Signal)
6868
if err != nil {
69-
s.events.On(progress.ErrorMessageEvent(eventName, "Error while Killing"))
69+
s.events.On(progress.ErrorEvent(eventName, "Error while Killing"))
7070
return err
7171
}
7272
s.events.On(progress.KilledEvent(eventName))

0 commit comments

Comments
 (0)