Consider endpoint path when checking default host.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
a7481289bb
commit
005f9f7378
@ -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"
|
||||
@ -336,16 +335,20 @@ 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")
|
||||
}
|
||||
// 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
|
||||
return nil, errors.Wrap(err, "get default host")
|
||||
}
|
||||
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 append(endpoints, "https://"+defaultHost), nil
|
||||
}
|
||||
|
||||
// newTransport returns a new HTTP transport used to pull image.
|
||||
// TODO(random-liu): Create a library and share this code with `ctr`.
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user