Skip to content

Commit

Permalink
feat: Add DWR endpoint annotations to che router created routes & ing…
Browse files Browse the repository at this point in the history
…resses

Fix eclipse-che/che#23064

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
  • Loading branch information
AObuchow committed Sep 23, 2024
1 parent d5243b7 commit d9aaac4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions controllers/devworkspace/solver/che_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ func exposeAllEndpoints(cheCluster *chev2.CheCluster, routing *dwo.DevWorkspaceR
port: int32(e.TargetPort),
scheme: determineEndpointScheme(e),
service: commonService,
annotations: e.Annotations,
})
order = order + 1
}
Expand Down
21 changes: 14 additions & 7 deletions controllers/devworkspace/solver/endpoint_exposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type EndpointInfo struct {
port int32
scheme string
service *corev1.Service
annotations map[string]string
}

// This method is used compose the object names (both Kubernetes objects and "objects" within Traefik configuration)
Expand Down Expand Up @@ -155,7 +156,7 @@ func (e *RouteExposer) getRouteForService(endpoint *EndpointInfo, endpointStrate
Name: getEndpointExposingObjectName(endpoint.componentName, e.devWorkspaceID, endpoint.port, endpoint.endpointName),
Namespace: endpoint.service.Namespace,
Labels: labels,
Annotations: routeAnnotations(endpoint.componentName, endpoint.endpointName),
Annotations: routeAnnotations(endpoint.annotations, endpoint.componentName, endpoint.endpointName),
OwnerReferences: endpoint.service.OwnerReferences,
},
Spec: routev1.RouteSpec{
Expand Down Expand Up @@ -197,7 +198,7 @@ func (e *IngressExposer) getIngressForService(endpoint *EndpointInfo, endpointSt
dwconstants.DevWorkspaceIDLabel: e.devWorkspaceID,
constants.KubernetesPartOfLabelKey: constants.CheEclipseOrg,
},
Annotations: finalizeIngressAnnotations(e.ingressAnnotations, endpoint.componentName, endpoint.endpointName),
Annotations: finalizeIngressAnnotations(e.ingressAnnotations, endpoint.annotations, endpoint.componentName, endpoint.endpointName),
OwnerReferences: endpoint.service.OwnerReferences,
},
Spec: networkingv1.IngressSpec{
Expand Down Expand Up @@ -239,18 +240,24 @@ func (e *IngressExposer) getIngressForService(endpoint *EndpointInfo, endpointSt
return ingress
}

func routeAnnotations(machineName string, endpointName string) map[string]string {
return map[string]string{
defaults.ConfigAnnotationEndpointName: endpointName,
defaults.ConfigAnnotationComponentName: machineName,
func routeAnnotations(endpointAnnotations map[string]string, machineName string, endpointName string) map[string]string {
annos := map[string]string{}
for k, v := range endpointAnnotations {
annos[k] = v
}
annos[defaults.ConfigAnnotationEndpointName] = endpointName
annos[defaults.ConfigAnnotationComponentName] = machineName
return annos
}

func finalizeIngressAnnotations(ingressAnnotations map[string]string, machineName string, endpointName string) map[string]string {
func finalizeIngressAnnotations(ingressAnnotations, endpointAnnotations map[string]string, machineName string, endpointName string) map[string]string {
annos := map[string]string{}
for k, v := range ingressAnnotations {
annos[k] = v
}
for k, v := range endpointAnnotations {
annos[k] = v
}
annos[defaults.ConfigAnnotationEndpointName] = endpointName
annos[defaults.ConfigAnnotationComponentName] = machineName

Expand Down

0 comments on commit d9aaac4

Please sign in to comment.