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:
		
				
					committed by
					
						
						k8s-infra-cherrypick-robot
					
				
			
			
				
	
			
			
			
						parent
						
							e1b0bb601e
						
					
				
				
					commit
					a2d9d4fd55
				
			@@ -96,39 +96,32 @@ 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 := func(snapshotter string) (snapshotRoot string) {
 | 
				
			||||||
				snapshotRoot = plugin.Meta.Exports["root"]
 | 
									if plugin := ic.Plugins().Get(plugins.SnapshotPlugin, snapshotter); 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()+"."+snapshotter)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return snapshotRoot
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if snapshotRoot == "" {
 | 
					
 | 
				
			||||||
				// Try a root in the same parent as this plugin
 | 
								options.ImageFSPaths[defaultSnapshotter] = snapshotRoot(defaultSnapshotter)
 | 
				
			||||||
				snapshotRoot = filepath.Join(filepath.Dir(ic.Properties[plugins.PropertyRootDir]), plugins.SnapshotPlugin.String()+"."+defaultSnapshotter)
 | 
								log.L.Infof("Get image filesystem path %q for snapshotter %q", options.ImageFSPaths[defaultSnapshotter], defaultSnapshotter)
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			options.ImageFSPaths[defaultSnapshotter] = snapshotRoot
 | 
					 | 
				
			||||||
			log.L.Infof("Get image filesystem path %q for snapshotter %q", snapshotRoot, defaultSnapshotter)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for runtimeName, rp := range config.RuntimePlatforms {
 | 
								for runtimeName, rp := range config.RuntimePlatforms {
 | 
				
			||||||
				snapshotter := rp.Snapshotter
 | 
									snapshotter := rp.Snapshotter
 | 
				
			||||||
				if snapshotter == "" {
 | 
									if snapshotter == "" {
 | 
				
			||||||
					snapshotter = defaultSnapshotter
 | 
										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 {
 | 
					 | 
				
			||||||
						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()+"."+snapshotter)
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
					options.ImageFSPaths[defaultSnapshotter] = snapshotRoot
 | 
									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,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user