Migrate unit tests for image pulling credentials and error handling

Also remove the dockertools package completely.
This commit is contained in:
Yu-Ju Hong
2017-05-03 18:42:29 -07:00
parent 48caf95a6c
commit 4b72d229f7
10 changed files with 152 additions and 383 deletions

View File

@@ -18,10 +18,12 @@ package dockershim
import (
"fmt"
"net/http"
"github.com/docker/docker/pkg/jsonmessage"
dockertypes "github.com/docker/engine-api/types"
runtimeapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
runtimeapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/dockershim/libdocker"
)
@@ -80,7 +82,7 @@ func (ds *dockerService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi
dockertypes.ImagePullOptions{},
)
if err != nil {
return "", err
return "", filterHTTPError(err, image.Image)
}
return getImageRef(ds.client, image.Image)
@@ -127,3 +129,18 @@ func getImageRef(client libdocker.Interface, image string) (string, error) {
func (ds *dockerService) ImageFsInfo() (*runtimeapi.FsInfo, error) {
return nil, fmt.Errorf("not implemented")
}
func filterHTTPError(err error, image string) error {
// docker/docker/pull/11314 prints detailed error info for docker pull.
// When it hits 502, it returns a verbose html output including an inline svg,
// which makes the output of kubectl get pods much harder to parse.
// Here converts such verbose output to a concise one.
jerr, ok := err.(*jsonmessage.JSONError)
if ok && (jerr.Code == http.StatusBadGateway ||
jerr.Code == http.StatusServiceUnavailable ||
jerr.Code == http.StatusGatewayTimeout) {
return fmt.Errorf("RegistryUnavailable: %v", err)
}
return err
}