Skip to content

Commit

Permalink
info: add information about ID mappings
Browse files Browse the repository at this point in the history
add information about the ID mappings used for the containers.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed May 19, 2018
1 parent 6d98a70 commit bbfab9e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
26 changes: 23 additions & 3 deletions server/inspect.go
Expand Up @@ -7,18 +7,38 @@ import (
"net/http"

cimage "github.com/containers/image/types"
"github.com/containers/storage/pkg/idtools"
"github.com/go-zoo/bone"
"github.com/kubernetes-incubator/cri-o/lib/sandbox"
"github.com/kubernetes-incubator/cri-o/oci"
"github.com/kubernetes-incubator/cri-o/types"
"github.com/sirupsen/logrus"
)

func (s *Server) getIDMappingsInfo() types.IDMappings {
if s.defaultIDMappings == nil {
fullMapping := idtools.IDMap{
ContainerID: 0,
HostID: 0,
Size: 4294967295,
}
return types.IDMappings{
Uids: []idtools.IDMap{fullMapping},
Gids: []idtools.IDMap{fullMapping},
}
}
return types.IDMappings{
Uids: s.defaultIDMappings.UIDs(),
Gids: s.defaultIDMappings.GIDs(),
}
}

func (s *Server) getInfo() types.CrioInfo {
return types.CrioInfo{
StorageDriver: s.config.Config.Storage,
StorageRoot: s.config.Config.Root,
CgroupDriver: s.config.Config.CgroupManager,
StorageDriver: s.config.Config.Storage,
StorageRoot: s.config.Config.Root,
CgroupDriver: s.config.Config.CgroupManager,
DefaultIDMappings: s.getIDMappingsInfo(),
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/ctr_userns.bats
Expand Up @@ -37,7 +37,15 @@ function teardown() {
state=$($RUNTIME state "$ctr_id")
pid=$(echo $state | python -c 'import json; import sys; d=json.load(sys.stdin); print d["pid"]')
grep 100000 /proc/$pid/uid_map
[ "$status" -eq 0 ]
grep 200000 /proc/$pid/gid_map
[ "$status" -eq 0 ]

out=`echo -e "GET /info HTTP/1.1\r\nHost: crio\r\n" | socat - UNIX-CONNECT:$CRIO_SOCKET`
echo "$out"
[[ "$out" =~ "100000" ]]
[[ "$out" =~ "200000" ]]

cleanup_ctrs
cleanup_pods
stop_crio
Expand Down
17 changes: 14 additions & 3 deletions types/types.go
@@ -1,5 +1,9 @@
package types

import (
"github.com/containers/storage/pkg/idtools"
)

// ContainerInfo stores information about containers
type ContainerInfo struct {
Name string `json:"name"`
Expand All @@ -16,9 +20,16 @@ type ContainerInfo struct {
IP string `json:"ip_address"`
}

// IDMappings specifies the ID mappings used for containers.
type IDMappings struct {
Uids []idtools.IDMap `json:"uids"`
Gids []idtools.IDMap `json:"gids"`
}

// CrioInfo stores information about the crio daemon
type CrioInfo struct {
StorageDriver string `json:"storage_driver"`
StorageRoot string `json:"storage_root"`
CgroupDriver string `json:"cgroup_driver"`
StorageDriver string `json:"storage_driver"`
StorageRoot string `json:"storage_root"`
CgroupDriver string `json:"cgroup_driver"`
DefaultIDMappings IDMappings `json:"default_id_mappings"`
}

0 comments on commit bbfab9e

Please sign in to comment.