mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-27 09:12:07 +01:00
Support vpc and internal network (goharbor#17488) (#17489)
Signed-off-by: Back Yu <yhfszb@gmail.com>
This commit is contained in:
parent
26ce10221e
commit
fe236ecd2e
@ -33,7 +33,9 @@ func init() {
|
||||
// example:
|
||||
// https://registry.%s.aliyuncs.com
|
||||
// https://cr.%s.aliyuncs.com
|
||||
var regRegion = regexp.MustCompile(`https://(registry|cr)\.([\w\-]+)\.aliyuncs\.com`)
|
||||
// https://registry-vpc.%s.aliyuncs.com
|
||||
// https://registry-internal.%s.aliyuncs.com
|
||||
var regRegion = regexp.MustCompile(`https://(registry|cr|registry-vpc|registry-internal)\.([\w\-]+)\.aliyuncs\.com`)
|
||||
|
||||
func getRegion(url string) (region string, err error) {
|
||||
if url == "" {
|
||||
@ -52,8 +54,15 @@ func newAdapter(registry *model.Registry) (*adapter, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// fix url (allow user input cr service url)
|
||||
registry.URL = fmt.Sprintf(registryEndpointTpl, region)
|
||||
switch true {
|
||||
case strings.Contains(registry.URL, "registry-vpc"):
|
||||
registry.URL = fmt.Sprintf(registryVPCEndpointTpl, region)
|
||||
case strings.Contains(registry.URL, "registry-internal"):
|
||||
registry.URL = fmt.Sprintf(registryInternalEndpointTpl, region)
|
||||
default:
|
||||
// fix url (allow user input cr service url)
|
||||
registry.URL = fmt.Sprintf(registryEndpointTpl, region)
|
||||
}
|
||||
realm, service, err := util.Ping(registry)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -153,6 +162,14 @@ func getAdapterInfo() *model.AdapterPattern {
|
||||
Key: e,
|
||||
Value: fmt.Sprintf("https://registry.%s.aliyuncs.com", e),
|
||||
})
|
||||
endpoints = append(endpoints, &model.Endpoint{
|
||||
Key: e + "-vpc",
|
||||
Value: fmt.Sprintf("https://registry-vpc.%s.aliyuncs.com", e),
|
||||
})
|
||||
endpoints = append(endpoints, &model.Endpoint{
|
||||
Key: e + "-internal",
|
||||
Value: fmt.Sprintf("https://registry-internal.%s.aliyuncs.com", e),
|
||||
})
|
||||
}
|
||||
info := &model.AdapterPattern{
|
||||
EndpointPattern: &model.EndpointPattern{
|
||||
|
@ -89,6 +89,8 @@ func Test_getRegion(t *testing.T) {
|
||||
{"registry shanghai", "https://registry.cn-shanghai.aliyuncs.com", "cn-shanghai", false},
|
||||
{"invalid registry shanghai", "http://registry.cn-shanghai.aliyuncs.com", "", true},
|
||||
{"registry hangzhou", "https://registry.cn-hangzhou.aliyuncs.com", "cn-hangzhou", false},
|
||||
{"registry hangzhou vpc", "https://registry-vpc.cn-hangzhou.aliyuncs.com", "cn-hangzhou", false},
|
||||
{"registry hangzhou internal", "https://registry-internal.cn-hangzhou.aliyuncs.com", "cn-hangzhou", false},
|
||||
{"cr shanghai", "https://cr.cn-shanghai.aliyuncs.com", "cn-shanghai", false},
|
||||
{"cr hangzhou", "https://cr.cn-hangzhou.aliyuncs.com", "cn-hangzhou", false},
|
||||
{"invalid cr url", "https://acr.cn-hangzhou.aliyuncs.com", "", true},
|
||||
@ -108,6 +110,8 @@ func Test_getRegion(t *testing.T) {
|
||||
var urlForBenchmark = []string{
|
||||
"https://cr.cn-hangzhou.aliyuncs.com",
|
||||
"https://registry.cn-shanghai.aliyuncs.com",
|
||||
"https://registry-vpc.cn-shanghai.aliyuncs.com",
|
||||
"https://registry-internal.cn-shanghai.aliyuncs.com",
|
||||
}
|
||||
|
||||
func BenchmarkGetRegion(b *testing.B) {
|
||||
|
@ -3,8 +3,10 @@ package aliacr
|
||||
import "time"
|
||||
|
||||
const (
|
||||
registryEndpointTpl = "https://registry.%s.aliyuncs.com"
|
||||
endpointTpl = "cr.%s.aliyuncs.com"
|
||||
registryEndpointTpl = "https://registry.%s.aliyuncs.com"
|
||||
registryVPCEndpointTpl = "https://registry-vpc.%s.aliyuncs.com"
|
||||
registryInternalEndpointTpl = "https://registry-internal.%s.aliyuncs.com"
|
||||
endpointTpl = "cr.%s.aliyuncs.com"
|
||||
)
|
||||
|
||||
type authorizationToken struct {
|
||||
|
@ -113,6 +113,166 @@ describe('CreateEditEndpointComponent (inline template)', () => {
|
||||
key: 'me-east-1',
|
||||
value: 'https://registry.me-east-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-hangzhou-vpc',
|
||||
value: 'https://registry-vpc.cn-hangzhou.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-shanghai-vpc',
|
||||
value: 'https://registry-vpc.cn-shanghai.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-qingdao-vpc',
|
||||
value: 'https://registry-vpc.cn-qingdao.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-beijing-vpc',
|
||||
value: 'https://registry-vpc.cn-beijing.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-zhangjiakou-vpc',
|
||||
value: 'https://registry-vpc.cn-zhangjiakou.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-huhehaote-vpc',
|
||||
value: 'https://registry-vpc.cn-huhehaote.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-shenzhen-vpc',
|
||||
value: 'https://registry-vpc.cn-shenzhen.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-chengdu-vpc',
|
||||
value: 'https://registry-vpc.cn-chengdu.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-hongkong-vpc',
|
||||
value: 'https://registry-vpc.cn-hongkong.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-1-vpc',
|
||||
value: 'https://registry-vpc.ap-southeast-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-2-vpc',
|
||||
value: 'https://registry-vpc.ap-southeast-2.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-3-vpc',
|
||||
value: 'https://registry-vpc.ap-southeast-3.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-5-vpc',
|
||||
value: 'https://registry-vpc.ap-southeast-5.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-northeast-1-vpc',
|
||||
value: 'https://registry-vpc.ap-northeast-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-south-1-vpc',
|
||||
value: 'https://registry-vpc.ap-south-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'eu-central-1-vpc',
|
||||
value: 'https://registry-vpc.eu-central-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'eu-west-1-vpc',
|
||||
value: 'https://registry-vpc.eu-west-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'us-west-1-vpc',
|
||||
value: 'https://registry-vpc.us-west-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'us-east-1-vpc',
|
||||
value: 'https://registry-vpc.us-east-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'me-east-1-vpc',
|
||||
value: 'https://registry-vpc.me-east-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-hangzhou-internal',
|
||||
value: 'https://registry-internal.cn-hangzhou.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-shanghai-internal',
|
||||
value: 'https://registry-internal.cn-shanghai.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-qingdao-internal',
|
||||
value: 'https://registry-internal.cn-qingdao.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-beijing-internal',
|
||||
value: 'https://registry-internal.cn-beijing.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-zhangjiakou-internal',
|
||||
value: 'https://registry-internal.cn-zhangjiakou.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-huhehaote-internal',
|
||||
value: 'https://registry-internal.cn-huhehaote.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-shenzhen-internal',
|
||||
value: 'https://registry-internal.cn-shenzhen.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-chengdu-internal',
|
||||
value: 'https://registry-internal.cn-chengdu.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-hongkong-internal',
|
||||
value: 'https://registry-internal.cn-hongkong.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-1-internal',
|
||||
value: 'https://registry-internal.ap-southeast-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-2-internal',
|
||||
value: 'https://registry-internal.ap-southeast-2.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-3-internal',
|
||||
value: 'https://registry-internal.ap-southeast-3.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-5-internal',
|
||||
value: 'https://registry-internal.ap-southeast-5.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-northeast-1-internal',
|
||||
value: 'https://registry-internal.ap-northeast-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-south-1-internal',
|
||||
value: 'https://registry-internal.ap-south-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'eu-central-1-internal',
|
||||
value: 'https://registry-internal.eu-central-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'eu-west-1-internal',
|
||||
value: 'https://registry-internal.eu-west-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'us-west-1-internal',
|
||||
value: 'https://registry-internal.us-west-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'us-east-1-internal',
|
||||
value: 'https://registry-internal.us-east-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'me-east-1-internal',
|
||||
value: 'https://registry-internal.me-east-1.aliyuncs.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
credential_pattern: null,
|
||||
|
@ -103,6 +103,166 @@ describe('EndpointComponent (inline template)', () => {
|
||||
key: 'me-east-1',
|
||||
value: 'https://registry.me-east-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-hangzhou-vpc',
|
||||
value: 'https://registry-vpc.cn-hangzhou.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-shanghai-vpc',
|
||||
value: 'https://registry-vpc.cn-shanghai.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-qingdao-vpc',
|
||||
value: 'https://registry-vpc.cn-qingdao.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-beijing-vpc',
|
||||
value: 'https://registry-vpc.cn-beijing.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-zhangjiakou-vpc',
|
||||
value: 'https://registry-vpc.cn-zhangjiakou.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-huhehaote-vpc',
|
||||
value: 'https://registry-vpc.cn-huhehaote.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-shenzhen-vpc',
|
||||
value: 'https://registry-vpc.cn-shenzhen.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-chengdu-vpc',
|
||||
value: 'https://registry-vpc.cn-chengdu.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-hongkong-vpc',
|
||||
value: 'https://registry-vpc.cn-hongkong.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-1-vpc',
|
||||
value: 'https://registry-vpc.ap-southeast-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-2-vpc',
|
||||
value: 'https://registry-vpc.ap-southeast-2.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-3-vpc',
|
||||
value: 'https://registry-vpc.ap-southeast-3.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-5-vpc',
|
||||
value: 'https://registry-vpc.ap-southeast-5.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-northeast-1-vpc',
|
||||
value: 'https://registry-vpc.ap-northeast-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-south-1-vpc',
|
||||
value: 'https://registry-vpc.ap-south-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'eu-central-1-vpc',
|
||||
value: 'https://registry-vpc.eu-central-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'eu-west-1-vpc',
|
||||
value: 'https://registry-vpc.eu-west-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'us-west-1-vpc',
|
||||
value: 'https://registry-vpc.us-west-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'us-east-1-vpc',
|
||||
value: 'https://registry-vpc.us-east-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'me-east-1-vpc',
|
||||
value: 'https://registry-vpc.me-east-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-hangzhou-internal',
|
||||
value: 'https://registry-internal.cn-hangzhou.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-shanghai-internal',
|
||||
value: 'https://registry-internal.cn-shanghai.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-qingdao-internal',
|
||||
value: 'https://registry-internal.cn-qingdao.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-beijing-internal',
|
||||
value: 'https://registry-internal.cn-beijing.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-zhangjiakou-internal',
|
||||
value: 'https://registry-internal.cn-zhangjiakou.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-huhehaote-internal',
|
||||
value: 'https://registry-internal.cn-huhehaote.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-shenzhen-internal',
|
||||
value: 'https://registry-internal.cn-shenzhen.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-chengdu-internal',
|
||||
value: 'https://registry-internal.cn-chengdu.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'cn-hongkong-internal',
|
||||
value: 'https://registry-internal.cn-hongkong.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-1-internal',
|
||||
value: 'https://registry-internal.ap-southeast-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-2-internal',
|
||||
value: 'https://registry-internal.ap-southeast-2.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-3-internal',
|
||||
value: 'https://registry-internal.ap-southeast-3.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-southeast-5-internal',
|
||||
value: 'https://registry-internal.ap-southeast-5.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-northeast-1-internal',
|
||||
value: 'https://registry-internal.ap-northeast-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'ap-south-1-internal',
|
||||
value: 'https://registry-internal.ap-south-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'eu-central-1-internal',
|
||||
value: 'https://registry-internal.eu-central-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'eu-west-1-internal',
|
||||
value: 'https://registry-internal.eu-west-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'us-west-1-internal',
|
||||
value: 'https://registry-internal.us-west-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'us-east-1-internal',
|
||||
value: 'https://registry-internal.us-east-1.aliyuncs.com',
|
||||
},
|
||||
{
|
||||
key: 'me-east-1-internal',
|
||||
value: 'https://registry-internal.me-east-1.aliyuncs.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
credential_pattern: null,
|
||||
|
Loading…
Reference in New Issue
Block a user