Fix runtime platform loading in cri image plugin init
The cri image service init has a bug where, after getting FSPath for snapshotter_i, it stores it under defaultSnapshotter instead of snapshotter_i. Also make a few other refactor: 1. Dedup the snapshotRoot loading for defaultSnapshotter 2. Remove some unnecessary logic in RuntimePlatforms for-loop Signed-off-by: Jin Dong <djdongjin95@gmail.com>
This commit is contained in:
parent
e1b0bb601e
commit
a2d9d4fd55
@ -96,28 +96,8 @@ func init() {
|
|||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("failed to find snapshotter %q", defaultSnapshotter)
|
return nil, fmt.Errorf("failed to find snapshotter %q", defaultSnapshotter)
|
||||||
}
|
}
|
||||||
var snapshotRoot string
|
|
||||||
if plugin := ic.Plugins().Get(plugins.SnapshotPlugin, defaultSnapshotter); plugin != nil {
|
|
||||||
snapshotRoot = plugin.Meta.Exports["root"]
|
|
||||||
}
|
|
||||||
if snapshotRoot == "" {
|
|
||||||
// Try a root in the same parent as this plugin
|
|
||||||
snapshotRoot = filepath.Join(filepath.Dir(ic.Properties[plugins.PropertyRootDir]), plugins.SnapshotPlugin.String()+"."+defaultSnapshotter)
|
|
||||||
}
|
|
||||||
options.ImageFSPaths[defaultSnapshotter] = snapshotRoot
|
|
||||||
log.L.Infof("Get image filesystem path %q for snapshotter %q", snapshotRoot, defaultSnapshotter)
|
|
||||||
|
|
||||||
for runtimeName, rp := range config.RuntimePlatforms {
|
snapshotRoot := func(snapshotter string) (snapshotRoot string) {
|
||||||
snapshotter := rp.Snapshotter
|
|
||||||
if snapshotter == "" {
|
|
||||||
snapshotter = defaultSnapshotter
|
|
||||||
} else if _, ok := options.ImageFSPaths[snapshotter]; !ok {
|
|
||||||
if s, ok := options.Snapshotters[defaultSnapshotter]; ok {
|
|
||||||
options.Snapshotters[defaultSnapshotter] = s
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("failed to find snapshotter %q", defaultSnapshotter)
|
|
||||||
}
|
|
||||||
var snapshotRoot string
|
|
||||||
if plugin := ic.Plugins().Get(plugins.SnapshotPlugin, snapshotter); plugin != nil {
|
if plugin := ic.Plugins().Get(plugins.SnapshotPlugin, snapshotter); plugin != nil {
|
||||||
snapshotRoot = plugin.Meta.Exports["root"]
|
snapshotRoot = plugin.Meta.Exports["root"]
|
||||||
}
|
}
|
||||||
@ -125,10 +105,23 @@ func init() {
|
|||||||
// Try a root in the same parent as this plugin
|
// Try a root in the same parent as this plugin
|
||||||
snapshotRoot = filepath.Join(filepath.Dir(ic.Properties[plugins.PropertyRootDir]), plugins.SnapshotPlugin.String()+"."+snapshotter)
|
snapshotRoot = filepath.Join(filepath.Dir(ic.Properties[plugins.PropertyRootDir]), plugins.SnapshotPlugin.String()+"."+snapshotter)
|
||||||
}
|
}
|
||||||
|
return snapshotRoot
|
||||||
|
}
|
||||||
|
|
||||||
options.ImageFSPaths[defaultSnapshotter] = snapshotRoot
|
options.ImageFSPaths[defaultSnapshotter] = snapshotRoot(defaultSnapshotter)
|
||||||
|
log.L.Infof("Get image filesystem path %q for snapshotter %q", options.ImageFSPaths[defaultSnapshotter], defaultSnapshotter)
|
||||||
|
|
||||||
|
for runtimeName, rp := range config.RuntimePlatforms {
|
||||||
|
snapshotter := rp.Snapshotter
|
||||||
|
if snapshotter == "" {
|
||||||
|
snapshotter = defaultSnapshotter
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := options.ImageFSPaths[snapshotter]; !ok {
|
||||||
|
options.ImageFSPaths[snapshotter] = snapshotRoot(snapshotter)
|
||||||
log.L.Infof("Get image filesystem path %q for snapshotter %q", options.ImageFSPaths[snapshotter], snapshotter)
|
log.L.Infof("Get image filesystem path %q for snapshotter %q", options.ImageFSPaths[snapshotter], snapshotter)
|
||||||
}
|
}
|
||||||
|
|
||||||
platform := platforms.DefaultSpec()
|
platform := platforms.DefaultSpec()
|
||||||
if rp.Platform != "" {
|
if rp.Platform != "" {
|
||||||
p, err := platforms.Parse(rp.Platform)
|
p, err := platforms.Parse(rp.Platform)
|
||||||
@ -137,6 +130,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
platform = p
|
platform = p
|
||||||
}
|
}
|
||||||
|
|
||||||
options.RuntimePlatforms[runtimeName] = images.ImagePlatform{
|
options.RuntimePlatforms[runtimeName] = images.ImagePlatform{
|
||||||
Snapshotter: snapshotter,
|
Snapshotter: snapshotter,
|
||||||
Platform: platform,
|
Platform: platform,
|
||||||
|
Loading…
Reference in New Issue
Block a user