Skip to content

Commit

Permalink
Consider endpoint path when checking default host.
Browse files Browse the repository at this point in the history
Signed-off-by: Lantao Liu <lantaol@google.com>
  • Loading branch information
Random-Liu committed Aug 10, 2019
1 parent a748128 commit 005f9f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/server/image_pull.go
Expand Up @@ -32,7 +32,6 @@ import (
containerdimages "github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/remotes/docker"
"github.com/containerd/cri/pkg/util"
distribution "github.com/docker/distribution/reference"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -336,15 +335,19 @@ func (c *criService) registryHosts(auth *runtime.AuthConfig) docker.RegistryHost
func addDefaultEndpoint(endpoints []string, host string) ([]string, error) {
defaultHost, err := docker.DefaultHost(host)
if err != nil {
return nil, errors.Wrapf(err, "get default host")
return nil, errors.Wrap(err, "get default host")
}
// If the http endpoint is configured, do not try https.
if !util.InStringSlice(endpoints, "http://"+defaultHost) {
if !util.InStringSlice(endpoints, "https://"+defaultHost) {
return append(endpoints, "https://"+defaultHost), nil
for _, e := range endpoints {
u, err := url.Parse(e)
if err != nil {
return nil, errors.Wrap(err, "parse endpoint url")
}
if u.Host == host {
// Do not add default if the endpoint already exists.
return endpoints, nil
}
}
return endpoints, nil
return append(endpoints, "https://"+defaultHost), nil
}

// newTransport returns a new HTTP transport used to pull image.
Expand Down
13 changes: 13 additions & 0 deletions pkg/server/image_pull_test.go
Expand Up @@ -147,6 +147,19 @@ func TestAddDefaultEndpoint(t *testing.T) {
"https://registry-3.io",
},
},
"default endpoint in list with path": {
endpoints: []string{
"https://registry-1.io",
"https://registry-2.io",
"https://registry-3.io/path",
},
host: "registry-3.io",
expected: []string{
"https://registry-1.io",
"https://registry-2.io",
"https://registry-3.io/path",
},
},
} {
t.Logf("TestCase %q", desc)
got, err := addDefaultEndpoint(test.endpoints, test.host)
Expand Down

0 comments on commit 005f9f7

Please sign in to comment.