Skip to content

Commit

Permalink
Make OpenShift Route work with gRPC receivers (open-telemetry#2028)
Browse files Browse the repository at this point in the history
* Make OpenShift Route work with gRPC receivers

Signed-off-by: Pavol Loffay <[email protected]>

* Fix

Signed-off-by: Pavol Loffay <[email protected]>

* Fix

Signed-off-by: Pavol Loffay <[email protected]>

* Fix

Signed-off-by: Pavol Loffay <[email protected]>

---------

Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay authored Aug 22, 2023
1 parent d3c98ae commit 7865a02
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .chloggen/route-grpc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Make OpenShift Route work with gRPC receivers by using h2c appProtocol

# One or more tracking issues related to the change
issues: [1969]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
7 changes: 6 additions & 1 deletion internal/manifests/collector/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func Routes(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetr
routes := make([]*routev1.Route, len(ports))
for i, p := range ports {
portName := naming.PortName(p.Name, p.Port)
path := "/"
// passthrough termination does not support paths
if otelcol.Spec.Ingress.Route.Termination == v1alpha1.TLSRouteTerminationTypePassthrough {
path = ""
}
routes[i] = &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: naming.Route(otelcol.Name, p.Name),
Expand All @@ -79,7 +84,7 @@ func Routes(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetr
},
Spec: routev1.RouteSpec{
Host: fmt.Sprintf("%s.%s", portName, otelcol.Spec.Ingress.Hostname),
Path: "/",
Path: path,
To: routev1.RouteTargetReference{
Kind: "Service",
Name: naming.Service(otelcol.Name),
Expand Down
10 changes: 10 additions & 0 deletions internal/manifests/collector/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package collector

import (
"fmt"
"strings"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -102,6 +103,15 @@ func Service(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemet

ports := adapters.ConfigToPorts(logger, configFromString)

// set appProtocol to h2c for grpc ports on OpenShift.
// OpenShift uses HA proxy that uses appProtocol for its configuration.
for i := range ports {
h2c := "h2c"
if otelcol.Spec.Ingress.Type == v1alpha1.IngressTypeRoute && ports[i].AppProtocol != nil && strings.EqualFold(*ports[i].AppProtocol, "grpc") {
ports[i].AppProtocol = &h2c
}
}

if len(otelcol.Spec.Ports) > 0 {
// we should add all the ports from the CR
// there are two cases where problems might occur:
Expand Down
19 changes: 18 additions & 1 deletion internal/manifests/collector/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ func TestDesiredService(t *testing.T) {

})

t.Run("on OpenShift gRPC appProtocol should be h2c", func(t *testing.T) {
h2c := "h2c"
jaegerPort := v1.ServicePort{
Name: "jaeger-grpc",
Protocol: "TCP",
Port: 14250,
AppProtocol: &h2c,
}

params := deploymentParams()
params.Instance.Spec.Ingress.Type = v1alpha1.IngressTypeRoute
actual := Service(params.Config, params.Log, params.Instance)

ports := append(params.Instance.Spec.Ports, jaegerPort)
expected := service("test-collector", ports)
assert.Equal(t, expected, *actual)
})

t.Run("should return service with local internal traffic policy", func(t *testing.T) {

grpc := "grpc"
Expand All @@ -144,7 +162,6 @@ func TestDesiredService(t *testing.T) {

assert.Equal(t, expected, *actual)
})

}

func TestHeadlessService(t *testing.T) {
Expand Down

0 comments on commit 7865a02

Please sign in to comment.