mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
pkg/kubelet/userns: Simplify error messages
The error we are wrapping is already verbose, let's just use minimal wrapping as it is usually the case in go code. Note that the error on parseUserNsFileAndRecord() can be returned to the user, so we added some context about user namespace. Otherwise, an error to parse the json would not be clear to which of all the json the kubelet parses it refers to. Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
This commit is contained in:
parent
fdc20de500
commit
0f7b9cc4f5
@ -96,7 +96,7 @@ func (m *UsernsManager) writeMappingsToFile(pod types.UID, userNs userNamespace)
|
||||
|
||||
fstore, err := utilstore.NewFileStore(dir, &utilfs.DefaultFs{})
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("create user namespace store: %w", err)
|
||||
}
|
||||
if err := fstore.Write(mappingsFile, data); err != nil {
|
||||
return err
|
||||
@ -123,7 +123,7 @@ func (m *UsernsManager) readMappingsFromFile(pod types.UID) ([]byte, error) {
|
||||
dir := m.kl.GetPodDir(pod)
|
||||
fstore, err := utilstore.NewFileStore(dir, &utilfs.DefaultFs{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("create user namespace store: %w", err)
|
||||
}
|
||||
return fstore.Read(mappingsFile)
|
||||
}
|
||||
@ -151,7 +151,7 @@ func MakeUserNsManager(kl userNsPodsManager) (*UsernsManager, error) {
|
||||
if os.IsNotExist(err) {
|
||||
return &m, nil
|
||||
}
|
||||
return nil, fmt.Errorf("user namespace manager can't read pods from disk: %w", err)
|
||||
return nil, fmt.Errorf("read pods from disk: %w", err)
|
||||
|
||||
}
|
||||
for _, podUID := range found {
|
||||
@ -308,7 +308,7 @@ func (m *UsernsManager) releaseWithLock(pod types.UID) {
|
||||
|
||||
func (m *UsernsManager) parseUserNsFileAndRecord(pod types.UID, content []byte) (userNs userNamespace, err error) {
|
||||
if err = json.Unmarshal([]byte(content), &userNs); err != nil {
|
||||
err = fmt.Errorf("can't parse file: %w", err)
|
||||
err = fmt.Errorf("invalid user namespace mappings file: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user