Merge pull request #3551 from reasonerjt/configure-endpoints

Make the internal URL of UI and JobService configurable
This commit is contained in:
Daniel Jiang 2017-11-05 22:33:05 +08:00 committed by GitHub
commit 9b37c2b01d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 3 deletions

View File

@ -42,3 +42,5 @@ RESET=false
UAA_ENDPOINT=$uaa_endpoint
UAA_CLIENTID=$uaa_clientid
UAA_CLIENTSECRET=$uaa_clientsecret
UI_URL=http://ui
JOBSERVICE_URL=http://jobservice

View File

@ -123,6 +123,11 @@ var (
parse: parseStringToBool,
},
common.ClairDBPassword: "CLAIR_DB_PASSWORD",
common.UAAEndpoint: "UAA_ENDPOINT",
common.UAAClientID: "UAA_CLIENTID",
common.UAAClientSecret: "UAA_CLIENTSECRET",
common.UIURL: "UI_URL",
common.JobServiceURL: "JOBSERVICE_URL",
}
// configurations need read from environment variables

View File

@ -38,6 +38,8 @@ const (
MySQLDatabase = "mysql_database"
SQLiteFile = "sqlite_file"
SelfRegistration = "self_registration"
UIURL = "ui_url"
JobServiceURL = "jobservice_url"
LDAPURL = "ldap_url"
LDAPSearchDN = "ldap_search_dn"
LDAPSearchPwd = "ldap_search_password"

View File

@ -63,6 +63,8 @@ var adminServerDefaultConfig = map[string]interface{}{
common.UAAClientID: "testid",
common.UAAClientSecret: "testsecret",
common.UAAEndpoint: "10.192.168.5",
common.UIURL: "http://myui:8888/",
common.JobServiceURL: "http://myjob:8888/",
}
// NewAdminserver returns a mock admin server

View File

@ -17,6 +17,7 @@ package config
import (
"fmt"
"os"
"strings"
"github.com/vmware/harbor/src/adminserver/client"
"github.com/vmware/harbor/src/adminserver/client/auth"
@ -107,7 +108,13 @@ func MaxJobWorkers() (int, error) {
// LocalUIURL returns the local ui url, job service will use this URL to call API hosted on ui process
func LocalUIURL() string {
return "http://ui"
cfg, err := mg.Get()
if err != nil {
log.Warningf("Failed to Get job service UI URL from backend, error: %v, will return default value.")
return "http://ui"
}
return strings.TrimSuffix(cfg[common.UIURL].(string), "/")
}
// LocalRegURL returns the local registry url, job service will use this URL to pull image from the registry

View File

@ -18,6 +18,7 @@ import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/vmware/harbor/src/common/utils/test"
)
@ -40,6 +41,7 @@ func TestConfig(t *testing.T) {
return
}
defer os.Remove(secretKeyPath)
assert := assert.New(t)
if err := os.Setenv("KEY_PATH", secretKeyPath); err != nil {
t.Fatalf("failed to set env %s: %v", "KEY_PATH", err)
@ -76,4 +78,5 @@ func TestConfig(t *testing.T) {
if _, err := ExtEndpoint(); err != nil {
t.Fatalf("failed to get ext endpoint: %v", err)
}
assert.Equal("http://myui:8888", LocalUIURL())
}

View File

@ -244,12 +244,26 @@ func RegistryURL() (string, error) {
// InternalJobServiceURL returns jobservice URL for internal communication between Harbor containers
func InternalJobServiceURL() string {
return "http://jobservice"
cfg, err := mg.Get()
if err != nil {
log.Warningf("Failed to Get job service URL from backend, error: %v, will return default value.")
return "http://jobservice"
}
return strings.TrimSuffix(cfg[common.JobServiceURL].(string), "/")
}
// InternalTokenServiceEndpoint returns token service endpoint for internal communication between Harbor containers
func InternalTokenServiceEndpoint() string {
return "http://ui/service/token"
uiURL := "http://ui"
cfg, err := mg.Get()
if err != nil {
log.Warningf("Failed to Get job service UI URL from backend, error: %v, will use default value.")
} else {
uiURL = cfg[common.UIURL].(string)
}
return strings.TrimSuffix(uiURL, "/") + "/service/token"
}
// InternalNotaryEndpoint returns notary server endpoint for internal communication between Harbor containers

View File

@ -17,6 +17,7 @@ import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/vmware/harbor/src/common/utils/test"
)
@ -39,6 +40,7 @@ func TestConfig(t *testing.T) {
return
}
defer os.Remove(secretKeyPath)
assert := assert.New(t)
if err := os.Setenv("KEY_PATH", secretKeyPath); err != nil {
t.Fatalf("failed to set env %s: %v", "KEY_PATH", err)
@ -164,5 +166,7 @@ func TestConfig(t *testing.T) {
if us.ClientID != "testid" || us.ClientSecret != "testsecret" || us.Endpoint != "10.192.168.5" {
t.Errorf("Unexpected UAA setting: %+v", *us)
}
assert.Equal("http://myjob:8888", InternalJobServiceURL())
assert.Equal("http://myui:8888/service/token", InternalTokenServiceEndpoint())
}