@@ -156,7 +156,7 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
156156 options .Variant = r .systemContext .VariantChoice
157157 }
158158
159- var pulledImages []string
159+ var pulledImages []* Image
160160
161161 // Dispatch the copy operation.
162162 switch ref .Transport ().Name () {
@@ -178,12 +178,7 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
178178 }
179179
180180 localImages := []* Image {}
181- for _ , iName := range pulledImages {
182- image , _ , err := r .LookupImage (iName , nil )
183- if err != nil {
184- return nil , fmt .Errorf ("locating pulled image %q name in containers storage: %w" , iName , err )
185- }
186-
181+ for _ , image := range pulledImages {
187182 // Note that we can ignore the 2nd return value here. Some
188183 // images may ship with "wrong" platform, but we already warn
189184 // about it. Throwing an error is not (yet) the plan.
@@ -229,7 +224,7 @@ func nameFromAnnotations(annotations map[string]string) string {
229224
230225// copyFromDefault is the default copier for a number of transports. Other
231226// transports require some specific dancing, sometimes Yoga.
232- func (r * Runtime ) copyFromDefault (ctx context.Context , ref types.ImageReference , options * CopyOptions ) ([]string , error ) {
227+ func (r * Runtime ) copyFromDefault (ctx context.Context , ref types.ImageReference , options * CopyOptions ) ([]* Image , error ) {
233228 c , err := r .newCopier (options , nil )
234229 if err != nil {
235230 return nil , err
@@ -321,7 +316,14 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
321316 }
322317
323318 _ , err = c .Copy (ctx , ref , destRef )
324- return []string {imageName }, err
319+ if err != nil {
320+ return nil , fmt .Errorf ("unable to perform copy: %w" , err )
321+ }
322+ image , _ , err := r .LookupImage (imageName , nil )
323+ if err != nil {
324+ return nil , fmt .Errorf ("Unable to lookup image %q: %w" , imageName , err )
325+ }
326+ return []* Image {image }, err
325327}
326328
327329// storageReferencesFromArchiveReader returns a slice of image references inside the
@@ -368,7 +370,7 @@ func (r *Runtime) storageReferencesReferencesFromArchiveReader(ctx context.Conte
368370}
369371
370372// copyFromDockerArchive copies one image from the specified reference.
371- func (r * Runtime ) copyFromDockerArchive (ctx context.Context , ref types.ImageReference , options * CopyOptions ) ([]string , error ) {
373+ func (r * Runtime ) copyFromDockerArchive (ctx context.Context , ref types.ImageReference , options * CopyOptions ) ([]* Image , error ) {
372374 // There may be more than one image inside the docker archive, so we
373375 // need a quick glimpse inside.
374376 reader , readerRef , err := dockerArchiveTransport .NewReaderForReference (& r .systemContext , ref )
@@ -385,7 +387,7 @@ func (r *Runtime) copyFromDockerArchive(ctx context.Context, ref types.ImageRefe
385387}
386388
387389// copyFromDockerArchiveReaderReference copies the specified readerRef from reader.
388- func (r * Runtime ) copyFromDockerArchiveReaderReference (ctx context.Context , reader * dockerArchiveTransport.Reader , readerRef types.ImageReference , options * CopyOptions ) ([]string , error ) {
390+ func (r * Runtime ) copyFromDockerArchiveReaderReference (ctx context.Context , reader * dockerArchiveTransport.Reader , readerRef types.ImageReference , options * CopyOptions ) ([]* Image , error ) {
389391 c , err := r .newCopier (options , nil )
390392 if err != nil {
391393 return nil , err
@@ -405,15 +407,23 @@ func (r *Runtime) copyFromDockerArchiveReaderReference(ctx context.Context, read
405407 }
406408 }
407409
408- return destNames , nil
410+ images := []* Image {}
411+ for _ , name := range destNames {
412+ image , _ , err := r .LookupImage (name , nil )
413+ if err != nil {
414+ return nil , fmt .Errorf ("Unable to lookup image %q: %w" , name , err )
415+ }
416+ images = append (images , image )
417+ }
418+
419+ return images , nil
409420}
410421
411422// copyFromRegistry pulls the specified, possibly unqualified, name from a
412- // registry. On successful pull it returns the ID of the image in local
413- // storage.
423+ // registry. On successful pull it returns the image in local storage.
414424//
415425// If options.All is set, all tags from the specified registry will be pulled.
416- func (r * Runtime ) copyFromRegistry (ctx context.Context , ref types.ImageReference , inputName string , pullPolicy config.PullPolicy , options * PullOptions ) ([]string , error ) {
426+ func (r * Runtime ) copyFromRegistry (ctx context.Context , ref types.ImageReference , inputName string , pullPolicy config.PullPolicy , options * PullOptions ) ([]* Image , error ) {
417427 // Sanity check.
418428 if err := pullPolicy .Validate (); err != nil {
419429 return nil , err
@@ -424,7 +434,7 @@ func (r *Runtime) copyFromRegistry(ctx context.Context, ref types.ImageReference
424434 if err != nil {
425435 return nil , err
426436 }
427- return []string {pulled }, nil
437+ return []* Image {pulled }, nil
428438 }
429439
430440 // Copy all tags
@@ -434,7 +444,7 @@ func (r *Runtime) copyFromRegistry(ctx context.Context, ref types.ImageReference
434444 return nil , err
435445 }
436446
437- pulledIDs := []string {}
447+ pulledImages := []* Image {}
438448 for _ , tag := range tags {
439449 select { // Let's be gentle with Podman remote.
440450 case <- ctx .Done ():
@@ -450,19 +460,18 @@ func (r *Runtime) copyFromRegistry(ctx context.Context, ref types.ImageReference
450460 if err != nil {
451461 return nil , err
452462 }
453- pulledIDs = append (pulledIDs , pulled )
463+ pulledImages = append (pulledImages , pulled )
454464 }
455465
456- return pulledIDs , nil
466+ return pulledImages , nil
457467}
458468
459469// copySingleImageFromRegistry pulls the specified, possibly unqualified, name
460- // from a registry. On successful pull it returns the ID of the image in local
461- // storage (or, FIXME, a name/ID? that could be resolved in local storage)
462- func (r * Runtime ) copySingleImageFromRegistry (ctx context.Context , imageName string , pullPolicy config.PullPolicy , options * PullOptions ) (string , error ) { //nolint:gocyclo
470+ // from a registry. On successful pull it returns the Image from the local storage
471+ func (r * Runtime ) copySingleImageFromRegistry (ctx context.Context , imageName string , pullPolicy config.PullPolicy , options * PullOptions ) (* Image , error ) { //nolint:gocyclo
463472 // Sanity check.
464473 if err := pullPolicy .Validate (); err != nil {
465- return "" , err
474+ return nil , err
466475 }
467476
468477 var (
@@ -487,14 +496,7 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
487496 if options .OS != runtime .GOOS {
488497 lookupImageOptions .OS = options .OS
489498 }
490- // FIXME: We sometimes return resolvedImageName from this function.
491- // The function documentation says this returns an image ID, resolvedImageName is frequently not an image ID.
492- //
493- // Ultimately Runtime.Pull looks up the returned name... again, possibly finding some other match
494- // than we did.
495- //
496- // This should be restructured so that the image we found here is returned to the caller of Pull
497- // directly, without another image -> name -> image round-trip and possible inconsistency.
499+
498500 localImage , resolvedImageName , err = r .LookupImage (imageName , lookupImageOptions )
499501 if err != nil && ! errors .Is (err , storage .ErrImageUnknown ) {
500502 logrus .Errorf ("Looking up %s in local storage: %v" , imageName , err )
@@ -525,23 +527,23 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
525527 if pullPolicy == config .PullPolicyNever {
526528 if localImage != nil {
527529 logrus .Debugf ("Pull policy %q and %s resolved to local image %s" , pullPolicy , imageName , resolvedImageName )
528- return resolvedImageName , nil
530+ return localImage , nil
529531 }
530532 logrus .Debugf ("Pull policy %q but no local image has been found for %s" , pullPolicy , imageName )
531- return "" , fmt .Errorf ("%s: %w" , imageName , storage .ErrImageUnknown )
533+ return nil , fmt .Errorf ("%s: %w" , imageName , storage .ErrImageUnknown )
532534 }
533535
534536 if pullPolicy == config .PullPolicyMissing && localImage != nil {
535- return resolvedImageName , nil
537+ return localImage , nil
536538 }
537539
538540 // If we looked up the image by ID, we cannot really pull from anywhere.
539541 if localImage != nil && strings .HasPrefix (localImage .ID (), imageName ) {
540542 switch pullPolicy {
541543 case config .PullPolicyAlways :
542- return "" , fmt .Errorf ("pull policy is always but image has been referred to by ID (%s)" , imageName )
544+ return nil , fmt .Errorf ("pull policy is always but image has been referred to by ID (%s)" , imageName )
543545 default :
544- return resolvedImageName , nil
546+ return localImage , nil
545547 }
546548 }
547549
@@ -566,9 +568,9 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
566568 resolved , err := shortnames .Resolve (sys , imageName )
567569 if err != nil {
568570 if localImage != nil && pullPolicy == config .PullPolicyNewer {
569- return resolvedImageName , nil
571+ return localImage , nil
570572 }
571- return "" , err
573+ return nil , err
572574 }
573575
574576 // NOTE: Below we print the description from the short-name resolution.
@@ -601,7 +603,7 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
601603 var resolvedReference types.ImageReference
602604 c , err := r .newCopier (& options .CopyOptions , & resolvedReference )
603605 if err != nil {
604- return "" , err
606+ return nil , err
605607 }
606608 defer c .Close ()
607609
@@ -611,7 +613,7 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
611613 logrus .Debugf ("Attempting to pull candidate %s for %s" , candidateString , imageName )
612614 srcRef , err := registryTransport .NewReference (candidate .Value )
613615 if err != nil {
614- return "" , err
616+ return nil , err
615617 }
616618
617619 if pullPolicy == config .PullPolicyNewer && localImage != nil {
@@ -629,15 +631,15 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
629631
630632 destRef , err := storageTransport .Transport .ParseStoreReference (r .store , candidate .Value .String ())
631633 if err != nil {
632- return "" , err
634+ return nil , err
633635 }
634636
635637 if err := writeDesc (); err != nil {
636- return "" , err
638+ return nil , err
637639 }
638640 if options .Writer != nil {
639641 if _ , err := io .WriteString (options .Writer , fmt .Sprintf ("Trying to pull %s...\n " , candidateString )); err != nil {
640- return "" , err
642+ return nil , err
641643 }
642644 }
643645 if _ , err := c .Copy (ctx , srcRef , destRef ); err != nil {
@@ -654,22 +656,26 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
654656
655657 logrus .Debugf ("Pulled candidate %s successfully" , candidateString )
656658 if resolvedReference == nil { // resolvedReference should always be set for storageTransport destinations
657- return "" , fmt .Errorf ("internal error: After pulling %s, resolvedReference is nil" , candidateString )
659+ return nil , fmt .Errorf ("internal error: After pulling %s, resolvedReference is nil" , candidateString )
658660 }
659661 _ , image , err := storageTransport .ResolveReference (resolvedReference )
660662 if err != nil {
661- return "" , fmt .Errorf ("resolving an already-resolved reference %q to the pulled image: %w" , transports .ImageName (resolvedReference ), err )
663+ return nil , fmt .Errorf ("resolving an already-resolved reference %q to the pulled image: %w" , transports .ImageName (resolvedReference ), err )
662664 }
663- return image .ID , nil
665+ resolvedImage := r .storageToImage (image , resolvedReference )
666+ // At this point resolvedImage is reference to `name@digest@ID` but
667+ // let's perform a reload so we only return `@ID` only reference.
668+ err = resolvedImage .reload ()
669+ return resolvedImage , err
664670 }
665671
666672 if localImage != nil && pullPolicy == config .PullPolicyNewer {
667- return resolvedImageName , nil
673+ return localImage , nil
668674 }
669675
670676 if len (pullErrors ) == 0 {
671- return "" , fmt .Errorf ("internal error: no image pulled (pull policy %s)" , pullPolicy )
677+ return nil , fmt .Errorf ("internal error: no image pulled (pull policy %s)" , pullPolicy )
672678 }
673679
674- return "" , resolved .FormatPullErrors (pullErrors )
680+ return nil , resolved .FormatPullErrors (pullErrors )
675681}
0 commit comments