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"
)
// pullStruct records a pair of prepared image references to try to pull (if not DockerArchive) or to pull all (if DockerArchive)
type pullStruct struct {
image string
srcRef types.ImageReference
dstRef types.ImageReference
shaPullName string
image string
srcRef types.ImageReference
dstRef types.ImageReference
}
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
}
// 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
// images names to try pulling in combination with the registries.conf file as well
func (i *Image) createNamesToPull() ([]*pullStruct, error) {
var (
pullNames []*pullStruct
pullNames []*nameToPull
imageName string
)
@ -279,7 +286,7 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
if err != nil {
return nil, errors.Wrapf(err, "unable to parse '%s'", i.InputName)
}
ps := pullStruct{
ps := nameToPull{
image: i.InputName,
srcRef: srcRef,
}
@ -303,7 +310,7 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
if err != nil {
return nil, errors.Wrapf(err, "unable to parse '%s'", i.InputName)
}
ps := pullStruct{
ps := nameToPull{
image: decomposedImage.assemble(),
srcRef: srcRef,
}
@ -311,8 +318,9 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
}
}
// Here we construct the destination reference
for _, pStruct := range pullNames {
// Here we construct the destination references
res := make([]*pullStruct, len(pullNames))
for j, pStruct := range pullNames {
dstName := pStruct.image
if pStruct.shaPullName != "" {
dstName = pStruct.shaPullName
@ -321,8 +329,11 @@ func (i *Image) createNamesToPull() ([]*pullStruct, error) {
if err != nil {
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 pullNames, nil
return res, nil
}