Skip to content

Commit

Permalink
Determine path strategy in different function
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 4213983 commit cf3e310
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions controllers/devworkspace/solver/che_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ func (c *CheRoutingSolver) cheExposedEndpoints(cheCluster *chev2.CheCluster, wor

gatewayHost := cheCluster.GetCheHost()

endpointStrategy := getEndpointPathStrategy(c.client, workspaceID, routingObj.Services[0].Namespace, routingObj.Services[0].ObjectMeta.OwnerReferences[0].Name)

for component, endpoints := range componentEndpoints {
for _, endpoint := range endpoints {
if dw.EndpointExposure(endpoint.Exposure) == dw.NoneEndpointExposure {
Expand Down Expand Up @@ -279,24 +281,6 @@ func (c *CheRoutingSolver) cheExposedEndpoints(cheCluster *chev2.CheCluster, wor
return map[string]dwo.ExposedEndpointList{}, false, nil
}

useLegacyRouting := false
username, err := getNormalizedUsername(c.client, routingObj.Services[0].Namespace)
if err != nil {
useLegacyRouting = true
}

dwName, err := getNormalizedWkspName(c.client, routingObj.Services[0].Namespace, routingObj.Services[0].ObjectMeta.OwnerReferences[0].Name)
if err != nil {
useLegacyRouting = true
}

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

publicURLPrefix := getPublicURLPrefixForEndpoint(component, endpoint, endpointStrategy)
endpointURL = path.Join(gatewayHost, publicURLPrefix, endpoint.Path)
}
Expand Down Expand Up @@ -347,24 +331,7 @@ func (c *CheRoutingSolver) getGatewayConfigsAndFillRoutingObjects(cheCluster *ch
}

configs := make([]corev1.ConfigMap, 0)

useLegacyRouting := false
username, err := getNormalizedUsername(c.client, routing.Namespace)
if err != nil {
useLegacyRouting = true
}

dwName, err := getNormalizedWkspName(c.client, routing.Namespace, routing.Name)
if err != nil {
useLegacyRouting = true
}

var endpointStrategy EndpointStrategy
if useLegacyRouting {
endpointStrategy = Legacy{workspaceID: workspaceID}
} else {
endpointStrategy = UsernameWkspName{username: username, workspaceName: dwName}
}
endpointStrategy := getEndpointPathStrategy(c.client, workspaceID, routing.Namespace, routing.Name)

// first do routing from main che-gateway into workspace service
if mainWsRouteConfig, err := provisionMainWorkspaceRoute(cheCluster, routing, cmLabels, endpointStrategy); err != nil {
Expand All @@ -385,6 +352,30 @@ func (c *CheRoutingSolver) getGatewayConfigsAndFillRoutingObjects(cheCluster *ch
return configs, nil
}

func getEndpointPathStrategy(c client.Client, workspaceId string, namespace string, dwRoutingName string) EndpointStrategy {
useLegacyPaths := false
username, err := getNormalizedUsername(c, namespace)
if err != nil {
useLegacyPaths = true
}

dwName, err := getNormalizedWkspName(c, namespace, dwRoutingName)
if err != nil {
useLegacyPaths = true
}

if useLegacyPaths {
strategy := new(Legacy)
strategy.workspaceID = workspaceId
return strategy
} else {
strategy := new(UsernameWkspName)
strategy.username = username
strategy.workspaceName = dwName
return strategy
}
}

func getNormalizedUsername(c client.Client, namespace string) (string, error) {
username, err := getUsernameFromNamespace(c, namespace)

Expand Down

0 comments on commit cf3e310

Please sign in to comment.