Skip to content

Commit

Permalink
Adapt Che routing solver to DevWorkspace Operator changes
Browse files Browse the repository at this point in the history
Adapt code in Che RoutingSolver to accomodate changes in DWO that
disconnect DevWorkspaceRouting resources from the upstream Devfile API

Signed-off-by: Angel Misevski <[email protected]>
  • Loading branch information
amisevsk committed Jan 27, 2022
1 parent 350a942 commit a9f2ff1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
20 changes: 9 additions & 11 deletions controllers/devworkspace/solver/che_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"strconv"
"strings"

"k8s.io/utils/pointer"

"github.com/eclipse-che/che-operator/pkg/util"

"github.com/eclipse-che/che-operator/pkg/deploy/gateway"
Expand Down Expand Up @@ -216,7 +214,7 @@ func (c *CheRoutingSolver) cheExposedEndpoints(cheCluster *v2alpha1.CheCluster,

for component, endpoints := range componentEndpoints {
for _, endpoint := range endpoints {
if endpoint.Exposure != dw.PublicEndpointExposure {
if dw.EndpointExposure(endpoint.Exposure) != dw.PublicEndpointExposure {
continue
}

Expand Down Expand Up @@ -361,7 +359,7 @@ func exposeAllEndpoints(cheCluster *v2alpha1.CheCluster, routing *dwo.DevWorkspa
order := 1
for componentName, endpoints := range routing.Spec.Endpoints {
for _, e := range endpoints {
if e.Exposure != dw.PublicEndpointExposure {
if dw.EndpointExposure(e.Exposure) != dw.PublicEndpointExposure {
continue
}

Expand Down Expand Up @@ -498,7 +496,7 @@ func routeForHealthzEndpoint(cfg *gateway.TraefikConfig, dwId string, endpoints
}
}

func addEndpointToTraefikConfig(componentName string, e dw.Endpoint, cfg *gateway.TraefikConfig, cheCluster *v2alpha1.CheCluster, routing *dwo.DevWorkspaceRouting) {
func addEndpointToTraefikConfig(componentName string, e dwo.Endpoint, cfg *gateway.TraefikConfig, cheCluster *v2alpha1.CheCluster, routing *dwo.DevWorkspaceRouting) {
routeName, prefix := createEndpointPath(&e, componentName)
rulePrefix := fmt.Sprintf("PathPrefix(`%s`)", prefix)

Expand Down Expand Up @@ -531,7 +529,7 @@ func addEndpointToTraefikConfig(componentName string, e dw.Endpoint, cfg *gatewa
}
}

func createEndpointPath(e *dw.Endpoint, componentName string) (routeName string, path string) {
func createEndpointPath(e *dwo.Endpoint, componentName string) (routeName string, path string) {
if e.Attributes.GetString(uniqueEndpointAttributeName, nil) == "true" {
// if endpoint is unique, we're exposing on /componentName/<endpoint-name>
routeName = e.Name
Expand All @@ -557,7 +555,7 @@ func findServiceForPort(port int32, objs *solvers.RoutingObjects) *corev1.Servic
return nil
}

func findIngressForEndpoint(componentName string, endpoint dw.Endpoint, objs *solvers.RoutingObjects) *networkingv1.Ingress {
func findIngressForEndpoint(componentName string, endpoint dwo.Endpoint, objs *solvers.RoutingObjects) *networkingv1.Ingress {
for i := range objs.Ingresses {
ingress := &objs.Ingresses[i]

Expand All @@ -580,7 +578,7 @@ func findIngressForEndpoint(componentName string, endpoint dw.Endpoint, objs *so
return nil
}

func findRouteForEndpoint(componentName string, endpoint dw.Endpoint, objs *solvers.RoutingObjects, dwId string) *routeV1.Route {
func findRouteForEndpoint(componentName string, endpoint dwo.Endpoint, objs *solvers.RoutingObjects, dwId string) *routeV1.Route {
service := findServiceForPort(int32(endpoint.TargetPort), objs)
if service == nil {
service = getCommonService(objs, dwId)
Expand Down Expand Up @@ -650,7 +648,7 @@ func getServiceURL(port int32, workspaceID string, workspaceNamespace string) st
return fmt.Sprintf("http://%s.%s.svc:%d", common.ServiceName(workspaceID), workspaceNamespace, port)
}

func getPublicURLPrefixForEndpoint(workspaceID string, machineName string, endpoint dw.Endpoint) string {
func getPublicURLPrefixForEndpoint(workspaceID string, machineName string, endpoint dwo.Endpoint) string {
endpointName := ""
if endpoint.Attributes.GetString(uniqueEndpointAttributeName, nil) == "true" {
endpointName = endpoint.Name
Expand All @@ -666,15 +664,15 @@ func getPublicURLPrefix(workspaceID string, machineName string, port int32, uniq
return fmt.Sprintf(uniqueEndpointURLPrefixPattern, workspaceID, machineName, uniqueEndpointName)
}

func determineEndpointScheme(e dw.Endpoint) string {
func determineEndpointScheme(e dwo.Endpoint) string {
var scheme string
if e.Protocol == "" {
scheme = "http"
} else {
scheme = string(e.Protocol)
}

upgradeToSecure := pointer.BoolPtrDerefOr(e.Secure, false)
upgradeToSecure := e.Secure

// gateway is always on HTTPS, so if the endpoint is served through the gateway, we need to use the TLS'd variant.
if e.Attributes.GetString(urlRewriteSupportedEndpointAttributeName, nil) == "true" {
Expand Down
29 changes: 13 additions & 16 deletions controllers/devworkspace/solver/che_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ import (
"strings"
"testing"

"k8s.io/utils/pointer"

"github.com/eclipse-che/che-operator/pkg/util"

"github.com/stretchr/testify/assert"

"github.com/eclipse-che/che-operator/pkg/deploy/gateway"

dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/api/v2/pkg/attributes"
dwo "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/controllers/controller/devworkspacerouting/solvers"
"github.com/devfile/devworkspace-operator/pkg/constants"
Expand Down Expand Up @@ -137,22 +134,22 @@ func subdomainDevWorkspaceRouting() *dwo.DevWorkspaceRouting {
{
Name: "e1",
TargetPort: 9999,
Exposure: dw.PublicEndpointExposure,
Exposure: dwo.PublicEndpointExposure,
Protocol: "https",
Path: "/1/",
},
{
Name: "e2",
TargetPort: 9999,
Exposure: dw.PublicEndpointExposure,
Exposure: dwo.PublicEndpointExposure,
Protocol: "http",
Path: "/2.js",
Secure: pointer.BoolPtr(true),
Secure: true,
},
{
Name: "e3",
TargetPort: 9999,
Exposure: dw.PublicEndpointExposure,
Exposure: dwo.PublicEndpointExposure,
},
},
},
Expand All @@ -174,30 +171,30 @@ func relocatableDevWorkspaceRouting() *dwo.DevWorkspaceRouting {
{
Name: "e1",
TargetPort: 9999,
Exposure: dw.PublicEndpointExposure,
Exposure: dwo.PublicEndpointExposure,
Protocol: "https",
Path: "/1/",
Attributes: attributes.Attributes{
Attributes: dwo.Attributes{
urlRewriteSupportedEndpointAttributeName: apiext.JSON{Raw: []byte("\"true\"")},
string(dwo.TypeEndpointAttribute): apiext.JSON{Raw: []byte("\"main\"")},
},
},
{
Name: "e2",
TargetPort: 9999,
Exposure: dw.PublicEndpointExposure,
Exposure: dwo.PublicEndpointExposure,
Protocol: "http",
Path: "/2.js",
Secure: pointer.BoolPtr(true),
Attributes: attributes.Attributes{
Secure: true,
Attributes: dwo.Attributes{
urlRewriteSupportedEndpointAttributeName: apiext.JSON{Raw: []byte("\"true\"")},
},
},
{
Name: "e3",
TargetPort: 9999,
Exposure: dw.PublicEndpointExposure,
Attributes: attributes.Attributes{
Exposure: dwo.PublicEndpointExposure,
Attributes: dwo.Attributes{
urlRewriteSupportedEndpointAttributeName: apiext.JSON{Raw: []byte("\"true\"")},
},
},
Expand Down Expand Up @@ -461,10 +458,10 @@ func TestUniqueMainEndpoint(t *testing.T) {
{
Name: "e1",
TargetPort: 9999,
Exposure: dw.PublicEndpointExposure,
Exposure: dwo.PublicEndpointExposure,
Protocol: "https",
Path: "/1/",
Attributes: attributes.Attributes{
Attributes: dwo.Attributes{
urlRewriteSupportedEndpointAttributeName: apiext.JSON{Raw: []byte("\"true\"")},
string(dwo.TypeEndpointAttribute): apiext.JSON{Raw: []byte("\"main\"")},
uniqueEndpointAttributeName: apiext.JSON{Raw: []byte("\"true\"")},
Expand Down

0 comments on commit a9f2ff1

Please sign in to comment.