Skip to content

Commit

Permalink
cli: update paths to be configurable for rootless execution
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 27, 2019
1 parent 175d49f commit 020051d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 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,10 @@ func FetchContainerIDMapping(containerID string) (string, error) {
return "", fmt.Errorf("Missing container ID")
}

if rootless.IsRootless() {
SetCtrsMapTreePath(filepath.Join(rootless.GetRootlessDir(), ctrsMapTreePath))
}

dirPath := filepath.Join(ctrsMapTreePath, containerID)

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

if rootless.IsRootless() {
SetCtrsMapTreePath(filepath.Join(rootless.GetRootlessDir(), ctrsMapTreePath))
}
parentPath := filepath.Join(ctrsMapTreePath, containerID)

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

if rootless.IsRootless() {
SetCtrsMapTreePath(filepath.Join(rootless.GetRootlessDir(), ctrsMapTreePath))
}
path := filepath.Join(ctrsMapTreePath, containerID)

return os.RemoveAll(path)
Expand Down

0 comments on commit 020051d

Please sign in to comment.