From 435c464f457c1fca97e05fb77a28be5113cfb164 Mon Sep 17 00:00:00 2001 From: Ian Robertson Date: Wed, 1 Oct 2025 14:48:09 -0500 Subject: [PATCH] Get container name from annotation Signed-off-by: Ian Robertson --- .../go-worker/pkg/container/containerd.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/container/go-worker/pkg/container/containerd.go b/plugins/container/go-worker/pkg/container/containerd.go index a62bfef0..4baba118 100644 --- a/plugins/container/go-worker/pkg/container/containerd.go +++ b/plugins/container/go-worker/pkg/container/containerd.go @@ -2,6 +2,10 @@ package container import ( "context" + "strconv" + "strings" + "sync" + "github.com/containerd/containerd/api/events" containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/core/containers" @@ -11,9 +15,6 @@ import ( "github.com/falcosecurity/plugins/plugins/container/go-worker/pkg/config" "github.com/falcosecurity/plugins/plugins/container/go-worker/pkg/event" "github.com/opencontainers/runtime-spec/specs-go" - "strconv" - "strings" - "sync" ) func init() { @@ -50,6 +51,14 @@ func (c *containerdEngine) ctrToInfo(namespacedContext context.Context, containe } } + // Name related + var containerName string + if name, ok := spec.Annotations["io.kubernetes.cri.container-name"]; ok && name != "" { + containerName = name + } else { + containerName = shortContainerID(container.ID()) + } + // Cpu related var ( cpuPeriod uint64 = defaultCpuPeriod @@ -207,7 +216,7 @@ func (c *containerdEngine) ctrToInfo(namespacedContext context.Context, containe Container: event.Container{ Type: typeContainerd.ToCTValue(), ID: shortContainerID(container.ID()), - Name: shortContainerID(container.ID()), + Name: containerName, Image: info.Image, ImageDigest: imageDigest, ImageRepo: imageRepo,