@@ -220,10 +220,28 @@ func removeCRIImage(cr CommandRunner, name string) error {
220
220
crictl := getCrictlPath (cr )
221
221
args := append ([]string {crictl , "rmi" }, name )
222
222
c := exec .Command ("sudo" , args ... )
223
- if _ , err := cr .RunCmd (c ); err != nil {
224
- return errors .Wrap (err , "crictl" )
223
+ var err error
224
+ if _ , err = cr .RunCmd (c ); err == nil {
225
+ return nil
225
226
}
226
- return nil
227
+ // the reason why we are doing this is that
228
+ // unlike other tool, podman assume the image has a localhost registry (not docker.io)
229
+ // if the image is loaded with a tarball without a registry specified in tag
230
+ // see https://github.com/containers/podman/issues/15974
231
+
232
+ // then retry with dockerio prefix
233
+ if _ , err := cr .RunCmd (exec .Command ("sudo" , crictl , "rmi" , AddDockerIO (name ))); err == nil {
234
+ return nil
235
+ }
236
+
237
+ // then retry with localhost prefix
238
+ if _ , err := cr .RunCmd (exec .Command ("sudo" , crictl , "rmi" , AddLocalhostPrefix (name ))); err == nil {
239
+
240
+ return nil
241
+ }
242
+
243
+ // if all of above failed, return original error
244
+ return errors .Wrap (err , "crictl" )
227
245
}
228
246
229
247
// stopCRIContainers stops containers using crictl
@@ -358,3 +376,8 @@ func checkCNIPlugins(kubernetesVersion semver.Version) error {
358
376
_ , err := os .Stat ("/opt/cni/bin" )
359
377
return err
360
378
}
379
+
380
+ // Add localhost prefix if the registy part is missing
381
+ func AddLocalhostPrefix (name string ) string {
382
+ return addRegistryPreix (name , "localhost" )
383
+ }
0 commit comments