mirror of https://github.com/k3s-io/k3s
Use docker's ParseRepositoryTag when pulling
parent
73229ed660
commit
c08f41c18b
|
@ -35,6 +35,7 @@ import (
|
|||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/leaky"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
@ -325,7 +326,7 @@ func NewDockerContainerCommandRunner(client DockerInterface) ContainerCommandRun
|
|||
}
|
||||
|
||||
func (p dockerPuller) Pull(image string) error {
|
||||
image, tag := parseImageName(image)
|
||||
_, tag := parsers.ParseRepositoryTag(image)
|
||||
|
||||
// If no tag was specified, use the default "latest".
|
||||
if len(tag) == 0 {
|
||||
|
@ -379,16 +380,6 @@ func (p dockerPuller) IsImagePresent(image string) (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
|
||||
// RequireLatestImage returns if the user wants the latest image
|
||||
func RequireLatestImage(name string) bool {
|
||||
_, tag := parseImageName(name)
|
||||
|
||||
if tag == "latest" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p throttledDockerPuller) IsImagePresent(name string) (bool, error) {
|
||||
return p.puller.IsImagePresent(name)
|
||||
}
|
||||
|
@ -771,29 +762,6 @@ func GetRunningContainers(client DockerInterface, ids []string) ([]*docker.Conta
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// Parses image name including a tag and returns image name and tag.
|
||||
// TODO: Future Docker versions can parse the tag on daemon side, see
|
||||
// https://github.com/dotcloud/docker/issues/6876
|
||||
// So this can be deprecated at some point.
|
||||
func parseImageName(image string) (string, string) {
|
||||
tag := ""
|
||||
parts := strings.SplitN(image, "/", 2)
|
||||
repo := ""
|
||||
if len(parts) == 2 {
|
||||
repo = parts[0]
|
||||
image = parts[1]
|
||||
}
|
||||
parts = strings.SplitN(image, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
image = parts[0]
|
||||
tag = parts[1]
|
||||
}
|
||||
if repo != "" {
|
||||
image = fmt.Sprintf("%s/%s", repo, image)
|
||||
}
|
||||
return image, tag
|
||||
}
|
||||
|
||||
// Get a docker endpoint, either from the string passed in, or $DOCKER_HOST environment variables
|
||||
func getDockerEndpoint(dockerEndpoint string) string {
|
||||
var endpoint string
|
||||
|
|
|
@ -179,29 +179,6 @@ func TestDockerContainerCommand(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
var parseImageNameTests = []struct {
|
||||
imageName string
|
||||
name string
|
||||
tag string
|
||||
}{
|
||||
{"ubuntu", "ubuntu", ""},
|
||||
{"ubuntu:2342", "ubuntu", "2342"},
|
||||
{"ubuntu:latest", "ubuntu", "latest"},
|
||||
{"foo/bar:445566", "foo/bar", "445566"},
|
||||
{"registry.example.com:5000/foobar", "registry.example.com:5000/foobar", ""},
|
||||
{"registry.example.com:5000/foobar:5342", "registry.example.com:5000/foobar", "5342"},
|
||||
{"registry.example.com:5000/foobar:latest", "registry.example.com:5000/foobar", "latest"},
|
||||
}
|
||||
|
||||
func TestParseImageName(t *testing.T) {
|
||||
for _, tt := range parseImageNameTests {
|
||||
name, tag := parseImageName(tt.imageName)
|
||||
if name != tt.name || tag != tt.tag {
|
||||
t.Errorf("Expected name/tag: %s/%s, got %s/%s", tt.name, tt.tag, name, tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDockerKeyringLookupFails(t *testing.T) {
|
||||
fakeKeyring := &credentialprovider.FakeKeyring{}
|
||||
fakeClient := &FakeDockerClient{
|
||||
|
@ -217,7 +194,7 @@ func TestDockerKeyringLookupFails(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
msg := "image pull failed for host/repository/image, this may be because there are no credentials on this request. details: (test error)"
|
||||
msg := "image pull failed for host/repository/image:version, this may be because there are no credentials on this request. details: (test error)"
|
||||
if err.Error() != msg {
|
||||
t.Errorf("expected: %s, saw: %s", msg, err.Error())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue