Have the zookeeper backend use the host port for the service paths, allow publishing services if the base service path already exists, and allow publishing into the root of zookeeper. #367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR solves three problems with the initially committed zookeeper backend.
Problem 1: Znode name for a registrator service is published as the PrivatePort not the PublicPort (or service.Port). This was a mistake when originally writing this and is a pretty bad flaw. The reason this is severe is because we cannot run more than a single container with the same service name and private port, since they cannot both be published in zookeeper.
A quick example, running this ubuntu container:
with registrator configured for
zookeeper://zk:2181/services
publishes this in zookeeper:The path is the base chroot (
/services
), the service name (ubuntu
), then the "PrivatePort" (which isservice.Origin.ExposedPort
in registrator). This needs to beservice.Port
.Problem 2: registrator cannot publish into zookeeper without a chroot style base path. When running this docker-compose.yml:
I get this error
Registrator is attempting create the service node at
//ubuntu
instead of/ubuntu
and fails.Problem 3: The only the first container for a service name is published
This is due to the zookeeper plugin checking if the 'base path' in zookeeper exists (chroot + service name). If it didn't exist, zookeeper creates the node, and then continues to create the service port entries in zookeeper under the service name path. However, the nested logic prevented any publishing from occuring if the base service name path existed. This is incorrect because if the path for the service name exists, registrator should still attempt to publish services for this name.
This PR addresses all three problems. Quick example here for the above docker-compose.yml which was tweaked to run a second ubuntu container (with the same SERVICE_80_name) and modified for a test build of registrator that this PR is for:
The service name is now published correctly into the root of zookeeper (
/ubuntu
) the service znode's name is now the PublicPort instead of the PrivatePort, and we see the services from both containers sharing the name 'ubuntu'. This enables me to run multiple containers for the same service name, after fixing the fact the second container wouldn't publish at all, and the path would have a collision since it used the PrivatePort.