Skip to content

Commit

Permalink
Merge pull request #81 from coroot/nomad_support
Browse files Browse the repository at this point in the history
add support for HashiCorp Nomad
  • Loading branch information
def authored May 8, 2024
2 parents 827e918 + 9d731ec commit c4e4c21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ContainerMetadata struct {
logDecoder logparser.Decoder
hostListens map[string][]netaddr.IPPort
networks map[string]ContainerNetwork
env map[string]string
}

type Delays struct {
Expand Down
12 changes: 12 additions & 0 deletions containers/dockerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func DockerdInspect(containerID string) (*ContainerMetadata, error) {
volumes: map[string]string{},
hostListens: map[string][]netaddr.IPPort{},
networks: map[string]ContainerNetwork{},
env: map[string]string{},
}
for _, m := range c.Mounts {
res.volumes[m.Destination] = common.ParseKubernetesVolumeSource(m.Source)
Expand Down Expand Up @@ -92,6 +93,17 @@ func DockerdInspect(containerID string) (*ContainerMetadata, error) {
}
}
}
if c.Config != nil {
for _, value := range c.Config.Env {
idx := strings.Index(value, "=")
if idx < 0 {
continue
}
k := value[:idx]
v := value[idx+1:]
res.env[k] = v
}
}
return res, nil
}

Expand Down
10 changes: 10 additions & 0 deletions containers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata) ContainerID {
}
return ContainerID(fmt.Sprintf("/swarm/%s/%s/%s", namespace, service, taskNameParts[1]))
}
if md.env != nil {
allocId := md.env["NOMAD_ALLOC_ID"]
group := md.env["NOMAD_GROUP_NAME"]
job := md.env["NOMAD_JOB_NAME"]
namespace := md.env["NOMAD_NAMESPACE"]
task := md.env["NOMAD_TASK_NAME"]
if allocId != "" && group != "" && job != "" && namespace != "" && task != "" {
return ContainerID(fmt.Sprintf("/nomad/%s/%s/%s/%s/%s", namespace, job, group, allocId, task))
}
}
if md.name == "" { // should be "pure" dockerd container here
klog.Warningln("empty dockerd container name for:", cg.ContainerId)
return ""
Expand Down

0 comments on commit c4e4c21

Please sign in to comment.