Skip to content

Commit a428800

Browse files
committed
service/progress: ServiceProgress: avoid fuzzy matching service ID in loop
Tasks with a service filter will result in the daemon performing a lookup of the full service ID, then updating the provided filter with the actual ID: https://github.com/moby/moby/blob/96ded2a1badcc5cb99d6d2ab7904d6f9e527cc4b/daemon/cluster/tasks.go#L15-L30 The `getService()` helper has a fast-path for situations where the given filter is a full ID, before falling back to fuzzy-logic to search filters by service name or prefix, which would return an error if the result is ambiguous; https://github.com/moby/moby/blob/96ded2a1badcc5cb99d6d2ab7904d6f9e527cc4b/daemon/cluster/helpers.go#L62-L81 The loop executed here calls `client.ServiceInspectWithRaw()` to get info of the service, and that method is ultimately calling the exact same `getService()` helper on the daemon side, which means that we don't need to repeat the work; we can use the `Service.ID` resolved from that call, and use it to apply as filter for listing the tasks. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent e88b193 commit a428800

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

cli/command/service/progress/progress.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID
7979
signal.Notify(sigint, os.Interrupt)
8080
defer signal.Stop(sigint)
8181

82-
taskFilter := filters.NewArgs()
83-
taskFilter.Add("service", serviceID)
84-
taskFilter.Add("_up-to-date", "true")
85-
86-
getUpToDateTasks := func() ([]swarm.Task, error) {
87-
return apiClient.TaskList(ctx, types.TaskListOptions{Filters: taskFilter})
88-
}
89-
9082
var (
9183
updater progressUpdater
9284
converged bool
@@ -151,7 +143,10 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID
151143
return nil
152144
}
153145

154-
tasks, err := getUpToDateTasks()
146+
tasks, err := apiClient.TaskList(ctx, types.TaskListOptions{Filters: filters.NewArgs(
147+
filters.KeyValuePair{Key: "service", Value: service.ID},
148+
filters.KeyValuePair{Key: "_up-to-date", Value: "true"},
149+
)})
155150
if err != nil {
156151
return err
157152
}
@@ -218,7 +213,10 @@ func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID
218213
}
219214
}
220215

221-
func getActiveNodes(ctx context.Context, apiClient client.APIClient) (map[string]struct{}, error) {
216+
// getActiveNodes returns all nodes that are currently not in status [swarm.NodeStateDown].
217+
//
218+
// TODO(thaJeztah): this should really be a filter on [apiClient.NodeList] instead of being filtered on the client side.
219+
func getActiveNodes(ctx context.Context, apiClient client.NodeAPIClient) (map[string]struct{}, error) {
222220
nodes, err := apiClient.NodeList(ctx, types.NodeListOptions{})
223221
if err != nil {
224222
return nil, err

0 commit comments

Comments
 (0)