Merge pull request #15389 from aidanhs/aphs-simpler-pull-codepath
Remove unnecessary function parameter, add mirror endpoint test
This commit is contained in:
commit
ec8bba861e
@ -677,6 +677,35 @@ func TestNewIndexInfo(t *testing.T) {
|
|||||||
testIndexInfo(config, expectedIndexInfos)
|
testIndexInfo(config, expectedIndexInfos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMirrorEndpointLookup(t *testing.T) {
|
||||||
|
containsMirror := func(endpoints []APIEndpoint) bool {
|
||||||
|
for _, pe := range endpoints {
|
||||||
|
if pe.URL == "my.mirror" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
s := Service{Config: makeServiceConfig([]string{"my.mirror"}, nil)}
|
||||||
|
imageName := IndexName + "/test/image"
|
||||||
|
|
||||||
|
pushAPIEndpoints, err := s.LookupPushEndpoints(imageName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if containsMirror(pushAPIEndpoints) {
|
||||||
|
t.Fatal("Push endpoint should not contain mirror")
|
||||||
|
}
|
||||||
|
|
||||||
|
pullAPIEndpoints, err := s.LookupPullEndpoints(imageName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !containsMirror(pullAPIEndpoints) {
|
||||||
|
t.Fatal("Pull endpoint should contain mirror")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPushRegistryTag(t *testing.T) {
|
func TestPushRegistryTag(t *testing.T) {
|
||||||
r := spawnTestRegistrySession(t)
|
r := spawnTestRegistrySession(t)
|
||||||
err := r.PushRegistryTag("foo42/bar", imageID, "stable", makeURL("/v1/"))
|
err := r.PushRegistryTag("foo42/bar", imageID, "stable", makeURL("/v1/"))
|
||||||
|
@ -113,36 +113,42 @@ func (s *Service) tlsConfigForMirror(mirror string) (*tls.Config, error) {
|
|||||||
// It gives preference to v2 endpoints over v1, mirrors over the actual
|
// It gives preference to v2 endpoints over v1, mirrors over the actual
|
||||||
// registry, and HTTPS over plain HTTP.
|
// registry, and HTTPS over plain HTTP.
|
||||||
func (s *Service) LookupPullEndpoints(repoName string) (endpoints []APIEndpoint, err error) {
|
func (s *Service) LookupPullEndpoints(repoName string) (endpoints []APIEndpoint, err error) {
|
||||||
return s.lookupEndpoints(repoName, false)
|
return s.lookupEndpoints(repoName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LookupPushEndpoints creates an list of endpoints to try to push to, in order of preference.
|
// LookupPushEndpoints creates an list of endpoints to try to push to, in order of preference.
|
||||||
// It gives preference to v2 endpoints over v1, and HTTPS over plain HTTP.
|
// It gives preference to v2 endpoints over v1, and HTTPS over plain HTTP.
|
||||||
// Mirrors are not included.
|
// Mirrors are not included.
|
||||||
func (s *Service) LookupPushEndpoints(repoName string) (endpoints []APIEndpoint, err error) {
|
func (s *Service) LookupPushEndpoints(repoName string) (endpoints []APIEndpoint, err error) {
|
||||||
return s.lookupEndpoints(repoName, true)
|
allEndpoints, err := s.lookupEndpoints(repoName)
|
||||||
|
if err == nil {
|
||||||
|
for _, endpoint := range allEndpoints {
|
||||||
|
if !endpoint.Mirror {
|
||||||
|
endpoints = append(endpoints, endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return endpoints, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) lookupEndpoints(repoName string, isPush bool) (endpoints []APIEndpoint, err error) {
|
func (s *Service) lookupEndpoints(repoName string) (endpoints []APIEndpoint, err error) {
|
||||||
var cfg = tlsconfig.ServerDefault
|
var cfg = tlsconfig.ServerDefault
|
||||||
tlsConfig := &cfg
|
tlsConfig := &cfg
|
||||||
if strings.HasPrefix(repoName, DefaultNamespace+"/") {
|
if strings.HasPrefix(repoName, DefaultNamespace+"/") {
|
||||||
if !isPush {
|
// v2 mirrors
|
||||||
// v2 mirrors for pull only
|
for _, mirror := range s.Config.Mirrors {
|
||||||
for _, mirror := range s.Config.Mirrors {
|
mirrorTLSConfig, err := s.tlsConfigForMirror(mirror)
|
||||||
mirrorTLSConfig, err := s.tlsConfigForMirror(mirror)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
endpoints = append(endpoints, APIEndpoint{
|
|
||||||
URL: mirror,
|
|
||||||
// guess mirrors are v2
|
|
||||||
Version: APIVersion2,
|
|
||||||
Mirror: true,
|
|
||||||
TrimHostname: true,
|
|
||||||
TLSConfig: mirrorTLSConfig,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
endpoints = append(endpoints, APIEndpoint{
|
||||||
|
URL: mirror,
|
||||||
|
// guess mirrors are v2
|
||||||
|
Version: APIVersion2,
|
||||||
|
Mirror: true,
|
||||||
|
TrimHostname: true,
|
||||||
|
TLSConfig: mirrorTLSConfig,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// v2 registry
|
// v2 registry
|
||||||
endpoints = append(endpoints, APIEndpoint{
|
endpoints = append(endpoints, APIEndpoint{
|
||||||
|
Loading…
Reference in New Issue
Block a user