1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

cluster/container: correctly name swarm tasks

Even after a slew of PRs, this still wasn't quite right. Now, we ensure
the task name is calculared in one place in the executor, as least.

We'll have to follow this up once the `api/naming` package from SwarmKit
lands.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2016-10-25 14:17:57 -07:00
parent 6e462412d7
commit 3b1af17518
No known key found for this signature in database
GPG key ID: FB5F6B2905D7ECF3

View file

@ -104,8 +104,13 @@ func (c *containerConfig) name() string {
return c.task.Annotations.Name
}
slot := fmt.Sprint(c.task.Slot)
if slot == "" || c.task.Slot == 0 {
slot = c.task.NodeID
}
// fallback to service.slot.id.
return strings.Join([]string{c.task.ServiceAnnotations.Name, fmt.Sprint(c.task.Slot), c.task.ID}, ".")
return fmt.Sprintf("%s.%s.%s", c.task.ServiceAnnotations.Name, slot, c.task.ID)
}
func (c *containerConfig) image() string {
@ -143,19 +148,11 @@ func (c *containerConfig) config() *enginecontainer.Config {
}
func (c *containerConfig) labels() map[string]string {
taskName := c.task.Annotations.Name
if taskName == "" {
if c.task.Slot != 0 {
taskName = fmt.Sprintf("%v.%v.%v", c.task.ServiceAnnotations.Name, c.task.Slot, c.task.ID)
} else {
taskName = fmt.Sprintf("%v.%v.%v", c.task.ServiceAnnotations.Name, c.task.NodeID, c.task.ID)
}
}
var (
system = map[string]string{
"task": "", // mark as cluster task
"task.id": c.task.ID,
"task.name": taskName,
"task.name": c.name(),
"node.id": c.task.NodeID,
"service.id": c.task.ServiceID,
"service.name": c.task.ServiceAnnotations.Name,