Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit eb8aa70

Browse files
ndegoryDavid Chung
authored andcommitted
Docker engine labels (#486)
Signed-off-by: Nicolas Degory <[email protected]>
1 parent 2779452 commit eb8aa70

File tree

7 files changed

+23
-6
lines changed

7 files changed

+23
-6
lines changed

.swp

20 KB
Binary file not shown.

examples/flavor/swarm/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ This plugin has a schema that looks like this:
1313
"SwarmJoinIP": "192.168.2.200",
1414
"Docker" : {
1515
"Host" : "tcp://192.168.2.200:4243"
16+
},
17+
"EngineLabels": {
18+
"storage": "ssd",
19+
"data": ""
1620
}
1721
}
1822
```
@@ -41,7 +45,7 @@ set -o xtrace
4145
mkdir -p /etc/docker
4246
cat << EOF > /etc/docker/daemon.json
4347
{
44-
"labels": {{ INFRAKIT_LABELS | to_json }}
48+
"labels": {{ INFRAKIT_LABELS | jsonEncode }}
4549
}
4650
EOF
4751

examples/flavor/swarm/flavor.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type Spec struct {
4141
// SwarmJoinIP is the IP for managers and workers to join
4242
SwarmJoinIP string
4343

44+
// Labels to apply on the Docker engine
45+
EngineLabels map[string]string
46+
4447
// Docker holds the connection params to the Docker engine for join tokens, etc.
4548
Docker ConnectInfo
4649
}
@@ -459,8 +462,18 @@ func (c *templateContext) Funcs() []template.Function {
459462
},
460463
{
461464
Name: "INFRAKIT_LABELS",
462-
Description: []string{"The Docker engine labels to be applied for linking the Docker engine to this instance."},
465+
Description: []string{"The Docker engine labels to be applied for linking the Docker engine to this instance, as well as those defined in the flavor spec."},
463466
Func: func() []string {
467+
if len(c.flavorSpec.EngineLabels) > 0 {
468+
out := []string{}
469+
for k, v := range c.flavorSpec.EngineLabels {
470+
out = append(out, fmt.Sprintf("%s=%s", k, v))
471+
}
472+
for k, v := range c.link.Map() {
473+
out = append(out, fmt.Sprintf("%s=%s", k, v))
474+
}
475+
return out
476+
}
464477
return c.link.KVPairs()
465478
},
466479
},

examples/flavor/swarm/manager-init-fast.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -o xtrace
66
mkdir -p /etc/docker
77
cat << EOF > /etc/docker/daemon.json
88
{
9-
"labels": {{ INFRAKIT_LABELS | to_json }}
9+
"labels": {{ INFRAKIT_LABELS | jsonEncode }}
1010
}
1111
EOF
1212

examples/flavor/swarm/manager-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -o xtrace
99
mkdir -p /etc/docker
1010
cat << EOF > /etc/docker/daemon.json
1111
{
12-
"labels": {{ INFRAKIT_LABELS | to_json }}
12+
"labels": {{ INFRAKIT_LABELS | jsonEncode }}
1313
}
1414
EOF
1515

examples/flavor/swarm/worker-init-fast.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -o xtrace
66
mkdir -p /etc/docker
77
cat << EOF > /etc/docker/daemon.json
88
{
9-
"labels": {{ INFRAKIT_LABELS | to_json }}
9+
"labels": {{ INFRAKIT_LABELS | jsonEncode }}
1010
}
1111
EOF
1212

examples/flavor/swarm/worker-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -o xtrace
99
mkdir -p /etc/docker
1010
cat << EOF > /etc/docker/daemon.json
1111
{
12-
"labels": {{ INFRAKIT_LABELS | to_json }}
12+
"labels": {{ INFRAKIT_LABELS | jsonEncode }}
1313
}
1414
EOF
1515

0 commit comments

Comments
 (0)