-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
support show numbers of global service in service ls command #27710
support show numbers of global service in service ls command #27710
Conversation
65c9aea
to
de687d7
Compare
I think
|
Oh, to be honest, your example is better. @AkihiroSuda |
@allencloud SGTM |
It will add a new column for the output maybe need more discussion. WDYT? @thaJeztah @AkihiroSuda @vdemeester |
/cc @thaJeztah @aluzzardi @stevvooe any reason why we did not add |
I agree with having a separate column as well (#27670 (comment)) 😄 |
@@ -116,7 +118,7 @@ func printTable(out io.Writer, services []swarm.Service, running map[string]int) | |||
if service.Spec.Mode.Replicated != nil && service.Spec.Mode.Replicated.Replicas != nil { | |||
replicas = fmt.Sprintf("%d/%d", running[service.ID], *service.Spec.Mode.Replicated.Replicas) | |||
} else if service.Spec.Mode.Global != nil { | |||
replicas = "global" | |||
replicas = fmt.Sprintf("%d/%d global", running[service.ID], tasksPerService[service.ID]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "total" here always using the total node count? If so, that should probably be changed to take constraints into account (which is supported for global services)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, actually it is not the total node count. Here is scene:
- 5 nodes, 2 managers, 3 workers.
- docker service create --constraint node.role==manager ubuntu:14.04 sleep 100000
- before 1.13.0, global service will be every node even if the node does not meet the constraint. While since PR Only create global service tasks on nodes that satisfy the constraints swarmkit#1570, task will only be on nodes which satisfies the constraints. However this PR counts all tasks of a global service, and I think it will be OK for docker version both before 1.13- and 1.13+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since 1.13.0, task of global service will only on node which satisfies constraints. So this PR counts node which only has the corresponding task. PTAL @thaJeztah
1d94a47
to
5c69224
Compare
Added a column already. PTAL @AkihiroSuda @vdemeester @thaJeztah |
design LGTM, but ping @aluzzardi PTAL |
LGTM /cc @dongluochen |
|
||
// first key is service id, the value of first key is a map | ||
// In the second map, key is node ID, value is task number of this service on this node. | ||
tasksPerService := map[string]map[string]int{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid 2D map because we are just interested in the number of tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, what we are interested in is number of tasks in every Service. I think we should classify tasks via different service.
If you have any better ways to implement this, please feel free to tell me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can implement the same thing with a struct-keyed map but I don't see this being accessed by taskID, so I don't quite understand what is being attempted here.
This should be called tasksByService
or taskCountByService
?
ping @dongluochen . PTAL, thanks. 😃 |
1c1fc64
to
d166eb8
Compare
@@ -95,34 +95,51 @@ func PrintNotQuiet(out io.Writer, services []swarm.Service, nodes []swarm.Node, | |||
} | |||
|
|||
running := map[string]int{} | |||
|
|||
// first key is service id, the value of first key is a map | |||
// In the second map, key is task ID, if the task's desired status is not shutdown, it has a value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the map by task ID necessary? Does TaskList
return duplicate tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, Yes, It is unnecessary now. Thanks a lot for your review. PTAL
036671a
to
6b2d8d0
Compare
``` | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra whitespace here. @thaJeztah does this matter in markdown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think it's a problem here, but @allencloud would be nice to clean up 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, Thanks. Now cleaned up this. 😄
LGTM |
6b2d8d0
to
5021c03
Compare
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5021c03
to
5a6c967
Compare
Signed-off-by: allencloud <allen.sun@daocloud.io>
5a6c967
to
ea03f09
Compare
Solve conflict because merging of #28029 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🐯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Leaving the merge for @thaJeztah
oops, late to the party, thanks! |
LGTM |
…vice-in-service-ls support show numbers of global service in service ls command
fixes #27670
make command
docker service ls
show numbers for global services, like :if a sevice's mode is global, actually we can not get the total number of task in this service. Here what I did is that we collect all the tasks, and classify via task.ServiceID. Then we can know that in a service how many tasks are in this service. In addition, we can not simply get the number of nodes to make it the total number of tasks in a service, since user can use constraints in creating global service, then task number in a service may not equal to the number of nodes.
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
Signed-off-by: allencloud allen.sun@daocloud.io