From 8e4feb4e8091756332683ab5809f9b22f60a251e Mon Sep 17 00:00:00 2001 From: Kornilios Kourtis Date: Wed, 4 Sep 2024 12:20:45 +0200 Subject: [PATCH] cgidimap: skip warning if cgidmap is disabled Currently, if cgidmap is disabled (this is the default), the agent issues the following warning: level=warning msg="failed to retrieve cgidmap, not registering rthook" error="cgidmap disabled" This commit changes the message to indicate that this actually happens in the podhook and, also, does not emit a warning if the error is that cgidmap is disabled. Signed-off-by: Kornilios Kourtis --- pkg/cgidmap/cgidmap.go | 11 +++++++++-- pkg/cgidmap/podhooks.go | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/cgidmap/cgidmap.go b/pkg/cgidmap/cgidmap.go index 1e55a48f391..529fe19487c 100644 --- a/pkg/cgidmap/cgidmap.go +++ b/pkg/cgidmap/cgidmap.go @@ -8,7 +8,6 @@ package cgidmap import ( - "errors" "sync" "github.com/cilium/tetragon/pkg/logger" @@ -249,12 +248,20 @@ var ( setGlMap sync.Once ) +type cgidDisabledTy struct{} + +var cgidDisabled = &cgidDisabledTy{} + +func (e *cgidDisabledTy) Error() string { + return "cgidmap disabled" +} + // GetState returns the global map func GlobalMap() (Map, error) { setGlMap.Do(func() { if !option.Config.EnableCgIDmap { glMap = nil - glError = errors.New("cgidmap disabled") + glError = cgidDisabled return } diff --git a/pkg/cgidmap/podhooks.go b/pkg/cgidmap/podhooks.go index 47874711099..6082e0eae41 100644 --- a/pkg/cgidmap/podhooks.go +++ b/pkg/cgidmap/podhooks.go @@ -4,6 +4,8 @@ package cgidmap import ( + "errors" + "github.com/cilium/tetragon/pkg/logger" "github.com/cilium/tetragon/pkg/podhelpers" "github.com/cilium/tetragon/pkg/podhooks" @@ -26,7 +28,10 @@ func registerPodCallbacks(podInformer cache.SharedIndexInformer) { m, err := GlobalMap() if err != nil { - logger.GetLogger().WithError(err).Warn("failed to retrieve cgidmap, not registering rthook") + // if cgidmap is disabled, an error is expected so do not omit a warning + if !errors.Is(err, cgidDisabled) { + logger.GetLogger().WithError(err).Warn("failed to retrieve cgidmap, not registering podhook") + } return }