Merge pull request #14182 from jiangyaoguo/distinguish-registry-unavailable-and-pull-failure

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2015-10-16 16:22:22 -07:00
commit 916ddbca65
4 changed files with 11 additions and 3 deletions

View File

@ -105,7 +105,12 @@ func (puller *imagePuller) PullImage(pod *api.Pod, container *api.Container, pul
if err = puller.runtime.PullImage(spec, pullSecrets); err != nil {
puller.logIt(ref, "Failed", logPrefix, fmt.Sprintf("Failed to pull image %q: %v", container.Image, err), glog.Warning)
puller.backOff.Next(backOffKey, puller.backOff.Clock.Now())
return ErrImagePull, err.Error()
if err == RegistryUnavailable {
msg := fmt.Sprintf("image pull failed for %s because the registry is temporarily unavailable.", container.Image)
return err, msg
} else {
return ErrImagePull, err.Error()
}
}
puller.logIt(ref, "Pulled", logPrefix, fmt.Sprintf("Successfully pulled image %q", container.Image), glog.Info)
puller.backOff.GC()

View File

@ -45,6 +45,9 @@ var (
// Required Image is absent on host and PullPolicy is NeverPullImage
ErrImageNeverPull = errors.New("ErrImageNeverPull")
// Get http error when pulling image from registry
RegistryUnavailable = errors.New("RegistryUnavailable")
)
var ErrRunContainer = errors.New("RunContainerError")

View File

@ -130,7 +130,7 @@ func filterHTTPError(err error, image string) error {
jerr.Code == http.StatusServiceUnavailable ||
jerr.Code == http.StatusGatewayTimeout) {
glog.V(2).Infof("Pulling image %q failed: %v", image, err)
return fmt.Errorf("image pull failed for %s because the registry is temporarily unavailable.", image)
return kubecontainer.RegistryUnavailable
} else {
return err
}

View File

@ -257,7 +257,7 @@ func TestPullWithJSONError(t *testing.T) {
"Bad gateway": {
"ubuntu",
&jsonmessage.JSONError{Code: 502, Message: "<!doctype html>\n<html class=\"no-js\" lang=\"\">\n <head>\n </head>\n <body>\n <h1>Oops, there was an error!</h1>\n <p>We have been contacted of this error, feel free to check out <a href=\"http://status.docker.com/\">status.docker.com</a>\n to see if there is a bigger issue.</p>\n\n </body>\n</html>"},
"because the registry is temporarily unavailable",
kubecontainer.RegistryUnavailable.Error(),
},
}
for i, test := range tests {