From 55ae6c54b76c7cb44ec55f3859051b27da1c97e7 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Fri, 2 Aug 2024 15:24:42 -0400 Subject: [PATCH] feat: Add DWR endpoint annotations to che router created routes & ingresses Fix eclipse-che/che#23064 Signed-off-by: Andrew Obuchowicz --- .../devworkspace/solver/che_routing.go | 1 + .../devworkspace/solver/endpoint_exposer.go | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/controllers/devworkspace/solver/che_routing.go b/controllers/devworkspace/solver/che_routing.go index cdc697eaa..3226bbbe2 100644 --- a/controllers/devworkspace/solver/che_routing.go +++ b/controllers/devworkspace/solver/che_routing.go @@ -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 } diff --git a/controllers/devworkspace/solver/endpoint_exposer.go b/controllers/devworkspace/solver/endpoint_exposer.go index 138431493..de1bb3bef 100644 --- a/controllers/devworkspace/solver/endpoint_exposer.go +++ b/controllers/devworkspace/solver/endpoint_exposer.go @@ -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) @@ -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{ @@ -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(endpoint.annotations, e.ingressAnnotations, endpoint.componentName, endpoint.endpointName), OwnerReferences: endpoint.service.OwnerReferences, }, Spec: networkingv1.IngressSpec{ @@ -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