Skip to content

Commit

Permalink
cli: update ctrsMapTreePath to allow rootless dir
Browse files Browse the repository at this point in the history
Before using the default ctrsMapTrePath, check whether the runtime
is being ran rootlessly, and if so set the ctrsMapTreePath to the
rootlessRuntimeDir configured by the libpod rootless library.

Fixes: kata-containers#1358

Signed-off-by: Gabi Beyer <[email protected]>
  • Loading branch information
Gabi Beyer committed Jun 25, 2019
1 parent 1a26b16 commit 9f1871f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/katautils/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"io/ioutil"
"os"
"path/filepath"

"github.com/kata-containers/runtime/pkg/rootless"
)

const ctrsMappingDirMode = os.FileMode(0750)
Expand All @@ -31,6 +33,14 @@ func FetchContainerIDMapping(containerID string) (string, error) {
return "", fmt.Errorf("Missing container ID")
}

if rootless.IsRootless() {
path, err := rootless.GetRootlessRuntimeDir()
if err != nil {
return "", err
}
SetCtrsMapTreePath(path)
}

dirPath := filepath.Join(ctrsMapTreePath, containerID)

files, err := ioutil.ReadDir(dirPath)
Expand Down Expand Up @@ -62,6 +72,13 @@ func AddContainerIDMapping(ctx context.Context, containerID, sandboxID string) e
return fmt.Errorf("Missing sandbox ID")
}

if rootless.IsRootless() {
path, err := rootless.GetRootlessRuntimeDir()
if err != nil {
return err
}
SetCtrsMapTreePath(path)
}
parentPath := filepath.Join(ctrsMapTreePath, containerID)

if err := os.RemoveAll(parentPath); err != nil {
Expand All @@ -86,6 +103,13 @@ func DelContainerIDMapping(ctx context.Context, containerID string) error {
return fmt.Errorf("Missing container ID")
}

if rootless.IsRootless() {
path, err := rootless.GetRootlessRuntimeDir()
if err != nil {
return err
}
SetCtrsMapTreePath(path)
}
path := filepath.Join(ctrsMapTreePath, containerID)

return os.RemoveAll(path)
Expand Down

0 comments on commit 9f1871f

Please sign in to comment.