distribution: un-export internal errors and error-utilities
un-exports errors that were only used internally: - Remove ErrNoSupport as it was not emitted anywhere - ImageConfigPullError -> imageConfigPullError - TranslatePullError() -> translatePullError() Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
fb5485f5d0
commit
074e41679d
4 changed files with 16 additions and 50 deletions
|
@ -18,17 +18,6 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrNoSupport is an error type used for errors indicating that an operation
|
|
||||||
// is not supported. It encapsulates a more specific error.
|
|
||||||
type ErrNoSupport struct{ Err error }
|
|
||||||
|
|
||||||
func (e ErrNoSupport) Error() string {
|
|
||||||
if e.Err == nil {
|
|
||||||
return "not supported"
|
|
||||||
}
|
|
||||||
return e.Err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallbackError wraps an error that can possibly allow fallback to a different
|
// fallbackError wraps an error that can possibly allow fallback to a different
|
||||||
// endpoint.
|
// endpoint.
|
||||||
type fallbackError struct {
|
type fallbackError struct {
|
||||||
|
@ -74,18 +63,18 @@ func (e notFoundError) Cause() error {
|
||||||
return e.cause
|
return e.cause
|
||||||
}
|
}
|
||||||
|
|
||||||
// TranslatePullError is used to convert an error from a registry pull
|
// translatePullError is used to convert an error from a registry pull
|
||||||
// operation to an error representing the entire pull operation. Any error
|
// operation to an error representing the entire pull operation. Any error
|
||||||
// information which is not used by the returned error gets output to
|
// information which is not used by the returned error gets output to
|
||||||
// log at info level.
|
// log at info level.
|
||||||
func TranslatePullError(err error, ref reference.Named) error {
|
func translatePullError(err error, ref reference.Named) error {
|
||||||
switch v := err.(type) {
|
switch v := err.(type) {
|
||||||
case errcode.Errors:
|
case errcode.Errors:
|
||||||
if len(v) != 0 {
|
if len(v) != 0 {
|
||||||
for _, extra := range v[1:] {
|
for _, extra := range v[1:] {
|
||||||
logrus.Infof("Ignoring extra error returned from registry: %v", extra)
|
logrus.WithError(extra).Infof("Ignoring extra error returned from registry")
|
||||||
}
|
}
|
||||||
return TranslatePullError(v[0], ref)
|
return translatePullError(v[0], ref)
|
||||||
}
|
}
|
||||||
case errcode.Error:
|
case errcode.Error:
|
||||||
switch v.Code {
|
switch v.Code {
|
||||||
|
@ -93,7 +82,7 @@ func TranslatePullError(err error, ref reference.Named) error {
|
||||||
return notFoundError{v, ref}
|
return notFoundError{v, ref}
|
||||||
}
|
}
|
||||||
case xfer.DoNotRetry:
|
case xfer.DoNotRetry:
|
||||||
return TranslatePullError(v.Err, ref)
|
return translatePullError(v.Err, ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errdefs.Unknown(err)
|
return errdefs.Unknown(err)
|
||||||
|
@ -125,14 +114,12 @@ func continueOnError(err error, mirrorEndpoint bool) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return continueOnError(v[0], mirrorEndpoint)
|
return continueOnError(v[0], mirrorEndpoint)
|
||||||
case ErrNoSupport:
|
|
||||||
return continueOnError(v.Err, mirrorEndpoint)
|
|
||||||
case errcode.Error:
|
case errcode.Error:
|
||||||
return mirrorEndpoint
|
return mirrorEndpoint
|
||||||
case *client.UnexpectedHTTPResponseError:
|
case *client.UnexpectedHTTPResponseError:
|
||||||
return true
|
return true
|
||||||
case ImageConfigPullError:
|
case imageConfigPullError:
|
||||||
// ImageConfigPullError only happens with v2 images, v1 fallback is
|
// imageConfigPullError only happens with v2 images, v1 fallback is
|
||||||
// unnecessary.
|
// unnecessary.
|
||||||
// Failures from a mirror endpoint should result in fallback to the
|
// Failures from a mirror endpoint should result in fallback to the
|
||||||
// canonical repo.
|
// canonical repo.
|
||||||
|
|
|
@ -18,15 +18,13 @@ var alwaysContinue = []error{
|
||||||
errUnexpected,
|
errUnexpected,
|
||||||
// nested
|
// nested
|
||||||
errcode.Errors{errUnexpected},
|
errcode.Errors{errUnexpected},
|
||||||
ErrNoSupport{Err: errUnexpected},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var continueFromMirrorEndpoint = []error{
|
var continueFromMirrorEndpoint = []error{
|
||||||
ImageConfigPullError{},
|
imageConfigPullError{},
|
||||||
errcode.Error{},
|
errcode.Error{},
|
||||||
// nested
|
// nested
|
||||||
errcode.Errors{errcode.Error{}},
|
errcode.Errors{errcode.Error{}},
|
||||||
ErrNoSupport{Err: errcode.Error{}},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var neverContinue = []error{
|
var neverContinue = []error{
|
||||||
|
|
|
@ -64,15 +64,6 @@ func Pull(ctx context.Context, ref reference.Named, imagePullConfig *ImagePullCo
|
||||||
var (
|
var (
|
||||||
lastErr error
|
lastErr error
|
||||||
|
|
||||||
// discardNoSupportErrors is used to track whether an endpoint encountered an error of type registry.ErrNoSupport
|
|
||||||
// By default it is false, which means that if an ErrNoSupport error is encountered, it will be saved in lastErr.
|
|
||||||
// As soon as another kind of error is encountered, discardNoSupportErrors is set to true, avoiding the saving of
|
|
||||||
// any subsequent ErrNoSupport errors in lastErr.
|
|
||||||
// It's needed for pull-by-digest on v1 endpoints: if there are only v1 endpoints configured, the error should be
|
|
||||||
// returned and displayed, but if there was a v2 endpoint which supports pull-by-digest, then the last relevant
|
|
||||||
// error is the ones from v2 endpoints not v1.
|
|
||||||
discardNoSupportErrors bool
|
|
||||||
|
|
||||||
// confirmedTLSRegistries is a map indicating which registries
|
// confirmedTLSRegistries is a map indicating which registries
|
||||||
// are known to be using TLS. There should never be a plaintext
|
// are known to be using TLS. There should never be a plaintext
|
||||||
// retry for any of these.
|
// retry for any of these.
|
||||||
|
@ -110,22 +101,12 @@ func Pull(ctx context.Context, ref reference.Named, imagePullConfig *ImagePullCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fallback {
|
if fallback {
|
||||||
if _, ok := err.(ErrNoSupport); !ok {
|
lastErr = err
|
||||||
// Because we found an error that's not ErrNoSupport, discard all subsequent ErrNoSupport errors.
|
|
||||||
discardNoSupportErrors = true
|
|
||||||
// append subsequent errors
|
|
||||||
lastErr = err
|
|
||||||
} else if !discardNoSupportErrors {
|
|
||||||
// Save the ErrNoSupport error, because it's either the first error or all encountered errors
|
|
||||||
// were also ErrNoSupport errors.
|
|
||||||
// append subsequent errors
|
|
||||||
lastErr = err
|
|
||||||
}
|
|
||||||
logrus.Infof("Attempting next endpoint for pull after error: %v", err)
|
logrus.Infof("Attempting next endpoint for pull after error: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logrus.Errorf("Not continuing with pull after error: %v", err)
|
logrus.Errorf("Not continuing with pull after error: %v", err)
|
||||||
return TranslatePullError(err, ref)
|
return translatePullError(err, ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
imagePullConfig.ImageEventLogger(reference.FamiliarString(ref), reference.FamiliarName(repoInfo.Name), "pull")
|
imagePullConfig.ImageEventLogger(reference.FamiliarString(ref), reference.FamiliarName(repoInfo.Name), "pull")
|
||||||
|
@ -136,7 +117,7 @@ func Pull(ctx context.Context, ref reference.Named, imagePullConfig *ImagePullCo
|
||||||
lastErr = fmt.Errorf("no endpoints found for %s", reference.FamiliarString(ref))
|
lastErr = fmt.Errorf("no endpoints found for %s", reference.FamiliarString(ref))
|
||||||
}
|
}
|
||||||
|
|
||||||
return TranslatePullError(lastErr, ref)
|
return translatePullError(lastErr, ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeStatus writes a status message to out. If layersDownloaded is true, the
|
// writeStatus writes a status message to out. If layersDownloaded is true, the
|
||||||
|
|
|
@ -41,14 +41,14 @@ var (
|
||||||
errRootFSInvalid = errors.New("invalid rootfs in image configuration")
|
errRootFSInvalid = errors.New("invalid rootfs in image configuration")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageConfigPullError is an error pulling the image config blob
|
// imageConfigPullError is an error pulling the image config blob
|
||||||
// (only applies to schema2).
|
// (only applies to schema2).
|
||||||
type ImageConfigPullError struct {
|
type imageConfigPullError struct {
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error returns the error string for ImageConfigPullError.
|
// Error returns the error string for imageConfigPullError.
|
||||||
func (e ImageConfigPullError) Error() string {
|
func (e imageConfigPullError) Error() string {
|
||||||
return "error pulling image configuration: " + e.Err.Error()
|
return "error pulling image configuration: " + e.Err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,7 +619,7 @@ func (p *v2Puller) pullSchema2Layers(ctx context.Context, target distribution.De
|
||||||
go func() {
|
go func() {
|
||||||
configJSON, err := p.pullSchema2Config(ctx, target.Digest)
|
configJSON, err := p.pullSchema2Config(ctx, target.Digest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
configErrChan <- ImageConfigPullError{Err: err}
|
configErrChan <- imageConfigPullError{Err: err}
|
||||||
cancel()
|
cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue