From 2d844ea5c8834b93239bd330f53cc43b90e060e0 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sat, 23 Jul 2016 09:58:58 -0700 Subject: [PATCH] Fix partial/full filter issue in `service tasks --filter` This fix tries to address the issue related to 24108 and 24790, and also the case from 24620#issuecomment-233715656 The reason for the failure case in the above mentioned issues is that currently Task names are actually indexed by Service Name (`e.ServiceAnnotations.Name`) To fix it, a pull request in swarmkit (swarmkit/pull/1193) has been opened separately. This fix adds the integration tests for the above mentioned issues. Swarmkit revendoring is needed to completely fix the issues. This fix fixes 24108. This fix fixes 24790. This fix is related to 24620. Signed-off-by: Yong Tang --- command/task/print.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/command/task/print.go b/command/task/print.go index 963aea95ce..b9d6b3eaf4 100644 --- a/command/task/print.go +++ b/command/task/print.go @@ -16,7 +16,7 @@ import ( ) const ( - psTaskItemFmt = "%s\t%s\t%s\t%s\t%s\t%s %s ago\t%s\n" + psTaskItemFmt = "%s\t%s\t%s\t%s\t%s %s ago\t%s\n" maxErrLength = 30 ) @@ -48,11 +48,12 @@ func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task // Ignore flushing errors defer writer.Flush() - fmt.Fprintln(writer, strings.Join([]string{"ID", "NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR"}, "\t")) + fmt.Fprintln(writer, strings.Join([]string{"NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR"}, "\t")) - prevName := "" + prevServiceName := "" + prevSlot := 0 for _, task := range tasks { - serviceValue, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID) + serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID) if err != nil { return err } @@ -61,17 +62,27 @@ func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task return err } - name := serviceValue - if task.Slot > 0 { - name = fmt.Sprintf("%s.%d", name, task.Slot) + name := task.Annotations.Name + // TODO: This is the fallback .. in case task name is not present in + // Annotations (upgraded from 1.12). + // We may be able to remove the following in the future. + if name == "" { + if task.Slot != 0 { + name = fmt.Sprintf("%v.%v.%v", serviceName, task.Slot, task.ID) + } else { + name = fmt.Sprintf("%v.%v.%v", serviceName, task.NodeID, task.ID) + } } // Indent the name if necessary indentedName := name - if prevName == name { + // Since the new format of the task name is .., we should only compare + // and here. + if prevServiceName == serviceName && prevSlot == task.Slot { indentedName = fmt.Sprintf(" \\_ %s", indentedName) } - prevName = name + prevServiceName = serviceName + prevSlot = task.Slot // Trim and quote the error message. taskErr := task.Status.Err @@ -85,7 +96,6 @@ func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task fmt.Fprintf( writer, psTaskItemFmt, - task.ID, indentedName, task.Spec.ContainerSpec.Image, nodeValue,