Skip to content

Commit

Permalink
Remove componentName field from from legacy strategy
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <dakwon@redhat.com>
  • Loading branch information
dkwon17 authored and tolusha committed May 31, 2023
1 parent 4074828 commit 4213983
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions controllers/devworkspace/solver/che_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ func (c *CheRoutingSolver) cheExposedEndpoints(cheCluster *chev2.CheCluster, wor

var endpointStrategy EndpointStrategy
if useLegacyRouting {
endpointStrategy = Legacy{workspaceID: workspaceID, componentName: component}
endpointStrategy = Legacy{workspaceID: workspaceID}
} else {
endpointStrategy = UsernameWkspName{username: username, workspaceName: dwName}
}

publicURLPrefix := getPublicURLPrefixForEndpoint(endpoint, endpointStrategy)
publicURLPrefix := getPublicURLPrefixForEndpoint(component, endpoint, endpointStrategy)
endpointURL = path.Join(gatewayHost, publicURLPrefix, endpoint.Path)
}

Expand Down Expand Up @@ -800,12 +800,12 @@ func getServiceURL(port int32, workspaceID string, workspaceNamespace string) st
return fmt.Sprintf("http://%s.%s.svc:%d", common.ServiceName(workspaceID), workspaceNamespace, port)
}

func getPublicURLPrefixForEndpoint(endpoint dwo.Endpoint, endpointStrategy EndpointStrategy) string {
func getPublicURLPrefixForEndpoint(componentName string, endpoint dwo.Endpoint, endpointStrategy EndpointStrategy) string {
endpointName := ""
if endpoint.Attributes.GetString(uniqueEndpointAttributeName, nil) == "true" {
endpointName = endpoint.Name
}
return endpointStrategy.getPublicURLPrefix(int32(endpoint.TargetPort), endpointName)
return endpointStrategy.getPublicURLPrefix(int32(endpoint.TargetPort), endpointName, componentName)
}

func determineEndpointScheme(e dwo.Endpoint) string {
Expand Down
13 changes: 6 additions & 7 deletions controllers/devworkspace/solver/endpoint_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// Interface for different workspace and endpoint url path strategies
type EndpointStrategy interface {
// get url paths for traefik config
getPublicURLPrefix(port int32, uniqueEndpointName string) string
getPublicURLPrefix(port int32, uniqueEndpointName string, componentName string) string
getMainWorkspacePathPrefix() string
getEndpointPath(e *dwo.Endpoint, componentName string) (routeName string, path string)
getEndpointPathPrefix(endpointPath string) string
Expand All @@ -41,7 +41,7 @@ type UsernameWkspName struct {
workspaceName string
}

func (u UsernameWkspName) getPublicURLPrefix(port int32, uniqueEndpointName string) string {
func (u UsernameWkspName) getPublicURLPrefix(port int32, uniqueEndpointName string, componentName string) string {
if uniqueEndpointName == "" {
return fmt.Sprintf(endpointURLPrefixPattern, u.username, u.workspaceName, port)
}
Expand Down Expand Up @@ -77,15 +77,14 @@ func (u UsernameWkspName) getHostname(endpointInfo *EndpointInfo, baseDomain str
// Public endpoints defined in the devfile are exposed on the following path via route or ingress:
// <WORKSPACE_ID>-<ENDPOINT_ORDER_NUMBER>.<CLUSTER_INGRESS_DOMAIN>/<ENDPOINT_PATH>
type Legacy struct {
workspaceID string
componentName string
workspaceID string
}

func (l Legacy) getPublicURLPrefix(port int32, uniqueEndpointName string) string {
func (l Legacy) getPublicURLPrefix(port int32, uniqueEndpointName string, componentName string) string {
if uniqueEndpointName == "" {
return fmt.Sprintf(endpointURLPrefixPattern, l.workspaceID, l.componentName, port)
return fmt.Sprintf(endpointURLPrefixPattern, l.workspaceID, componentName, port)
}
return fmt.Sprintf(uniqueEndpointURLPrefixPattern, l.workspaceID, l.componentName, uniqueEndpointName)
return fmt.Sprintf(uniqueEndpointURLPrefixPattern, l.workspaceID, componentName, uniqueEndpointName)
}

func (l Legacy) getMainWorkspacePathPrefix() string {
Expand Down

0 comments on commit 4213983

Please sign in to comment.