userns: Use len to handle empty non-nil slices

When using an old runtime like containerd 1.7, this message is not
implemented and what we get here is an empty non-nil slice. Let's check
the len of the slice instead.

While we are there, let's just return false and no error. In the
following commits we will wrap the error and we didn't find any more
info to add here.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
This commit is contained in:
Rodrigo Campos 2025-05-06 14:54:55 +02:00
parent 88e9d8fe6a
commit e983d3f575

View File

@ -120,8 +120,9 @@ func (kl *Kubelet) ListPodsFromDisk() ([]types.UID, error) {
// user namespaces. // user namespaces.
func (kl *Kubelet) HandlerSupportsUserNamespaces(rtHandler string) (bool, error) { func (kl *Kubelet) HandlerSupportsUserNamespaces(rtHandler string) (bool, error) {
rtHandlers := kl.runtimeState.runtimeHandlers() rtHandlers := kl.runtimeState.runtimeHandlers()
if rtHandlers == nil { if len(rtHandlers) == 0 {
return false, fmt.Errorf("runtime handlers are not set") // The slice is empty if the runtime is old and doesn't support this message.
return false, nil
} }
for _, h := range rtHandlers { for _, h := range rtHandlers {
if h.Name == rtHandler { if h.Name == rtHandler {