Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for HashiCorp Nomad #81

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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