@@ -22,8 +22,8 @@ import (
22
22
"time"
23
23
24
24
"github.com/containerd/containerd/errdefs"
25
+ criapi "github.com/google/cadvisor/cri-api/pkg/apis/runtime/v1alpha2"
25
26
"golang.org/x/net/context"
26
- criapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
27
27
28
28
"github.com/google/cadvisor/container"
29
29
"github.com/google/cadvisor/container/common"
@@ -176,15 +176,17 @@ func newContainerdContainerHandler(
176
176
if includedMetrics .Has (container .DiskUsageMetrics ) && cntr .Labels ["io.cri-containerd.kind" ] != "sandbox" {
177
177
mounts , err := client .SnapshotMounts (ctx , cntr .Snapshotter , cntr .SnapshotKey )
178
178
if err != nil {
179
- return nil , err
179
+ return nil , fmt . Errorf ( "failed to obtain containerd snapshot mounts for disk usage metrics: %v" , err )
180
180
}
181
181
182
- // Default to top directory if the specific upperdir snapshot is not found
182
+ // Default to top directory
183
183
snapshotDir := "/var/lib/containerd"
184
- // Example: upperdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/5001/fs
185
- if len (mounts ) > 0 {
184
+ // TODO: only overlay snapshotters is handled as of now.
185
+ // Note: overlay returns single mount. https://github.com/containerd/containerd/blob/main/snapshots/overlay/overlay.go
186
+ if len (mounts ) > 0 && mounts [0 ].Type == "overlay" {
186
187
for _ , option := range mounts [0 ].Options {
187
- if strings .Index (option , "upperdir=" ) == 0 {
188
+ // Example: upperdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/5001/fs
189
+ if strings .HasPrefix (option , "upperdir=" ) {
188
190
snapshotDir = option [len ("upperdir=" ):]
189
191
break
190
192
}
0 commit comments