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

Export stack commands #1519

Merged
merged 1 commit into from
Jan 23, 2019
Merged

Conversation

silvin-lubecki
Copy link
Contributor

@silvin-lubecki silvin-lubecki commented Nov 14, 2018

- What I did
Export stack commands for vendoring and extract/factorize common code.

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

image

@codecov-io
Copy link

codecov-io commented Nov 14, 2018

Codecov Report

Merging #1519 into master will increase coverage by 0.06%.
The diff coverage is 55.55%.

@@            Coverage Diff             @@
##           master    #1519      +/-   ##
==========================================
+ Coverage   55.16%   55.22%   +0.06%     
==========================================
  Files         301      301              
  Lines       20384    20377       -7     
==========================================
+ Hits        11244    11253       +9     
+ Misses       8335     8318      -17     
- Partials      805      806       +1

Copy link
Collaborator

@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.

@silvin-lubecki I guess it's required for docker/app or things like that ? 👼

cli/command/stack/common.go Outdated Show resolved Hide resolved
@silvin-lubecki
Copy link
Contributor Author

Yep good guess @vdemeester 😄

cli/command/stack/deploy.go Outdated Show resolved Hide resolved
cli/command/stack/ps.go Outdated Show resolved Hide resolved
cli/command/stack/remove.go Outdated Show resolved Hide resolved
cli/command/stack/services.go Outdated Show resolved Hide resolved
Factorize orchestrator switch among stack commands.

Signed-off-by: Silvin Lubecki <[email protected]>
@silvin-lubecki
Copy link
Contributor Author

@simonferquel @vdemeester PTAL, I rebased and cleaned this PR 🦁

@simonferquel
Copy link
Contributor

LGTM

Copy link
Collaborator

@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 🐯
/cc @thaJeztah

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

lgtm, but see my comment inline; I'm not sure this is fully the right direction to go in

@vdemeester any suggestions?

@@ -35,7 +35,8 @@ func newListCommand(dockerCli command.Cli, common *commonOptions) *cobra.Command
return cmd
}

func runList(cmd *cobra.Command, dockerCli command.Cli, opts options.List, orchestrator command.Orchestrator) error {
// RunList performs a stack list against the specified orchestrator
func RunList(cmd *cobra.Command, dockerCli command.Cli, opts options.List, orchestrator command.Orchestrator) error {
Copy link
Member

Choose a reason for hiding this comment

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

Only concern I have with exporting all of these is that;

  • These functions now become a public "API", with no interface defined for them
    • this can complicate making changes in the CLI (they were kept non-exported, as their signature/interface was not "stable")
  • Some of these functions actually have a "UX" component built-in (e.g. they print confirmation messages on stdout/stderr, have an option to print formatted output); is that really suitable for external consumption?
    • calling these commands would become almost equivalent to exec.Cmd("docker stack ls")

For the underlying code on the other hand, we have various interfaces defined; if those are lacking functionality that's needed, should we review those interfaces, and make that the API to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the underlying code on the other hand, we have various interfaces defined; if those are lacking functionality that's needed, should we review those interfaces, and make that the API to use?

I guess you can see these functions as a Facade, a simple API endpoint for a simple use, but if you have a more advanced use case, you can still rely on the underlying interfaces (like if you only want to talk to Swarm and don't care about Kubernetes). Otherwise if you want the same behavior, you need to replicate this complicated switch kubernetes/swarm.

Some of these functions actually have a "UX" component built-in (e.g. they print confirmation messages on stdout/stderr, have an option to print formatted output); is that really suitable for external consumption?
calling these commands would become almost equivalent to exec.Cmd("docker stack ls")

That is exactly the purpose of this PR: someone who vendors the docker/cli can benefit the same look-and-feel (and behavior) as the "real" docker-cli binary, without relying on the binary itself.

These functions now become a public "API", with no interface defined for them
this can complicate making changes in the CLI (they were kept non-exported, as their signature/interface was not "stable")

I think these signatures are simple and somehow stable. I don't have a crystal ball but my 2 cts is that they won't be modified before a long time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, I do agree with @thaJeztah and also @silvin-lubecki 😅 🙃

I think our client API is too low-level, and we need to export those because of that 😅
We may define better APIs in the future (that would not have cobra.Command or comand.Cli in the method signature) for example.

I think it's the less worse we can do for now 👼 so, still LGTM 👼

Copy link
Member

Choose a reason for hiding this comment

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

was discussing with @chris-crone to add a note somewhere (perhaps the readme) to indicate that these functions, even though they're exported, should not be considered a stable API (as in; their signature can change, and shouldn't be relied on)

We could also add notes to the GoDoc of these, similar to https://golang.org/pkg/testing/#RunTests

An internal function but exported because it is cross-package; part of the implementation of the "go test" command.

But that would be a bit more work to do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was discussing with @chris-crone to add a note somewhere (perhaps the readme) to indicate that these functions, even though they're exported, should not be considered a stable API (as in; their signature can change, and shouldn't be relied on)

Will do that in a follow-up 👍

@vdemeester vdemeester merged commit 4d5f8ea into docker:master Jan 23, 2019
@GordonTheTurtle GordonTheTurtle added this to the 19.03.0 milestone Jan 23, 2019
@silvin-lubecki silvin-lubecki deleted the export-stack-commands branch January 23, 2019 10:19
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.

6 participants