Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions cli/command/service/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func terminalState(state swarm.TaskState) bool {
//
//nolint:gocyclo
func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID string, progressWriter io.WriteCloser) error {
defer progressWriter.Close()
defer func() { _ = progressWriter.Close() }()

progressOut := streamformatter.NewJSONProgressOutput(progressWriter, false)

Expand Down Expand Up @@ -118,7 +118,7 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID
return fmt.Errorf("service update paused: %s", res.Service.UpdateStatus.Message)
case swarm.UpdateStateRollbackStarted:
if !rollback && res.Service.UpdateStatus.Message != "" {
progressOut.WriteProgress(progress.Progress{
_ = progressOut.WriteProgress(progress.Progress{
ID: "rollback",
Action: res.Service.UpdateStatus.Message,
})
Expand Down Expand Up @@ -169,7 +169,7 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID
// use the presence of this field to check if the service is a job
// here.
if res.Service.JobStatus != nil {
progress.Message(progressOut, "", "job complete")
_ = progressOut.WriteProgress(progress.Progress{Message: "job complete"})
return nil
}

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

func writeOverallProgress(progressOut progress.Output, numerator, denominator int, rollback bool) {
if rollback {
progressOut.WriteProgress(progress.Progress{
_ = progressOut.WriteProgress(progress.Progress{
ID: "overall progress",
Action: fmt.Sprintf("rolling back update: %d out of %d tasks", numerator, denominator),
})
return
}
progressOut.WriteProgress(progress.Progress{
_ = progressOut.WriteProgress(progress.Progress{
ID: "overall progress",
Action: fmt.Sprintf("%d out of %d tasks", numerator, denominator),
})
Expand Down Expand Up @@ -305,7 +305,10 @@ func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm.

if replicas <= maxProgressBars {
for i := uint64(1); i <= replicas; i++ {
progress.Update(u.progressOut, fmt.Sprintf("%d/%d", i, replicas), " ")
_ = u.progressOut.WriteProgress(progress.Progress{
ID: fmt.Sprintf("%d/%d", i, replicas),
Action: " ",
})
}
}
u.initialized = true
Expand Down Expand Up @@ -388,15 +391,15 @@ func (u *replicatedProgressUpdater) writeTaskProgress(task swarm.Task, mappedSlo
}

if task.Status.Err != "" {
u.progressOut.WriteProgress(progress.Progress{
_ = u.progressOut.WriteProgress(progress.Progress{
ID: fmt.Sprintf("%d/%d", mappedSlot, replicas),
Action: truncError(task.Status.Err),
})
return
}

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

if task.Status.Err != "" {
u.progressOut.WriteProgress(progress.Progress{
_ = u.progressOut.WriteProgress(progress.Progress{
ID: formatter.TruncateID(task.NodeID),
Action: truncError(task.Status.Err),
})
return
}

if !terminalState(task.DesiredState) && !terminalState(task.Status.State) {
u.progressOut.WriteProgress(progress.Progress{
_ = u.progressOut.WriteProgress(progress.Progress{
ID: formatter.TruncateID(task.NodeID),
Action: fmt.Sprintf("%-[1]*s", longestState, task.Status.State),
Current: numberedStates[task.Status.State],
Expand Down Expand Up @@ -593,7 +596,7 @@ func (u *replicatedJobProgressUpdater) update(_ swarm.Service, tasks []swarm.Tas
// only write out progress bars if there will be less than the maximum
if u.total <= maxProgressBars {
for i := 1; i <= u.total; i++ {
u.progressOut.WriteProgress(progress.Progress{
_ = u.progressOut.WriteProgress(progress.Progress{
ID: fmt.Sprintf("%d/%d", i, u.total),
Action: " ",
})
Expand Down
10 changes: 5 additions & 5 deletions cli/command/swarm/progress/root_rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func RootRotationProgress(ctx context.Context, apiClient client.APIClient, progr
defer signal.Stop(sigint)

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

var done bool

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