Skip to content

Commit 411fa0f

Browse files
thaJeztahvvoland
authored andcommitted
cli/command: reduce uses of client/pkg/progress utilities
Also suppress some unhandled errors Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit a9f5e8a) Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent e09580d commit 411fa0f

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

‎cli/command/service/progress/progress.go‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func terminalState(state swarm.TaskState) bool {
7272
//
7373
//nolint:gocyclo
7474
func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID string, progressWriter io.WriteCloser) error {
75-
defer progressWriter.Close()
75+
defer func() { _ = progressWriter.Close() }()
7676

7777
progressOut := streamformatter.NewJSONProgressOutput(progressWriter, false)
7878

@@ -118,7 +118,7 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID
118118
return fmt.Errorf("service update paused: %s", res.Service.UpdateStatus.Message)
119119
case swarm.UpdateStateRollbackStarted:
120120
if !rollback && res.Service.UpdateStatus.Message != "" {
121-
progressOut.WriteProgress(progress.Progress{
121+
_ = progressOut.WriteProgress(progress.Progress{
122122
ID: "rollback",
123123
Action: res.Service.UpdateStatus.Message,
124124
})
@@ -169,7 +169,7 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID
169169
// use the presence of this field to check if the service is a job
170170
// here.
171171
if res.Service.JobStatus != nil {
172-
progress.Message(progressOut, "", "job complete")
172+
_ = progressOut.WriteProgress(progress.Progress{Message: "job complete"})
173173
return nil
174174
}
175175

@@ -205,8 +205,8 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID
205205
case <-time.After(200 * time.Millisecond):
206206
case <-sigint:
207207
if !converged {
208-
progress.Message(progressOut, "", "Operation continuing in background.")
209-
progress.Messagef(progressOut, "", "Use `docker service ps %s` to check progress.", serviceID)
208+
_ = progressOut.WriteProgress(progress.Progress{Message: "Operation continuing in background."})
209+
_ = progressOut.WriteProgress(progress.Progress{Message: fmt.Sprintf("Use `docker service ps %s` to check progress.", serviceID)})
210210
}
211211
return nil
212212
}
@@ -255,13 +255,13 @@ func initializeUpdater(service swarm.Service, progressOut progress.Output) (prog
255255

256256
func writeOverallProgress(progressOut progress.Output, numerator, denominator int, rollback bool) {
257257
if rollback {
258-
progressOut.WriteProgress(progress.Progress{
258+
_ = progressOut.WriteProgress(progress.Progress{
259259
ID: "overall progress",
260260
Action: fmt.Sprintf("rolling back update: %d out of %d tasks", numerator, denominator),
261261
})
262262
return
263263
}
264-
progressOut.WriteProgress(progress.Progress{
264+
_ = progressOut.WriteProgress(progress.Progress{
265265
ID: "overall progress",
266266
Action: fmt.Sprintf("%d out of %d tasks", numerator, denominator),
267267
})
@@ -305,7 +305,10 @@ func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm.
305305

306306
if replicas <= maxProgressBars {
307307
for i := uint64(1); i <= replicas; i++ {
308-
progress.Update(u.progressOut, fmt.Sprintf("%d/%d", i, replicas), " ")
308+
_ = u.progressOut.WriteProgress(progress.Progress{
309+
ID: fmt.Sprintf("%d/%d", i, replicas),
310+
Action: " ",
311+
})
309312
}
310313
}
311314
u.initialized = true
@@ -388,15 +391,15 @@ func (u *replicatedProgressUpdater) writeTaskProgress(task swarm.Task, mappedSlo
388391
}
389392

390393
if task.Status.Err != "" {
391-
u.progressOut.WriteProgress(progress.Progress{
394+
_ = u.progressOut.WriteProgress(progress.Progress{
392395
ID: fmt.Sprintf("%d/%d", mappedSlot, replicas),
393396
Action: truncError(task.Status.Err),
394397
})
395398
return
396399
}
397400

398401
if !terminalState(task.DesiredState) && !terminalState(task.Status.State) {
399-
u.progressOut.WriteProgress(progress.Progress{
402+
_ = u.progressOut.WriteProgress(progress.Progress{
400403
ID: fmt.Sprintf("%d/%d", mappedSlot, replicas),
401404
Action: fmt.Sprintf("%-[1]*s", longestState, task.Status.State),
402405
Current: numberedStates[task.Status.State],
@@ -427,7 +430,7 @@ func (u *globalProgressUpdater) update(_ swarm.Service, tasks []swarm.Task, acti
427430
// Two possibilities: either the orchestrator hasn't created
428431
// the tasks yet, or the service doesn't meet constraints for
429432
// any node. Either way, we wait.
430-
u.progressOut.WriteProgress(progress.Progress{
433+
_ = u.progressOut.WriteProgress(progress.Progress{
431434
ID: "overall progress",
432435
Action: "waiting for new tasks",
433436
})
@@ -505,15 +508,15 @@ func (u *globalProgressUpdater) writeTaskProgress(task swarm.Task, nodeCount int
505508
}
506509

507510
if task.Status.Err != "" {
508-
u.progressOut.WriteProgress(progress.Progress{
511+
_ = u.progressOut.WriteProgress(progress.Progress{
509512
ID: formatter.TruncateID(task.NodeID),
510513
Action: truncError(task.Status.Err),
511514
})
512515
return
513516
}
514517

515518
if !terminalState(task.DesiredState) && !terminalState(task.Status.State) {
516-
u.progressOut.WriteProgress(progress.Progress{
519+
_ = u.progressOut.WriteProgress(progress.Progress{
517520
ID: formatter.TruncateID(task.NodeID),
518521
Action: fmt.Sprintf("%-[1]*s", longestState, task.Status.State),
519522
Current: numberedStates[task.Status.State],
@@ -593,7 +596,7 @@ func (u *replicatedJobProgressUpdater) update(_ swarm.Service, tasks []swarm.Tas
593596
// only write out progress bars if there will be less than the maximum
594597
if u.total <= maxProgressBars {
595598
for i := 1; i <= u.total; i++ {
596-
u.progressOut.WriteProgress(progress.Progress{
599+
_ = u.progressOut.WriteProgress(progress.Progress{
597600
ID: fmt.Sprintf("%d/%d", i, u.total),
598601
Action: " ",
599602
})

‎cli/command/swarm/progress/root_rotation.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func RootRotationProgress(ctx context.Context, apiClient client.APIClient, progr
3737
defer signal.Stop(sigint)
3838

3939
// draw 2 progress bars, 1 for nodes with the correct cert, 1 for nodes with the correct trust root
40-
progress.Update(progressOut, "desired root digest", "")
41-
progress.Update(progressOut, certsRotatedStr, certsAction)
42-
progress.Update(progressOut, rootsRotatedStr, rootsAction)
40+
_ = progressOut.WriteProgress(progress.Progress{ID: "desired root digest"})
41+
_ = progressOut.WriteProgress(progress.Progress{ID: certsRotatedStr, Action: certsAction})
42+
_ = progressOut.WriteProgress(progress.Progress{ID: rootsRotatedStr, Action: rootsAction})
4343

4444
var done bool
4545

@@ -64,8 +64,8 @@ func RootRotationProgress(ctx context.Context, apiClient client.APIClient, progr
6464
case <-time.After(200 * time.Millisecond):
6565
case <-sigint:
6666
if !done {
67-
progress.Message(progressOut, "", "Operation continuing in background.")
68-
progress.Message(progressOut, "", "Use `swarmctl cluster inspect default` to check progress.")
67+
_ = progressOut.WriteProgress(progress.Progress{Message: "Operation continuing in background."})
68+
_ = progressOut.WriteProgress(progress.Progress{Message: "Use `swarmctl cluster inspect default` to check progress."})
6969
}
7070
return nil
7171
}

0 commit comments

Comments
 (0)