Skip to content

Commit a8ebceb

Browse files
dcantahKern Walster
authored andcommitted
CRI: "Fix" imageFSPath behavior
Currently it didn't take into account that certain snapshots can explicitly have their root directories placed at a different location. This changes it to use the RootPath method of the snapshotter if it implements it. Without this change, cadvisor is not able to get filesystem usage information, which prevents the kubelet from doing image garbage collection and enforcing ephemeral storage limits. Signed-off-by: Danny Canter <[email protected]> (cherry picked from commit 6aeec45) Signed-off-by: Kern Walster <[email protected]>
1 parent bd423bf commit a8ebceb

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

pkg/cri/cri.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func init() {
5050
plugin.ServicePlugin,
5151
plugin.NRIApiPlugin,
5252
plugin.WarningPlugin,
53+
plugin.SnapshotPlugin,
5354
},
5455
InitFn: initCRIService,
5556
})

pkg/cri/server/service.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package server
1818

1919
import (
20+
"context"
2021
"encoding/json"
22+
"errors"
2123
"fmt"
2224
"io"
2325
"net/http"
@@ -126,6 +128,11 @@ type criService struct {
126128
func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri.API, warn warning.Service) (CRIService, error) {
127129
var err error
128130
labels := label.NewStore()
131+
132+
if client.SnapshotService(config.ContainerdConfig.Snapshotter) == nil {
133+
return nil, fmt.Errorf("failed to find snapshotter %q", config.ContainerdConfig.Snapshotter)
134+
}
135+
129136
c := &criService{
130137
config: config,
131138
client: client,
@@ -149,7 +156,11 @@ func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri.
149156
return nil, fmt.Errorf("failed to find snapshotter %q", c.config.ContainerdConfig.Snapshotter)
150157
}
151158

152-
c.imageFSPath = imageFSPath(config.ContainerdRootDir, config.ContainerdConfig.Snapshotter)
159+
c.imageFSPath = imageFSPath(
160+
config.ContainerdRootDir,
161+
config.ContainerdConfig.Snapshotter,
162+
client,
163+
)
153164
logrus.Infof("Get image filesystem path %q", c.imageFSPath)
154165

155166
if err := c.initPlatform(); err != nil {
@@ -341,8 +352,40 @@ func (c *criService) register(s *grpc.Server) error {
341352

342353
// imageFSPath returns containerd image filesystem path.
343354
// Note that if containerd changes directory layout, we also needs to change this.
344-
func imageFSPath(rootDir, snapshotter string) string {
345-
return filepath.Join(rootDir, fmt.Sprintf("%s.%s", plugin.SnapshotPlugin, snapshotter))
355+
func imageFSPath(rootDir, snapshotter string, client *containerd.Client) string {
356+
introspection := func() (string, error) {
357+
filters := []string{fmt.Sprintf("type==%s, id==%s", plugin.SnapshotPlugin, snapshotter)}
358+
in := client.IntrospectionService()
359+
360+
resp, err := in.Plugins(context.Background(), filters)
361+
if err != nil {
362+
return "", err
363+
}
364+
365+
if len(resp.Plugins) <= 0 {
366+
return "", fmt.Errorf("inspection service could not find snapshotter %s plugin", snapshotter)
367+
}
368+
369+
sn := resp.Plugins[0]
370+
if root, ok := sn.Exports[plugin.SnapshotterRootDir]; ok {
371+
return root, nil
372+
}
373+
return "", errors.New("snapshotter does not export root path")
374+
}
375+
376+
var imageFSPath string
377+
path, err := introspection()
378+
if err != nil {
379+
logrus.WithError(err).WithField("snapshotter", snapshotter).Warn("snapshotter doesn't export root path")
380+
imageFSPath = filepath.Join(
381+
rootDir,
382+
plugin.SnapshotPlugin.String()+"."+snapshotter,
383+
)
384+
} else {
385+
imageFSPath = path
386+
}
387+
388+
return imageFSPath
346389
}
347390

348391
func loadOCISpec(filename string) (*oci.Spec, error) {

0 commit comments

Comments
 (0)