in ecr/base.go [115:162]
func (b *ecrBase) runGetImage(ctx context.Context, batchGetImageInput ecr.BatchGetImageInput) (*ecr.Image, error) {
// Allow only a single image to be fetched at a time.
if len(batchGetImageInput.ImageIds) != 1 {
return nil, errGetImageUnhandled
}
batchGetImageInput.RegistryId = aws.String(b.ecrSpec.Registry())
batchGetImageInput.RepositoryName = aws.String(b.ecrSpec.Repository)
log.G(ctx).WithField("batchGetImageInput", batchGetImageInput).Trace("ecr.base.image: requesting images")
batchGetImageOutput, err := b.client.BatchGetImageWithContext(ctx, &batchGetImageInput)
if err != nil {
log.G(ctx).WithError(err).Error("ecr.base.image: failed to get image")
return nil, err
}
log.G(ctx).WithField("batchGetImageOutput", batchGetImageOutput).Trace("ecr.base.image: api response")
// Summarize image request failures for handled errors. Only the first
// failure is checked as only a single ImageIdentifier is allowed to be
// queried for.
if len(batchGetImageOutput.Failures) > 0 {
failure := batchGetImageOutput.Failures[0]
switch aws.StringValue(failure.FailureCode) {
// Requested image with a corresponding tag and digest does not exist.
// This failure will generally occur when pushing an updated (or new)
// image with a tag.
case ecr.ImageFailureCodeImageTagDoesNotMatchDigest:
log.G(ctx).WithField("failure", failure).Debug("ecr.base.image: no matching image with specified digest")
return nil, errImageNotFound
// Requested image doesn't resolve to a known image. A new image will
// result in an ImageNotFound error when checked before push.
case ecr.ImageFailureCodeImageNotFound:
log.G(ctx).WithField("failure", failure).Debug("ecr.base.image: no image found")
return nil, errImageNotFound
// Requested image identifiers are invalid.
case ecr.ImageFailureCodeInvalidImageDigest, ecr.ImageFailureCodeInvalidImageTag:
log.G(ctx).WithField("failure", failure).Error("ecr.base.image: invalid image identifier")
return nil, reference.ErrInvalid
// Unhandled failure reported for image request made.
default:
log.G(ctx).WithField("failure", failure).Warn("ecr.base.image: unhandled image request failure")
return nil, errGetImageUnhandled
}
}
return batchGetImageOutput.Images[0], nil
}