mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Set the node host name to default task label
Signed-off-by: JieJhih Jhang <aawer12345tw@yahoo.com.tw>
This commit is contained in:
@@ -43,6 +43,7 @@ const (
|
||||
// components.
|
||||
type containerConfig struct {
|
||||
task *api.Task
|
||||
node *api.NodeDescription
|
||||
networksAttachments map[string]*api.NetworkAttachment
|
||||
}
|
||||
|
||||
@@ -76,6 +77,7 @@ func (c *containerConfig) setTask(t *api.Task, node *api.NodeDescription) error
|
||||
}
|
||||
|
||||
c.task = t
|
||||
c.node = node
|
||||
|
||||
if t.Spec.GetContainer() != nil {
|
||||
preparedSpec, err := template.ExpandContainerSpec(node, t)
|
||||
@@ -234,12 +236,13 @@ func (c *containerConfig) config() *enginecontainer.Config {
|
||||
func (c *containerConfig) labels() map[string]string {
|
||||
var (
|
||||
system = map[string]string{
|
||||
"task": "", // mark as cluster task
|
||||
"task.id": c.task.ID,
|
||||
"task.name": c.name(),
|
||||
"node.id": c.task.NodeID,
|
||||
"service.id": c.task.ServiceID,
|
||||
"service.name": c.task.ServiceAnnotations.Name,
|
||||
"task": "", // mark as cluster task
|
||||
"task.id": c.task.ID,
|
||||
"task.name": c.name(),
|
||||
"node.id": c.task.NodeID,
|
||||
"node.hostname": c.node.Hostname,
|
||||
"service.id": c.task.ServiceID,
|
||||
"service.name": c.task.ServiceAnnotations.Name,
|
||||
}
|
||||
labels = make(map[string]string)
|
||||
)
|
||||
|
||||
@@ -44,13 +44,14 @@ func TestContainerLabels(t *testing.T) {
|
||||
Runtime: &swarmapi.TaskSpec_Container{
|
||||
Container: &swarmapi.ContainerSpec{
|
||||
Labels: map[string]string{
|
||||
"com.docker.swarm.task": "user-specified-task",
|
||||
"com.docker.swarm.task.id": "user-specified-task.id",
|
||||
"com.docker.swarm.task.name": "user-specified-task.name",
|
||||
"com.docker.swarm.node.id": "user-specified-node.id",
|
||||
"com.docker.swarm.service.id": "user-specified-service.id",
|
||||
"com.docker.swarm.service.name": "user-specified-service.name",
|
||||
"this-is-a-user-label": "this is a user label's value",
|
||||
"com.docker.swarm.task": "user-specified-task",
|
||||
"com.docker.swarm.task.id": "user-specified-task.id",
|
||||
"com.docker.swarm.task.name": "user-specified-task.name",
|
||||
"com.docker.swarm.node.id": "user-specified-node.id",
|
||||
"com.docker.swarm.node.hostname": "user-specified-node.hostname",
|
||||
"com.docker.swarm.service.id": "user-specified-service.id",
|
||||
"com.docker.swarm.service.name": "user-specified-service.name",
|
||||
"this-is-a-user-label": "this is a user label's value",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -65,16 +66,20 @@ func TestContainerLabels(t *testing.T) {
|
||||
Name: "real-service.name",
|
||||
},
|
||||
},
|
||||
node: &swarmapi.NodeDescription{
|
||||
Hostname: "real-node.hostname",
|
||||
},
|
||||
}
|
||||
|
||||
expected := map[string]string{
|
||||
"com.docker.swarm.task": "",
|
||||
"com.docker.swarm.task.id": "real-task.id",
|
||||
"com.docker.swarm.task.name": "real-service.name.123.real-task.id",
|
||||
"com.docker.swarm.node.id": "real-node.id",
|
||||
"com.docker.swarm.service.id": "real-service.id",
|
||||
"com.docker.swarm.service.name": "real-service.name",
|
||||
"this-is-a-user-label": "this is a user label's value",
|
||||
"com.docker.swarm.task": "",
|
||||
"com.docker.swarm.task.id": "real-task.id",
|
||||
"com.docker.swarm.task.name": "real-service.name.123.real-task.id",
|
||||
"com.docker.swarm.node.id": "real-node.id",
|
||||
"com.docker.swarm.node.hostname": "real-node.hostname",
|
||||
"com.docker.swarm.service.id": "real-service.id",
|
||||
"com.docker.swarm.service.name": "real-service.name",
|
||||
"this-is-a-user-label": "this is a user label's value",
|
||||
}
|
||||
|
||||
labels := c.labels()
|
||||
|
||||
Reference in New Issue
Block a user