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

improve error of docker network create -d overlay on non-Swarm node #31912

Merged
merged 1 commit into from Apr 24, 2017

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Mar 17, 2017

- What I did

Improved the error of docker network create -d overlay on non-Swarm node.

before: Error response from daemon: datastore for scope "global" is not initialized
after: Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.

This PR also vendors moby/libnetwork@f6ce0ce (for moby/libnetwork#1707)

- How I did it

Check daemon.clusterProvider during createNetwork().
Also, addedpkg/errorutils for deduplicating error literals.

- How to verify it

docker network create -d overlay on non-Swarm node

- Description for the changelog

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

penguin

Signed-off-by: Akihiro Suda suda.akihiro@lab.ntt.co.jp

@@ -262,6 +263,11 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
driver = c.Config().Daemon.DefaultDriver
}

if driver == "overlay" &&
(daemon.clusterProvider == nil || !daemon.clusterProvider.IsManager()) {
return nil, errorutils.ErrNotSwarmManager
Copy link
Member

Choose a reason for hiding this comment

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

Will this be a problem if someone uses an external k/v store for overlay networks?

@AkihiroSuda
Copy link
Member Author

@thaJeztah
Thank you for pointing out, updated PR to support external cluster store

cc @aboch @mavenugo

@@ -262,6 +263,12 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
driver = c.Config().Daemon.DefaultDriver
}

isSwarmModeManager := daemon.clusterProvider != nil && daemon.clusterProvider.IsManager()
withClusterStore := daemon.configStore.ClusterStore != "" // classic
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure looking up configStore is correct here, but netController does not seem to contain cluster store info

@AkihiroSuda
Copy link
Member Author

Failure on windows and z should be unrelated.

PTAL

@@ -302,6 +303,12 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
driver = c.Config().Daemon.DefaultDriver
}

isSwarmModeManager := daemon.clusterProvider != nil && daemon.clusterProvider.IsManager()
withClusterStore := daemon.configStore.ClusterStore != "" // classic
if driver == "overlay" && !isSwarmModeManager && !withClusterStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @AkihiroSuda, I agree with this change as it will remove the very confusing previous message.
But I think we should not base it on the driver name (overlay), because we support network plugins which can be global scope, therefore working with previous cluster store config and with new swarm.

What do you think about have libnetwork return a well known error in case the datastore is not present
https://github.com/docker/libnetwork/blob/master/store.go#L228
so that you can recognize it at L331 here and return the new error instead ?
You can define the error in https://github.com/docker/libnetwork/blob/master/error.go

@AkihiroSuda
Copy link
Member Author

@aboch
Sure, opened moby/libnetwork#1707

@AkihiroSuda AkihiroSuda changed the title improve error of docker network create -d overlay on non-Swarm node improve error of docker network create -d overlay on non-Swarm node + vendor libnetwork@f6ce0ce Apr 5, 2017
@AkihiroSuda
Copy link
Member Author

vendored moby/libnetwork#1707 in this PR

@AkihiroSuda
Copy link
Member Author

rebased

PTAL @aboch

cc @vdemeester (pkg/errorutils seems weird place to add new error constants?)

@AkihiroSuda AkihiroSuda changed the title improve error of docker network create -d overlay on non-Swarm node + vendor libnetwork@f6ce0ce improve error of docker network create -d overlay on non-Swarm node Apr 10, 2017
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

ping @aboch @mavenugo PTAL

@vdemeester
Copy link
Member

cc @vdemeester (pkg/errorutils seems weird place to add new error constants?)

@AkihiroSuda definitely, it shouldn't be in that package. /cc @dnephin

@AkihiroSuda
Copy link
Member Author

@vdemeester Where is the best place?

@aboch
Copy link
Contributor

aboch commented Apr 10, 2017

Looks good to me

Copy link
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

daemon/errors.go might have worked, but it's used from the CLI. I don't have any better suggetions

@vdemeester
Copy link
Member

@dnephin @AkihiroSuda "daemon/errors.go might have worked, but it's used from the CLI. I don't have any better suggetions" yeah me neither but… having a swarm related error in a pkg package feels not right. We could put it somewhere in opts or another package that is referenced by both cli and daemon side 👼

@AkihiroSuda
Copy link
Member Author

Until 1.12 we had github.com/docker/docker/errors pkg https://github.com/docker/docker/tree/1.12.x/errors

Can we revive this pkg? (with different content)

@thaJeztah
Copy link
Member

If this is all because we want to prevent writing the error message twice; perhaps it's not that bad to just write it twice.

Also; the error message from the CLI could diverge from the error message generated by the daemon (in a way, it's already odd that the daemon/API returns instructions on how to use the CLI, while it doesn't even know what CLI is used)

@thaJeztah
Copy link
Member

(i.e. the "Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again." part is something that the client should add probably)

before: Error response from daemon: datastore for scope "global" is not initialized
after: Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
@AkihiroSuda
Copy link
Member Author

Thank you @thaJeztah , removed errorutils pkg. PTAL.

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 vdemeester merged commit f9311c5 into moby:master Apr 24, 2017
@thaJeztah thaJeztah added this to the 17.06 milestone Apr 24, 2017
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.

None yet

8 participants