Skip to content

Commit b48e108

Browse files
authored
Merge pull request #11248 from k8s-infra-cherrypick-robot/cherry-pick-11165-to-release/2.0
[release/2.0] Fix runtime platform loading in cri image plugin init
2 parents e1b0bb6 + a2d9d4f commit b48e108

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

plugins/cri/images/plugin.go

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,39 +96,32 @@ func init() {
9696
} else {
9797
return nil, fmt.Errorf("failed to find snapshotter %q", defaultSnapshotter)
9898
}
99-
var snapshotRoot string
100-
if plugin := ic.Plugins().Get(plugins.SnapshotPlugin, defaultSnapshotter); plugin != nil {
101-
snapshotRoot = plugin.Meta.Exports["root"]
102-
}
103-
if snapshotRoot == "" {
104-
// Try a root in the same parent as this plugin
105-
snapshotRoot = filepath.Join(filepath.Dir(ic.Properties[plugins.PropertyRootDir]), plugins.SnapshotPlugin.String()+"."+defaultSnapshotter)
99+
100+
snapshotRoot := func(snapshotter string) (snapshotRoot string) {
101+
if plugin := ic.Plugins().Get(plugins.SnapshotPlugin, snapshotter); plugin != nil {
102+
snapshotRoot = plugin.Meta.Exports["root"]
103+
}
104+
if snapshotRoot == "" {
105+
// Try a root in the same parent as this plugin
106+
snapshotRoot = filepath.Join(filepath.Dir(ic.Properties[plugins.PropertyRootDir]), plugins.SnapshotPlugin.String()+"."+snapshotter)
107+
}
108+
return snapshotRoot
106109
}
107-
options.ImageFSPaths[defaultSnapshotter] = snapshotRoot
108-
log.L.Infof("Get image filesystem path %q for snapshotter %q", snapshotRoot, defaultSnapshotter)
110+
111+
options.ImageFSPaths[defaultSnapshotter] = snapshotRoot(defaultSnapshotter)
112+
log.L.Infof("Get image filesystem path %q for snapshotter %q", options.ImageFSPaths[defaultSnapshotter], defaultSnapshotter)
109113

110114
for runtimeName, rp := range config.RuntimePlatforms {
111115
snapshotter := rp.Snapshotter
112116
if snapshotter == "" {
113117
snapshotter = defaultSnapshotter
114-
} else if _, ok := options.ImageFSPaths[snapshotter]; !ok {
115-
if s, ok := options.Snapshotters[defaultSnapshotter]; ok {
116-
options.Snapshotters[defaultSnapshotter] = s
117-
} else {
118-
return nil, fmt.Errorf("failed to find snapshotter %q", defaultSnapshotter)
119-
}
120-
var snapshotRoot string
121-
if plugin := ic.Plugins().Get(plugins.SnapshotPlugin, snapshotter); plugin != nil {
122-
snapshotRoot = plugin.Meta.Exports["root"]
123-
}
124-
if snapshotRoot == "" {
125-
// Try a root in the same parent as this plugin
126-
snapshotRoot = filepath.Join(filepath.Dir(ic.Properties[plugins.PropertyRootDir]), plugins.SnapshotPlugin.String()+"."+snapshotter)
127-
}
118+
}
128119

129-
options.ImageFSPaths[defaultSnapshotter] = snapshotRoot
120+
if _, ok := options.ImageFSPaths[snapshotter]; !ok {
121+
options.ImageFSPaths[snapshotter] = snapshotRoot(snapshotter)
130122
log.L.Infof("Get image filesystem path %q for snapshotter %q", options.ImageFSPaths[snapshotter], snapshotter)
131123
}
124+
132125
platform := platforms.DefaultSpec()
133126
if rp.Platform != "" {
134127
p, err := platforms.Parse(rp.Platform)
@@ -137,6 +130,7 @@ func init() {
137130
}
138131
platform = p
139132
}
133+
140134
options.RuntimePlatforms[runtimeName] = images.ImagePlatform{
141135
Snapshotter: snapshotter,
142136
Platform: platform,

0 commit comments

Comments
 (0)