Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --format to docker service ls #28199

Merged
merged 1 commit into from
Feb 2, 2017

Conversation

yongtang
Copy link
Member

@yongtang yongtang commented Nov 9, 2016

- What I did

This fix tries to improve the display of docker service ls and adds --format flag to docker service ls.

In addition to --format flag, several other improvement:

  1. Adds --no-trunc to docker service ls
  2. Updates docker stacks service.
  3. Adds servicesFormat to config file.

Related docs has been updated.

cc @thaJeztah @vdemeester @dnephin

- A picture of a cute animal (not mandatory but encouraged)

1223

Signed-off-by: Yong Tang yong.tang.github@outlook.com

@AkihiroSuda
Copy link
Member

SGTM, can you add tests?

@vdemeester
Copy link
Member

Design SGTM 👼

@@ -40,6 +36,8 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {

flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate the output")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should consider introducing ShortID and/or TruncID placeholders. The TruncID placeholder has the behavior of what ID has now (so, truncated by default, but show full ID if --trunc is added. That way people can define a template where the output always has the full-id, or has an ID that can be truncated or full.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah does that mean we will leave ID alone regardless of --no-trunc=false/true, and only trunc TruncID based on --no-trunc=true?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yongtang perhaps, yes. My initial thought was "do we need a --no-trunc flag? That's when I started thinking if we perhaps need other options for the format.

It's just a thought though, so perhaps @vdemeester or @dnephin has some thoughts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same though as @thaJeztah, I don't really like --no-trunc flag, especially since format uses go template. We could provide a function that shorten "or not" the ID : --format="{{ .ID | shorten }}" or something like that.

@yongtang yongtang force-pushed the 11062016-service-ls-format branch from 1e001a5 to c5ba328 Compare November 9, 2016 15:01
@yongtang
Copy link
Member Author

yongtang commented Nov 9, 2016

@AkihiroSuda Added a test for the PR.

@thaJeztah
Copy link
Member

Design LGTM, let's keep #28199 (comment) for another discussion

@vdemeester
Copy link
Member

ping @yongtang, needs a rebase 👼

@yongtang yongtang force-pushed the 11062016-service-ls-format branch from c5ba328 to 9113044 Compare January 13, 2017 03:33
@yongtang
Copy link
Member Author

Thanks @vdemeester. The PR has been rebased.

@AkihiroSuda
Copy link
Member

00:00:59.032 Errors from golint:
00:00:59.032 cli/command/service/list.go:94:1: comment on exported function GetServicesStatus should be of the form "GetServicesStatus ..."
00:00:59.032 
00:00:59.032 Please fix the above errors. You can test via "golint" and commit the result.

@yongtang yongtang force-pushed the 11062016-service-ls-format branch from 9113044 to c411a9b Compare January 13, 2017 04:11
@yongtang
Copy link
Member Author

Thanks @AkihiroSuda. The PR has been updated with golint issue addressed.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments 👼
I do agree with @thaJeztah on the --no-trunc flags (on other commands as well but 😅)

@@ -40,6 +36,8 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {

flags := cmd.Flags()
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate the output")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same though as @thaJeztah, I don't really like --no-trunc flag, especially since format uses go template. We could provide a function that shorten "or not" the ID : --format="{{ .ID | shorten }}" or something like that.

}
mode[service.ID] = "global"
replicas[service.ID] = fmt.Sprintf("%d/%d", running[service.ID], tasksNoShutdown[service.ID])
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else is empty right ? should go 👼

// Besides this, command `docker stack services xxx` will call this, too.
func PrintNotQuiet(out io.Writer, services []swarm.Service, nodes []swarm.Node, tasks []swarm.Task) {
// GetServicesStatus returns a map of mode and replicas
func GetServicesStatus(services []swarm.Service, nodes []swarm.Node, tasks []swarm.Task) (map[string]string, map[string]string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should/Could this return a map of struct instead, with mode and replica in the struct, instead of two maps ? 👼

@yongtang yongtang force-pushed the 11062016-service-ls-format branch 3 times, most recently from 45533cd to 09edc91 Compare January 14, 2017 03:02
@yongtang
Copy link
Member Author

yongtang commented Jan 14, 2017

@vdemeester @thaJeztah Thanks for the review. The PR has been updated and now --no-trunc are replaced with template func of shorten. Please take a look and let me know if there are any issues.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐸

@@ -1630,3 +1630,33 @@ func (s *DockerSwarmSuite) TestSwarmInitWithDrain(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, "Drain")
}

func (s *DockerSwarmSuite) TestSwarmServiceListFormat(c *check.C) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder this test can be moved to UT, but it can be another PR in the future

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👍

`.ID` | Service ID
`.Name` | Service name
`.Mode` | Service mode (replicated, global)
`.Replicas` | Service replicas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder we should have two separate placeholders e.g. RunningReplicas and AllReplicas.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda I feel like that means we introduce new concepts that does not necessary match the existing Table header. Should we change the table header to RUNNING/ALL REPLICAS? Or maybe we could leave it alone for now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is ok to introduce all .Replicas, .RunningReplicas, and .AllReplicas.
But it is ok to leave it alone for now.

@yongtang yongtang force-pushed the 11062016-service-ls-format branch from 09edc91 to 6bf3b16 Compare January 20, 2017 21:05
@yongtang
Copy link
Member Author

Thanks @thaJeztah. The PR has been updated. Also created another PR #30484 for shorten. Please take a look.

Also in this PR I didn't add the --no-trunc flag and the output of ID will be truncated by default (same as old behavior). Please let me know if we want to introduce --no-trunc in this PR, or we want to have the full ID output by default (behavior will be different from original).

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐯

@vdemeester
Copy link
Member

Moving to docs-review
/cc @thaJeztah

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yongtang Could you update docs/reference/commandline/cli.md to add an example for ServicesFormat ?

@yongtang
Copy link
Member Author

yongtang commented Feb 1, 2017

Thanks @vdemeester. The docs has been updated in the PR. Please take a look and let me know if there are any issues.

@yongtang yongtang force-pushed the 11062016-service-ls-format branch from e60ec5d to 90e4711 Compare February 1, 2017 16:32
This fix tries to improve the display of `docker service ls`
and adds `--format` flag to `docker service ls`.

In addition to `--format` flag, several other improvement:
1. Updates `docker stacks service`.
2. Adds `servicesFormat` to config file.

Related docs has been updated.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
@yongtang yongtang force-pushed the 11062016-service-ls-format branch from 90e4711 to 000f040 Compare February 1, 2017 16:34
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs LGTM 🐸
/cc @thaJeztah for docs revisit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants