@@ -156,7 +156,7 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
156
156
options .Variant = r .systemContext .VariantChoice
157
157
}
158
158
159
- var pulledImages []string
159
+ var pulledImages []* Image
160
160
161
161
// Dispatch the copy operation.
162
162
switch ref .Transport ().Name () {
@@ -178,12 +178,7 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
178
178
}
179
179
180
180
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 {
187
182
// Note that we can ignore the 2nd return value here. Some
188
183
// images may ship with "wrong" platform, but we already warn
189
184
// about it. Throwing an error is not (yet) the plan.
@@ -229,7 +224,7 @@ func nameFromAnnotations(annotations map[string]string) string {
229
224
230
225
// copyFromDefault is the default copier for a number of transports. Other
231
226
// 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 ) {
233
228
c , err := r .newCopier (options , nil )
234
229
if err != nil {
235
230
return nil , err
@@ -321,7 +316,11 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
321
316
}
322
317
323
318
_ , err = c .Copy (ctx , ref , destRef )
324
- return []string {imageName }, err
319
+ image , _ , err := r .LookupImage (imageName , nil )
320
+ if err != nil {
321
+ return nil , fmt .Errorf ("Unable to lookup image %q: %w" , imageName , err )
322
+ }
323
+ return []* Image {image }, err
325
324
}
326
325
327
326
// storageReferencesFromArchiveReader returns a slice of image references inside the
@@ -368,7 +367,7 @@ func (r *Runtime) storageReferencesReferencesFromArchiveReader(ctx context.Conte
368
367
}
369
368
370
369
// copyFromDockerArchive copies one image from the specified reference.
371
- func (r * Runtime ) copyFromDockerArchive (ctx context.Context , ref types.ImageReference , options * CopyOptions ) ([]string , error ) {
370
+ func (r * Runtime ) copyFromDockerArchive (ctx context.Context , ref types.ImageReference , options * CopyOptions ) ([]* Image , error ) {
372
371
// There may be more than one image inside the docker archive, so we
373
372
// need a quick glimpse inside.
374
373
reader , readerRef , err := dockerArchiveTransport .NewReaderForReference (& r .systemContext , ref )
@@ -385,7 +384,7 @@ func (r *Runtime) copyFromDockerArchive(ctx context.Context, ref types.ImageRefe
385
384
}
386
385
387
386
// 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 ) {
387
+ func (r * Runtime ) copyFromDockerArchiveReaderReference (ctx context.Context , reader * dockerArchiveTransport.Reader , readerRef types.ImageReference , options * CopyOptions ) ([]* Image , error ) {
389
388
c , err := r .newCopier (options , nil )
390
389
if err != nil {
391
390
return nil , err
@@ -405,15 +404,23 @@ func (r *Runtime) copyFromDockerArchiveReaderReference(ctx context.Context, read
405
404
}
406
405
}
407
406
408
- return destNames , nil
407
+ images := []* Image {}
408
+ for _ , name := range destNames {
409
+ image , _ , err := r .LookupImage (name , nil )
410
+ if err != nil {
411
+ return nil , fmt .Errorf ("Unable to lookup image %q: %w" , name , err )
412
+ }
413
+ images = append (images , image )
414
+ }
415
+
416
+ return images , nil
409
417
}
410
418
411
419
// 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.
420
+ // registry. On successful pull it returns the image in local storage.
414
421
//
415
422
// 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 ) {
423
+ func (r * Runtime ) copyFromRegistry (ctx context.Context , ref types.ImageReference , inputName string , pullPolicy config.PullPolicy , options * PullOptions ) ([]* Image , error ) {
417
424
// Sanity check.
418
425
if err := pullPolicy .Validate (); err != nil {
419
426
return nil , err
@@ -424,7 +431,7 @@ func (r *Runtime) copyFromRegistry(ctx context.Context, ref types.ImageReference
424
431
if err != nil {
425
432
return nil , err
426
433
}
427
- return []string {pulled }, nil
434
+ return []* Image {pulled }, nil
428
435
}
429
436
430
437
// Copy all tags
@@ -434,7 +441,7 @@ func (r *Runtime) copyFromRegistry(ctx context.Context, ref types.ImageReference
434
441
return nil , err
435
442
}
436
443
437
- pulledIDs := []string {}
444
+ pulledImages := []* Image {}
438
445
for _ , tag := range tags {
439
446
select { // Let's be gentle with Podman remote.
440
447
case <- ctx .Done ():
@@ -450,19 +457,18 @@ func (r *Runtime) copyFromRegistry(ctx context.Context, ref types.ImageReference
450
457
if err != nil {
451
458
return nil , err
452
459
}
453
- pulledIDs = append (pulledIDs , pulled )
460
+ pulledImages = append (pulledImages , pulled )
454
461
}
455
462
456
- return pulledIDs , nil
463
+ return pulledImages , nil
457
464
}
458
465
459
466
// 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
467
+ // from a registry. On successful pull it returns the Image from the local storage
468
+ func (r * Runtime ) copySingleImageFromRegistry (ctx context.Context , imageName string , pullPolicy config.PullPolicy , options * PullOptions ) (* Image , error ) { //nolint:gocyclo
463
469
// Sanity check.
464
470
if err := pullPolicy .Validate (); err != nil {
465
- return "" , err
471
+ return nil , err
466
472
}
467
473
468
474
var (
@@ -487,14 +493,7 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
487
493
if options .OS != runtime .GOOS {
488
494
lookupImageOptions .OS = options .OS
489
495
}
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.
496
+
498
497
localImage , resolvedImageName , err = r .LookupImage (imageName , lookupImageOptions )
499
498
if err != nil && ! errors .Is (err , storage .ErrImageUnknown ) {
500
499
logrus .Errorf ("Looking up %s in local storage: %v" , imageName , err )
@@ -525,23 +524,23 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
525
524
if pullPolicy == config .PullPolicyNever {
526
525
if localImage != nil {
527
526
logrus .Debugf ("Pull policy %q and %s resolved to local image %s" , pullPolicy , imageName , resolvedImageName )
528
- return resolvedImageName , nil
527
+ return localImage , nil
529
528
}
530
529
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 )
530
+ return nil , fmt .Errorf ("%s: %w" , imageName , storage .ErrImageUnknown )
532
531
}
533
532
534
533
if pullPolicy == config .PullPolicyMissing && localImage != nil {
535
- return resolvedImageName , nil
534
+ return localImage , nil
536
535
}
537
536
538
537
// If we looked up the image by ID, we cannot really pull from anywhere.
539
538
if localImage != nil && strings .HasPrefix (localImage .ID (), imageName ) {
540
539
switch pullPolicy {
541
540
case config .PullPolicyAlways :
542
- return "" , fmt .Errorf ("pull policy is always but image has been referred to by ID (%s)" , imageName )
541
+ return nil , fmt .Errorf ("pull policy is always but image has been referred to by ID (%s)" , imageName )
543
542
default :
544
- return resolvedImageName , nil
543
+ return localImage , nil
545
544
}
546
545
}
547
546
@@ -566,9 +565,9 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
566
565
resolved , err := shortnames .Resolve (sys , imageName )
567
566
if err != nil {
568
567
if localImage != nil && pullPolicy == config .PullPolicyNewer {
569
- return resolvedImageName , nil
568
+ return localImage , nil
570
569
}
571
- return "" , err
570
+ return nil , err
572
571
}
573
572
574
573
// NOTE: Below we print the description from the short-name resolution.
@@ -601,7 +600,7 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
601
600
var resolvedReference types.ImageReference
602
601
c , err := r .newCopier (& options .CopyOptions , & resolvedReference )
603
602
if err != nil {
604
- return "" , err
603
+ return nil , err
605
604
}
606
605
defer c .Close ()
607
606
@@ -611,7 +610,7 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
611
610
logrus .Debugf ("Attempting to pull candidate %s for %s" , candidateString , imageName )
612
611
srcRef , err := registryTransport .NewReference (candidate .Value )
613
612
if err != nil {
614
- return "" , err
613
+ return nil , err
615
614
}
616
615
617
616
if pullPolicy == config .PullPolicyNewer && localImage != nil {
@@ -629,15 +628,15 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
629
628
630
629
destRef , err := storageTransport .Transport .ParseStoreReference (r .store , candidate .Value .String ())
631
630
if err != nil {
632
- return "" , err
631
+ return nil , err
633
632
}
634
633
635
634
if err := writeDesc (); err != nil {
636
- return "" , err
635
+ return nil , err
637
636
}
638
637
if options .Writer != nil {
639
638
if _ , err := io .WriteString (options .Writer , fmt .Sprintf ("Trying to pull %s...\n " , candidateString )); err != nil {
640
- return "" , err
639
+ return nil , err
641
640
}
642
641
}
643
642
if _ , err := c .Copy (ctx , srcRef , destRef ); err != nil {
@@ -654,22 +653,22 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
654
653
655
654
logrus .Debugf ("Pulled candidate %s successfully" , candidateString )
656
655
if resolvedReference == nil { // resolvedReference should always be set for storageTransport destinations
657
- return "" , fmt .Errorf ("internal error: After pulling %s, resolvedReference is nil" , candidateString )
656
+ return nil , fmt .Errorf ("internal error: After pulling %s, resolvedReference is nil" , candidateString )
658
657
}
659
658
_ , image , err := storageTransport .ResolveReference (resolvedReference )
660
659
if err != nil {
661
- return "" , fmt .Errorf ("resolving an already-resolved reference %q to the pulled image: %w" , transports .ImageName (resolvedReference ), err )
660
+ return nil , fmt .Errorf ("resolving an already-resolved reference %q to the pulled image: %w" , transports .ImageName (resolvedReference ), err )
662
661
}
663
- return image . ID , nil
662
+ return r . storageToImage ( image , resolvedReference ) , nil
664
663
}
665
664
666
665
if localImage != nil && pullPolicy == config .PullPolicyNewer {
667
- return resolvedImageName , nil
666
+ return localImage , nil
668
667
}
669
668
670
669
if len (pullErrors ) == 0 {
671
- return "" , fmt .Errorf ("internal error: no image pulled (pull policy %s)" , pullPolicy )
670
+ return nil , fmt .Errorf ("internal error: no image pulled (pull policy %s)" , pullPolicy )
672
671
}
673
672
674
- return "" , resolved .FormatPullErrors (pullErrors )
673
+ return nil , resolved .FormatPullErrors (pullErrors )
675
674
}
0 commit comments