Update how too-long endpoint hostnames are handled
Update the hostname format used for endpoints whose hostnames are too long from <workspace-id>-<order>.<base-domain> to <workspace-id>-<endpoint-name>.<base-domain> This is necessary as the iteration order through endpoints is random (iterating through Go maps is random), resulting in inconsistent numbers used for <order>. Using a combination of workspace ID and endpoint name should always be valid: * Workspace IDs are 25 characters long * Endpoint names are restricted to max 15 characters by the Devfile API * Endpoint names and workspace IDs are required to be alphanumeric with dashes, starting and ending with an alphanumeric character * Endpoint names are unique across all endpoints in the workspace Signed-off-by: Angel Misevski <amisevsk@redhat.com>pull/1803/head
parent
4de7be5489
commit
d295ee1492
|
|
@ -1569,24 +1569,24 @@ func TestReportSubdomainExposedEndpointsLongUsername(t *testing.T) {
|
|||
if e1.Name != "e1" {
|
||||
t.Errorf("The first endpoint should have been e1 but is %s", e1.Name)
|
||||
}
|
||||
if e1.Url != "https://wsid-1.down.on.earth/1/" {
|
||||
t.Errorf("The e1 endpoint should have the following URL: '%s' but has '%s'.", "https://wsid-1.down.on.earth/1/", e1.Url)
|
||||
if e1.Url != "https://wsid-e1.down.on.earth/1/" {
|
||||
t.Errorf("The e1 endpoint should have the following URL: '%s' but has '%s'.", "https://wsid-e1.down.on.earth/1/", e1.Url)
|
||||
}
|
||||
|
||||
e2 := m1[1]
|
||||
if e2.Name != "e2" {
|
||||
t.Errorf("The second endpoint should have been e2 but is %s", e1.Name)
|
||||
}
|
||||
if e2.Url != "https://wsid-2.down.on.earth/2.js" {
|
||||
t.Errorf("The e2 endpoint should have the following URL: '%s' but has '%s'.", "https://wsid-2.down.on.earth/2.js", e2.Url)
|
||||
if e2.Url != "https://wsid-e2.down.on.earth/2.js" {
|
||||
t.Errorf("The e2 endpoint should have the following URL: '%s' but has '%s'.", "https://wsid-e2.down.on.earth/2.js", e2.Url)
|
||||
}
|
||||
|
||||
e3 := m1[2]
|
||||
if e3.Name != "e3" {
|
||||
t.Errorf("The third endpoint should have been e3 but is %s", e1.Name)
|
||||
}
|
||||
if e3.Url != "http://wsid-3.down.on.earth/" {
|
||||
t.Errorf("The e3 endpoint should have the following URL: '%s' but has '%s'.", "https://wsid-3.down.on.earth/", e3.Url)
|
||||
if e3.Url != "http://wsid-e3.down.on.earth/" {
|
||||
t.Errorf("The e3 endpoint should have the following URL: '%s' but has '%s'.", "https://wsid-e3.down.on.earth/", e3.Url)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,8 +72,10 @@ func (u UsernameWkspName) getEndpointPathPrefix(endpointPath string) string {
|
|||
func (u UsernameWkspName) getHostname(endpointInfo *EndpointInfo, baseDomain string) string {
|
||||
subDomain := fmt.Sprintf("%s-%s-%s", u.username, u.workspaceName, endpointInfo.endpointName)
|
||||
if errs := validation.IsValidLabelValue(subDomain); len(errs) > 0 {
|
||||
// if subdomain is not valid, use legacy paths
|
||||
return fmt.Sprintf("%s-%d.%s", u.workspaceID, endpointInfo.order, baseDomain)
|
||||
// If subdomain is not valid (e.g. too long), use alternate format
|
||||
// The below should always be under 63 characters, as endpoint names are limited to 15 characters and workspace IDs are
|
||||
// 25 characters.
|
||||
return fmt.Sprintf("%s-%s.%s", u.workspaceID, endpointInfo.endpointName, baseDomain)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s.%s", subDomain, baseDomain)
|
||||
|
|
|
|||
Loading…
Reference in New Issue