Skip to content

Commit

Permalink
cgidmap: do not panic if cri is not enabled
Browse files Browse the repository at this point in the history
cgidmap requires cri for pod association to work with existing pods.
Currently, if cri is not enabled the cgidmap code will panic:

E0904 10:02:54.892524   22765 runtime.go:79] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference)
goroutine 13 [running]:
k8s.io/apimachinery/pkg/util/runtime.logPanic({0x276f260, 0x4a09c00})
        /home/kkourt/src/tetragon/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:75 +0x85
k8s.io/apimachinery/pkg/util/runtime.HandleCrash({0x0, 0x0, 0xc004fd3340?})
        /home/kkourt/src/tetragon/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:49 +0x6b
panic({0x276f260?, 0x4a09c00?})
        /opt/go/src/runtime/panic.go:770 +0x132
github.com/cilium/tetragon/pkg/cgidmap.(*criResolver).enqeue(0x0, {0xc005434f20, 0xc004fdfb28?, 0x40?})

This commit adds a nil check to avoid the panic and issues a warning if
cri is not enabled but cgidmap is.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Sep 4, 2024
1 parent 94839ba commit 77b5ec9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/cgidmap/cgidmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func newMap() (*cgidm, error) {
var criResolver *criResolver
if option.Config.EnableCRI {
criResolver = newCriResolver(m)
} else {
logger.GetLogger().Warn("cgidmap is enabled but cri is not. This means that pod association will not work for existing pods. You can enable cri using --enable-cri")
}
m.criResolver = criResolver
return m, nil
Expand Down Expand Up @@ -234,7 +236,9 @@ func (m *cgidm) Update(podID PodID, contIDs []ContainerID) {
contID: id,
})
}
m.criResolver.enqeue(unmappedIDs)
if m.criResolver != nil {
m.criResolver.enqeue(unmappedIDs)
}
}

// Global state
Expand Down

0 comments on commit 77b5ec9

Please sign in to comment.