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 swarm Is Leader field to docker info #25065

Open
kencochrane opened this issue Jul 26, 2016 · 8 comments
Open

Add swarm Is Leader field to docker info #25065

kencochrane opened this issue Jul 26, 2016 · 8 comments
Labels
area/swarm kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.
Milestone

Comments

@kencochrane
Copy link
Contributor

Right now docker info will return if a node is a swarm manager, but it doesn't say if that node is the leader node or not.

Swarm: active
 NodeID: 2bf7ukd8dj209nbepgyvg3ngh
 Is Manager: true
 Managers: 3
 Nodes: 4
 Node Address: 192.168.33.216

There is a way to find out by doing docker node inspect self -f "{{ .ManagerStatus.Leader }}" but this will not work on worker nodes, only manager nodes, since the node inspect isn't available on worker nodes.

So you need to make two calls, find out if the node is a manager, and if so, then make the second call to find out if the node is a leader. Adding it to Docker info, will make it only one call, and it will work for both workers and managers.

End result would look like this.

Swarm: active
 NodeID: 2bf7ukd8dj209nbepgyvg3ngh
 Is Manager: true
 Is Leader: false
 Managers: 3
 Nodes: 4
 Node Address: 192.168.33.216

If this seems reasonable, I can submit a PR, but I will need a little help to point me in the right direction for where the change needs to happen, I'm guessing there might need to be a swarmkit change as well?

@aluzzardi

@yongtang
Copy link
Member

yongtang commented Jul 26, 2016

@kencochrane
Copy link
Contributor Author

@yongtang yes, you can call it like this. docker node inspect self -f "{{ .ManagerStatus.Leader }}" but like I mentioned above, it would be nice to have that info on the docker info command instead of having to make two different calls.

@abronan
Copy link
Contributor

abronan commented Jul 26, 2016

This field would be useless for Workers though (as in the information is only useful for Managers). Does this mean that we should only show the field when you are a Manager?

Also the proper way I think to get those types of information and query for the Leader is to use the /nodes api endpoint (ref). You can get all the informations you need with docker node ls.

The problem being that you only get this on Managers. But we can think about giving limited access to the Agents to proxy their requests (to list manager nodes, etc.) to the Manager they are connected to. Then in one call you know if you are a Manager or not but also who is the Leader in the cluster. docker node ls would be accessible from any node.

@abronan abronan added area/swarm kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels Jul 26, 2016
@kencochrane
Copy link
Contributor Author

This field would be useless for Workers though (as in the information is only useful for Managers). Does this mean that we should only show the field when you are a Manager?

@abronan you could either only show the Is Leader field when it a manager, or we can default to false when a worker (since if it's a worker then it's obviously not a leader), so that it's always there. There are already some fields that only show up in docker info, when it is a manager, so this isn't something that is new.

Also the proper way I think to get those types of information and query for the Leader is to use the /nodes api endpoint (ref). You can get all the informations you need with docker node ls.

The docker node commands aren't available when you are a worker, even so, the information isn't very helpful from the CLI, because it just shows a * for the leader, and it is hard to parse the CLI output to find which record is the star.

The problem being that you only get this on Managers. But we can think about giving limited access to the Agents to proxy their requests (to list manager nodes, etc.) to the Manager they are connected to. Then in one call you know if you are a Manager or not but also who is the Leader in the cluster. docker node ls would be accessible from any node.

That would be helpful, it would reduce the number of lookups required to find out if a node is a leader. Another thing that would be great (which this would now allow), is the ability to get the ClusterID in docker info for worker nodes as well. Today that is only available on docker info for manager nodes.

@aaronlehmann
Copy link
Contributor

What's the use case for figuring out which node is the leader? It should be pretty transparent to the user. The only time I use it is testing the code ("what happens if i kill the leader?")

The docker node commands aren't available when you are a worker, even so, the information isn't very helpful from the CLI, because it just shows a * for the leader, and it is hard to parse the CLI output to find which record is the star.

The * indicates which node you are running the command against. The leader has Leader printed in the Manager column.

@kencochrane
Copy link
Contributor Author

kencochrane commented Jul 27, 2016

We need to know if the current node is the leader for docker for aws and docker for azure.

The servers don't know anything and we use the docker info commands to find out if it is a worker or manager node, and if manager if it is the leader.

It comes into play when we upgrade the servers, we need to know if the node is the current leader so that we can make sure we don't cause any problems during the upgrade.

We also run some commands only on the leader node, so knowing which node is the leader is important for this.

These are all scripted against the CLI, so getting the data easily is important.

Sorry about the confusion around the * I think it was like that in old versions of swarmkit. The CLI changes so often, it is hard to keep it all straight.

@kencochrane
Copy link
Contributor Author

FYI: Comments from another PR that led to this issue getting created.

#24492 (comment) and #24492 (comment)

@briceburg
Copy link

As a workaround, you can use docker node ls --format and grep to determine the current node's leadership status until this is implemented;

docker node ls --format "{{.Self }} {{.ManagerStatus}}" | grep -q "true Leader" && \
  echo "I am the leader"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/swarm kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.
Projects
None yet
Development

No branches or pull requests

6 participants