Skip to content

Commit c4e4c21

Browse files
authored
Merge pull request #81 from coroot/nomad_support
add support for HashiCorp Nomad
2 parents 827e918 + 9d731ec commit c4e4c21

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

containers/container.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type ContainerMetadata struct {
4343
logDecoder logparser.Decoder
4444
hostListens map[string][]netaddr.IPPort
4545
networks map[string]ContainerNetwork
46+
env map[string]string
4647
}
4748

4849
type Delays struct {

containers/dockerd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func DockerdInspect(containerID string) (*ContainerMetadata, error) {
5656
volumes: map[string]string{},
5757
hostListens: map[string][]netaddr.IPPort{},
5858
networks: map[string]ContainerNetwork{},
59+
env: map[string]string{},
5960
}
6061
for _, m := range c.Mounts {
6162
res.volumes[m.Destination] = common.ParseKubernetesVolumeSource(m.Source)
@@ -92,6 +93,17 @@ func DockerdInspect(containerID string) (*ContainerMetadata, error) {
9293
}
9394
}
9495
}
96+
if c.Config != nil {
97+
for _, value := range c.Config.Env {
98+
idx := strings.Index(value, "=")
99+
if idx < 0 {
100+
continue
101+
}
102+
k := value[:idx]
103+
v := value[idx+1:]
104+
res.env[k] = v
105+
}
106+
}
95107
return res, nil
96108
}
97109

containers/registry.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,16 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata) ContainerID {
391391
}
392392
return ContainerID(fmt.Sprintf("/swarm/%s/%s/%s", namespace, service, taskNameParts[1]))
393393
}
394+
if md.env != nil {
395+
allocId := md.env["NOMAD_ALLOC_ID"]
396+
group := md.env["NOMAD_GROUP_NAME"]
397+
job := md.env["NOMAD_JOB_NAME"]
398+
namespace := md.env["NOMAD_NAMESPACE"]
399+
task := md.env["NOMAD_TASK_NAME"]
400+
if allocId != "" && group != "" && job != "" && namespace != "" && task != "" {
401+
return ContainerID(fmt.Sprintf("/nomad/%s/%s/%s/%s/%s", namespace, job, group, allocId, task))
402+
}
403+
}
394404
if md.name == "" { // should be "pure" dockerd container here
395405
klog.Warningln("empty dockerd container name for:", cg.ContainerId)
396406
return ""

0 commit comments

Comments
 (0)