Skip to content

Commit

Permalink
Adapt code to use new format for Attributes
Browse files Browse the repository at this point in the history
Reflecting devfile/api PR devfile/api#214

Cherry-picked from commit cdef6dc and
adapted slightly

Signed-off-by: David Festal <dfestal@redhat.com>
  • Loading branch information
davidfestal authored and amisevsk committed Nov 27, 2020
1 parent b7c5b0e commit 1ac4a9b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func (s *ClusterSolver) GetExposedEndpoints(

for machineName, machineEndpoints := range endpoints {
for _, endpoint := range machineEndpoints {
if endpoint.Attributes[string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)] != "true" {
endpointAttributes := map[string]string{}
endpoint.Attributes.DecodeInto(&endpointAttributes)
if endpointAttributes[string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)] != "true" {
continue
}
url, err := resolveServiceHostnameForEndpoint(endpoint, routingObj.Services)
Expand All @@ -84,7 +86,7 @@ func (s *ClusterSolver) GetExposedEndpoints(
exposedEndpoints[machineName] = append(exposedEndpoints[machineName], controllerv1alpha1.ExposedEndpoint{
Name: endpoint.Name,
Url: url,
Attributes: endpoint.Attributes,
Attributes: endpointAttributes,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/controller/workspacerouting/solvers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func getDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1
var services []corev1.Service
for _, machineEndpoints := range endpoints {
for _, endpoint := range machineEndpoints {
if endpoint.Attributes[string(controllerv1alpha1.DISCOVERABLE_ATTRIBUTE)] == "true" {
if endpoint.Attributes.GetString(string(controllerv1alpha1.DISCOVERABLE_ATTRIBUTE)) == "true" {
// Create service with name matching endpoint
// TODO: This could cause a reconcile conflict if multiple workspaces define the same discoverable endpoint
// Also endpoint names may not be valid as service names
Expand Down Expand Up @@ -118,7 +118,7 @@ func getRoutingForSpec(endpoints map[string]controllerv1alpha1.EndpointList, met
var routes []routeV1.Route
for _, machineEndpoints := range endpoints {
for _, endpoint := range machineEndpoints {
if endpoint.Attributes[string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)] != "true" {
if endpoint.Attributes.GetString(string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)) != "true" {
continue
}
if config.ControllerCfg.IsOpenShift() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (s *OpenShiftOAuthSolver) getProxyRoutes(
proxyEndpoint := portMappings[upstreamEndpoint.Name]
endpoint := proxyEndpoint.publicEndpoint
var tls *routeV1.TLSConfig = nil
if endpoint.Attributes[string(controllerv1alpha1.SECURE_ENDPOINT_ATTRIBUTE)] == "true" {
if endpoint.Attributes[string(controllerv1alpha1.TYPE_ENDPOINT_ATTRIBUTE)] == "terminal" {
if endpoint.Attributes.Strings()[string(controllerv1alpha1.SECURE_ENDPOINT_ATTRIBUTE)] == "true" {
if endpoint.Attributes.Strings()[string(controllerv1alpha1.TYPE_ENDPOINT_ATTRIBUTE)] == "terminal" {
tls = &routeV1.TLSConfig{
Termination: routeV1.TLSTerminationEdge,
InsecureEdgeTerminationPolicy: routeV1.InsecureEdgeTerminationPolicyRedirect,
Expand Down Expand Up @@ -171,9 +171,10 @@ func getProxyEndpointMappings(
}

func endpointNeedsProxy(endpoint devworkspace.Endpoint) bool {
publicAttr, exists := endpoint.Attributes[string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)]
stringAttributes := endpoint.Attributes.Strings()
publicAttr, exists := stringAttributes[string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)]
endpointIsPublic := !exists || (publicAttr == "true")
return endpointIsPublic &&
endpoint.Attributes[string(controllerv1alpha1.SECURE_ENDPOINT_ATTRIBUTE)] == "true" &&
endpoint.Attributes[string(controllerv1alpha1.TYPE_ENDPOINT_ATTRIBUTE)] != "terminal"
stringAttributes[string(controllerv1alpha1.SECURE_ENDPOINT_ATTRIBUTE)] == "true" &&
stringAttributes[string(controllerv1alpha1.TYPE_ENDPOINT_ATTRIBUTE)] != "terminal"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func getExposedEndpoints(

for machineName, machineEndpoints := range endpoints {
for _, endpoint := range machineEndpoints {
if endpoint.Attributes[string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)] != "true" {
endpointAttributes := map[string]string{}
endpoint.Attributes.DecodeInto(&endpointAttributes)
if endpointAttributes[string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)] != "true" {
continue
}
endpointUrl, err := resolveURLForEndpoint(endpoint, routingObj)
Expand All @@ -43,7 +45,7 @@ func getExposedEndpoints(
exposedEndpoints[machineName] = append(exposedEndpoints[machineName], controllerv1alpha1.ExposedEndpoint{
Name: endpoint.Name,
Url: endpointUrl,
Attributes: endpoint.Attributes,
Attributes: endpointAttributes,
})
}
}
Expand Down Expand Up @@ -71,11 +73,11 @@ func resolveURLForEndpoint(
}

func getURLForEndpoint(endpoint devworkspace.Endpoint, host string, secure bool) string {
protocol := endpoint.Attributes[string(controllerv1alpha1.PROTOCOL_ENDPOINT_ATTRIBUTE)]
if secure && endpoint.Attributes[string(controllerv1alpha1.SECURE_ENDPOINT_ATTRIBUTE)] == "true" {
protocol := endpoint.Attributes.GetString(string(controllerv1alpha1.PROTOCOL_ENDPOINT_ATTRIBUTE))
if secure && endpoint.Attributes.GetString(string(controllerv1alpha1.SECURE_ENDPOINT_ATTRIBUTE)) == "true" {
protocol = getSecureProtocol(protocol)
}
path := endpoint.Attributes[string(controllerv1alpha1.PATH_ENDPOINT_ATTRIBUTE)]
path := endpoint.Attributes.GetString(string(controllerv1alpha1.PATH_ENDPOINT_ATTRIBUTE))
u := url.URL{
Scheme: protocol,
Host: host,
Expand Down
5 changes: 3 additions & 2 deletions controllers/workspace/restapis/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strings"

devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/api/pkg/attributes"
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/pkg/common"
"github.com/devfile/devworkspace-operator/pkg/config"
Expand Down Expand Up @@ -110,10 +111,10 @@ func GetCheRestApisComponent(workspaceName, workspaceId, namespace string) contr
},
Endpoints: []devworkspace.Endpoint{
{
Attributes: map[string]string{
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
string(controllerv1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE): "false",
string(controllerv1alpha1.PROTOCOL_ENDPOINT_ATTRIBUTE): "tcp",
},
}),
Name: cheRestAPIsName,
TargetPort: cheRestApisPort,
Exposure: devworkspace.PublicEndpointExposure,
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -567,22 +567,18 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
k8s.io/api v0.17.1/go.mod h1:zxiAc5y8Ngn4fmhWUtSxuUlkfz1ixT7j9wESokELzOg=
k8s.io/api v0.18.6 h1:osqrAXbOQjkKIWDTjrqxWQ3w0GkKb1KA1XkUGHHYpeE=
k8s.io/api v0.18.6/go.mod h1:eeyxr+cwCjMdLAmr2W3RyDI0VvTawSg/3RFFBEnmZGI=
k8s.io/api v0.18.8 h1:aIKUzJPb96f3fKec2lxtY7acZC9gQNDLVhfSGpxBAC4=
k8s.io/api v0.18.8/go.mod h1:d/CXqwWv+Z2XEG1LgceeDmHQwpUJhROPx16SlxJgERY=
k8s.io/apiextensions-apiserver v0.18.6 h1:vDlk7cyFsDyfwn2rNAO2DbmUbvXy5yT5GE3rrqOzaMo=
k8s.io/apiextensions-apiserver v0.18.6/go.mod h1:lv89S7fUysXjLZO7ke783xOwVTm6lKizADfvUM/SS/M=
k8s.io/apiextensions-apiserver v0.18.8 h1:pkqYPKTHa0/3lYwH7201RpF9eFm0lmZDFBNzhN+k/sA=
k8s.io/apiextensions-apiserver v0.18.8/go.mod h1:7f4ySEkkvifIr4+BRrRWriKKIJjPyg9mb/p63dJKnlM=
k8s.io/apimachinery v0.17.1/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
k8s.io/apimachinery v0.18.6 h1:RtFHnfGNfd1N0LeSrKCUznz5xtUP1elRGvHJbL3Ntag=
k8s.io/apimachinery v0.18.6/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
k8s.io/apimachinery v0.18.8 h1:jimPrycCqgx2QPearX3to1JePz7wSbVLq+7PdBTTwQ0=
k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig=
k8s.io/apiserver v0.18.6/go.mod h1:Zt2XvTHuaZjBz6EFYzpp+X4hTmgWGy8AthNVnTdm3Wg=
k8s.io/apiserver v0.18.8/go.mod h1:12u5FuGql8Cc497ORNj79rhPdiXQC4bf53X/skR/1YM=
k8s.io/client-go v0.18.6 h1:I+oWqJbibLSGsZj8Xs8F0aWVXJVIoUHWaaJV3kUN/Zw=
k8s.io/client-go v0.18.6/go.mod h1:/fwtGLjYMS1MaM5oi+eXhKwG+1UHidUEXRh6cNsdO0Q=
k8s.io/client-go v0.18.8 h1:SdbLpIxk5j5YbFr1b7fq8S7mDgDjYmUxSbszyoesoDM=
k8s.io/client-go v0.18.8/go.mod h1:HqFqMllQ5NnQJNwjro9k5zMyfhZlOwpuTLVrxjkYSxU=
Expand Down
11 changes: 7 additions & 4 deletions pkg/adaptor/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"strconv"
"strings"

"github.com/devfile/api/pkg/attributes"

"github.com/devfile/devworkspace-operator/pkg/adaptor/plugin_patch"

devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
Expand Down Expand Up @@ -125,12 +127,13 @@ func createEndpointsFromPlugin(plugin brokerModel.ChePlugin) []devworkspace.Endp
var endpoints []devworkspace.Endpoint

for _, pluginEndpoint := range plugin.Endpoints {
attributes := map[string]string{}
// Default value of http for protocol, may be overwritten by pluginEndpoint attributes
attributes[string(v1alpha1.PROTOCOL_ENDPOINT_ATTRIBUTE)] = "http"
attributes[string(v1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE)] = strconv.FormatBool(pluginEndpoint.Public)
attributes := attributes.Attributes{}.FromStringMap(map[string]string{
string(v1alpha1.PROTOCOL_ENDPOINT_ATTRIBUTE): "http",
string(v1alpha1.PUBLIC_ENDPOINT_ATTRIBUTE): strconv.FormatBool(pluginEndpoint.Public),
})
for key, val := range pluginEndpoint.Attributes {
attributes[key] = val
attributes.PutString(key, val)
}
endpoints = append(endpoints, devworkspace.Endpoint{
Name: common.EndpointName(pluginEndpoint.Name),
Expand Down

0 comments on commit 1ac4a9b

Please sign in to comment.