Skip to content

Commit

Permalink
cgidimap: skip warning if cgidmap is disabled
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kkourt committed Sep 4, 2024
1 parent 77b5ec9 commit 8e4feb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pkg/cgidmap/cgidmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package cgidmap

import (
"errors"
"sync"

"github.com/cilium/tetragon/pkg/logger"
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/cgidmap/podhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down

0 comments on commit 8e4feb4

Please sign in to comment.