Introduce nameToPull, move shaPullName in there

shaPullName is only used internally in createNamesToPull; so, introduce
a nameToPull as a variant of pullStruct which has shaPullName (and does not
have destRef).

Eventually, we want to split pullStruct preparation into easily-testable
store-independent name preparation, and a store-dependent and difficult-to-test
but trivial conversion using StorageTransport.ParseStoreReference.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1112
Approved by: rhatdan
This commit is contained in:
Miloslav Trmač 2018-07-18 23:20:36 +02:00 committed by Atomic Bot
parent 70589c326c
commit 775eb78f6b
1 changed files with 23 additions and 12 deletions

View File

@ -50,11 +50,11 @@ var (
DefaultLocalRepo = "localhost" DefaultLocalRepo = "localhost"
) )
// pullStruct records a pair of prepared image references to try to pull (if not DockerArchive) or to pull all (if DockerArchive)
type pullStruct struct { type pullStruct struct {
image string image string
srcRef types.ImageReference srcRef types.ImageReference
dstRef types.ImageReference dstRef types.ImageReference
shaPullName string
} }
func (ir *Runtime) getPullStruct(srcRef types.ImageReference, destName string) (*pullStruct, error) { func (ir *Runtime) getPullStruct(srcRef types.ImageReference, destName string) (*pullStruct, error) {
@ -257,11 +257,18 @@ func (i *Image) pullImage(ctx context.Context, writer io.Writer, authfile, signa
return images, nil return images, nil
} }
// nameToPull is a mapping between a resolved source and an expected store destination name (FIXME: clean up somehow?)
type nameToPull struct {
image string
srcRef types.ImageReference
shaPullName string
}
// createNamesToPull looks at a decomposed image and determines the possible // createNamesToPull looks at a decomposed image and determines the possible
// images names to try pulling in combination with the registries.conf file as well // images names to try pulling in combination with the registries.conf file as well
func (i *Image) createNamesToPull() ([]*pullStruct, error) { func (i *Image) createNamesToPull() ([]*pullStruct, error) {
var ( var (
pullNames []*pullStruct pullNames []*nameToPull
imageName string imageName string
) )
@ -279,7 +286,7 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "unable to parse '%s'", i.InputName) return nil, errors.Wrapf(err, "unable to parse '%s'", i.InputName)
} }
ps := pullStruct{ ps := nameToPull{
image: i.InputName, image: i.InputName,
srcRef: srcRef, srcRef: srcRef,
} }
@ -303,7 +310,7 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "unable to parse '%s'", i.InputName) return nil, errors.Wrapf(err, "unable to parse '%s'", i.InputName)
} }
ps := pullStruct{ ps := nameToPull{
image: decomposedImage.assemble(), image: decomposedImage.assemble(),
srcRef: srcRef, srcRef: srcRef,
} }
@ -311,8 +318,9 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
} }
} }
// Here we construct the destination reference // Here we construct the destination references
for _, pStruct := range pullNames { res := make([]*pullStruct, len(pullNames))
for j, pStruct := range pullNames {
dstName := pStruct.image dstName := pStruct.image
if pStruct.shaPullName != "" { if pStruct.shaPullName != "" {
dstName = pStruct.shaPullName dstName = pStruct.shaPullName
@ -321,8 +329,11 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error parsing dest reference name") return nil, errors.Wrapf(err, "error parsing dest reference name")
} }
pStruct.dstRef = destRef res[j] = &pullStruct{
image: pStruct.image,
srcRef: pStruct.srcRef,
dstRef: destRef,
}
} }
return res, nil
return pullNames, nil
} }