Skip to content

Commit c0eb9e3

Browse files
committed
userns: Improve error returned if userns is not supported
This makes it clear the error comes due to a user namespace configuration. Otherwise the error returned looks too generic and is not clear. Before this PR, the error was: Warning FailedCreatePodSandBox 1s kubelet Failed to create pod sandbox: the handler "" is not known Now it is: Warning FailedCreatePodSandBox 1s kubelet Failed to create pod sandbox: runtime does not support user namespaces Signed-off-by: Rodrigo Campos <[email protected]>
1 parent e983d3f commit c0eb9e3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/kubelet/userns/userns_manager.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,15 @@ func (m *UsernsManager) GetOrCreateUserNamespaceMappings(pod *v1.Pod, runtimeHan
411411
// From here onwards, hostUsers=false and the feature gate is enabled.
412412

413413
// if the pod requested a user namespace and the runtime doesn't support user namespaces then return an error.
414-
if handlerSupportsUserns, err := m.kl.HandlerSupportsUserNamespaces(runtimeHandler); err != nil {
415-
return nil, err
416-
} else if !handlerSupportsUserns {
417-
return nil, fmt.Errorf("RuntimeClass handler %q does not support user namespaces", runtimeHandler)
414+
if handlerSupportsUserns, err := m.kl.HandlerSupportsUserNamespaces(runtimeHandler); err != nil || !handlerSupportsUserns {
415+
msg := "can't set `spec.hostUsers: false`, runtime does not support user namespaces"
416+
if runtimeHandler != "" {
417+
msg = fmt.Sprintf("can't set `spec.hostUsers: false`, RuntimeClass handler %q does not support user namespaces", runtimeHandler)
418+
}
419+
if err != nil {
420+
return nil, fmt.Errorf("%v: %w", msg, err)
421+
}
422+
return nil, fmt.Errorf("%v", msg)
418423
}
419424

420425
m.lock.Lock()

0 commit comments

Comments
 (0)