1616package docker
1717
1818import (
19+ "encoding/json"
1920 "fmt"
2021 "os"
2122 "path"
@@ -25,13 +26,16 @@ import (
2526
2627 "github.com/google/cadvisor/container"
2728 "github.com/google/cadvisor/container/common"
29+ "github.com/google/cadvisor/container/containerd"
30+ "github.com/google/cadvisor/container/containerd/namespaces"
2831 dockerutil "github.com/google/cadvisor/container/docker/utils"
2932 containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
3033 "github.com/google/cadvisor/devicemapper"
3134 "github.com/google/cadvisor/fs"
3235 info "github.com/google/cadvisor/info/v1"
3336 "github.com/google/cadvisor/zfs"
3437 "github.com/opencontainers/cgroups"
38+ "github.com/opencontainers/runtime-spec/specs-go"
3539
3640 docker "github.com/docker/docker/client"
3741 "golang.org/x/net/context"
@@ -112,6 +116,7 @@ func getRwLayerID(containerID, storageDir string, sd StorageDriver, dockerVersio
112116// newDockerContainerHandler returns a new container.ContainerHandler
113117func newDockerContainerHandler (
114118 client * docker.Client ,
119+ containerdClient containerd.ContainerdClient ,
115120 name string ,
116121 machineInfoFactory info.MachineInfoFactory ,
117122 fsInfo fs.FsInfo ,
@@ -147,16 +152,31 @@ func newDockerContainerHandler(
147152 // FIXME: Give `otherStorageDir` a more descriptive name.
148153 otherStorageDir := path .Join (storageDir , pathToContainersDir , id )
149154
150- rwLayerID , err := getRwLayerID (id , storageDir , storageDriver , dockerVersion )
151- if err != nil {
152- return nil , err
153- }
155+ var rootfsStorageDir , zfsFilesystem , zfsParent string
156+ if storageDriver == ContainerdSnapshotterStorageDriver {
157+ ctx := namespaces .WithNamespace (context .Background (), "moby" )
158+ cntr , err := containerdClient .LoadContainer (ctx , id )
159+ if err != nil {
160+ return nil , err
161+ }
154162
155- // Determine the rootfs storage dir OR the pool name to determine the device.
156- // For devicemapper, we only need the thin pool name, and that is passed in to this call
157- rootfsStorageDir , zfsFilesystem , zfsParent , err := DetermineDeviceStorage (storageDriver , storageDir , rwLayerID )
158- if err != nil {
159- return nil , fmt .Errorf ("unable to determine device storage: %v" , err )
163+ var spec specs.Spec
164+ if err := json .Unmarshal (cntr .Spec .Value , & spec ); err != nil {
165+ return nil , err
166+ }
167+ rootfsStorageDir = spec .Root .Path
168+ } else {
169+ rwLayerID , err := getRwLayerID (id , storageDir , storageDriver , dockerVersion )
170+ if err != nil {
171+ return nil , err
172+ }
173+
174+ // Determine the rootfs storage dir OR the pool name to determine the device.
175+ // For devicemapper, we only need the thin pool name, and that is passed in to this call
176+ rootfsStorageDir , zfsFilesystem , zfsParent , err = DetermineDeviceStorage (storageDriver , storageDir , rwLayerID )
177+ if err != nil {
178+ return nil , fmt .Errorf ("unable to determine device storage: %v" , err )
179+ }
160180 }
161181
162182 // We assume that if Inspect fails then the container is not known to docker.
0 commit comments