From 9d731ece0dcc44886666bdf516c1598a8e807308 Mon Sep 17 00:00:00 2001 From: Nikolay Sivko Date: Wed, 8 May 2024 15:00:37 +0300 Subject: [PATCH] add support for HashiCorp Nomad --- containers/container.go | 1 + containers/dockerd.go | 12 ++++++++++++ containers/registry.go | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/containers/container.go b/containers/container.go index a5b0ea3..2a6f2a2 100644 --- a/containers/container.go +++ b/containers/container.go @@ -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 { diff --git a/containers/dockerd.go b/containers/dockerd.go index c6cba40..a65cd95 100644 --- a/containers/dockerd.go +++ b/containers/dockerd.go @@ -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) @@ -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 } diff --git a/containers/registry.go b/containers/registry.go index f020997..4350497 100644 --- a/containers/registry.go +++ b/containers/registry.go @@ -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 ""