Fix subdomain for public endpoint urls

Signed-off-by: David Kwon <dakwon@redhat.com>
pull/1702/head
David Kwon 2023-06-06 10:16:16 -04:00
parent f0c01676bd
commit cd72623e54
2 changed files with 19 additions and 19 deletions

View File

@ -995,14 +995,14 @@ func TestCreateSubDomainObjects(t *testing.T) {
if len(objs.Ingresses) != 3 {
t.Error("Expected 3 ingress, found ", len(objs.Ingresses))
}
if objs.Ingresses[0].Spec.Rules[0].Host != "username.my-workspace.e1.down.on.earth" {
t.Error("Expected Ingress host 'username.my-workspace.e1.down.on.earth', but got ", objs.Ingresses[0].Spec.Rules[0].Host)
if objs.Ingresses[0].Spec.Rules[0].Host != "username-my-workspace-e1.down.on.earth" {
t.Error("Expected Ingress host 'username-my-workspace-e1.down.on.earth', but got ", objs.Ingresses[0].Spec.Rules[0].Host)
}
if objs.Ingresses[1].Spec.Rules[0].Host != "username.my-workspace.e2.down.on.earth" {
t.Error("Expected Ingress host 'username.my-workspace.e2.down.on.earth', but got ", objs.Ingresses[1].Spec.Rules[0].Host)
if objs.Ingresses[1].Spec.Rules[0].Host != "username-my-workspace-e2.down.on.earth" {
t.Error("Expected Ingress host 'username-my-workspace-e2.down.on.earth', but got ", objs.Ingresses[1].Spec.Rules[0].Host)
}
if objs.Ingresses[2].Spec.Rules[0].Host != "username.my-workspace.e3.down.on.earth" {
t.Error("Expected Ingress host 'username.my-workspace.e3.down.on.earth', but got ", objs.Ingresses[2].Spec.Rules[0].Host)
if objs.Ingresses[2].Spec.Rules[0].Host != "username-my-workspace-e3.down.on.earth" {
t.Error("Expected Ingress host 'username-my-workspace-e3.down.on.earth', but got ", objs.Ingresses[2].Spec.Rules[0].Host)
}
})
@ -1011,8 +1011,8 @@ func TestCreateSubDomainObjects(t *testing.T) {
if len(objs.Routes) != 3 {
t.Error("Expected 3 Routes, found ", len(objs.Routes))
}
if objs.Routes[0].Spec.Host != "username.my-workspace.e1.down.on.earth" {
t.Error("Expected Route host 'username.my-workspace.e1.down.on.earth', but got ", objs.Routes[0].Spec.Host)
if objs.Routes[0].Spec.Host != "username-my-workspace-e1.down.on.earth" {
t.Error("Expected Route host 'username-my-workspace-e1.down.on.earth', but got ", objs.Routes[0].Spec.Host)
}
})
}
@ -1335,7 +1335,7 @@ func TestExposeEndpoints(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, 1, len(spnr))
assert.Equal(t, "server-pub-nr", spnr[0].Name)
assert.Equal(t, "http://username.my-workspace.server-pub-nr.down.on.earth/", spnr[0].Url)
assert.Equal(t, "http://username-my-workspace-server-pub-nr.down.on.earth/", spnr[0].Url)
}
func TestExposeEndpointsLegacy(t *testing.T) {
@ -1499,24 +1499,24 @@ func TestReportSubdomainExposedEndpoints(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://username.my-workspace.e1.down.on.earth/1/" {
t.Errorf("The e1 endpoint should have the following URL: '%s' but has '%s'.", "https://username.my-workspace.e1.down.on.earth/1/", e1.Url)
if e1.Url != "https://username-my-workspace-e1.down.on.earth/1/" {
t.Errorf("The e1 endpoint should have the following URL: '%s' but has '%s'.", "https://username-my-workspace-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://username.my-workspace.e2.down.on.earth/2.js" {
t.Errorf("The e2 endpoint should have the following URL: '%s' but has '%s'.", "https://username.my-workspace.e2.down.on.earth/2.js", e2.Url)
if e2.Url != "https://username-my-workspace-e2.down.on.earth/2.js" {
t.Errorf("The e2 endpoint should have the following URL: '%s' but has '%s'.", "https://username-my-workspace-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://username.my-workspace.e3.down.on.earth/" {
t.Errorf("The e3 endpoint should have the following URL: '%s' but has '%s'.", "http://username.my-workspace.e3.down.on.earth/", e3.Url)
if e3.Url != "http://username-my-workspace-e3.down.on.earth/" {
t.Errorf("The e3 endpoint should have the following URL: '%s' but has '%s'.", "http://username-my-workspace-e3.down.on.earth/", e3.Url)
}
}
@ -1712,7 +1712,7 @@ func TestUsesCustomCertificateForWorkspaceEndpointIngresses(t *testing.T) {
t.Fatalf("Unexpected number of host records on the TLS spec: %d", len(ingress.Spec.TLS[0].Hosts))
}
if ingress.Spec.TLS[0].Hosts[0] != "username.my-workspace.e1.almost.trivial" {
if ingress.Spec.TLS[0].Hosts[0] != "username-my-workspace-e1.almost.trivial" {
t.Errorf("Unexpected host name of the TLS spec: %s", ingress.Spec.TLS[0].Hosts[0])
}
@ -1730,7 +1730,7 @@ func TestUsesCustomCertificateForWorkspaceEndpointIngresses(t *testing.T) {
t.Fatalf("Unexpected number of host records on the TLS spec: %d", len(ingress.Spec.TLS[0].Hosts))
}
if ingress.Spec.TLS[0].Hosts[0] != "username.my-workspace.e2.almost.trivial" {
if ingress.Spec.TLS[0].Hosts[0] != "username-my-workspace-e2.almost.trivial" {
t.Errorf("Unexpected host name of the TLS spec: %s", ingress.Spec.TLS[0].Hosts[0])
}

View File

@ -35,7 +35,7 @@ type EndpointStrategy interface {
// <CHE_DOMAIN>/<USERNAME>/<WORKSPACE_NAME>/<PORT>/
// Public endpoints defined in the devfile are exposed on the following path via route or ingress:
// <USERNAME>.<WORKSPACE_NAME>.<ENDPOINT_NAME>.<CLUSTER_INGRESS_DOMAIN>/<ENDPOINT_PATH>
// <USERNAME>-<WORKSPACE_NAME>-<ENDPOINT_NAME>.<CLUSTER_INGRESS_DOMAIN>/<ENDPOINT_PATH>
type UsernameWkspName struct {
username string
workspaceName string
@ -68,7 +68,7 @@ func (u UsernameWkspName) getEndpointPathPrefix(endpointPath string) string {
}
func (u UsernameWkspName) getHostname(endpointInfo *EndpointInfo, baseDomain string) string {
return fmt.Sprintf("%s.%s.%s.%s", u.username, u.workspaceName, endpointInfo.endpointName, baseDomain)
return fmt.Sprintf("%s-%s-%s.%s", u.username, u.workspaceName, endpointInfo.endpointName, baseDomain)
}
// Main workspace URL is exposed on the following path: