Skip to content

Commit 25b9ce1

Browse files
Merge pull request #1 from raniellyferreira/fix-fffe71de-0e9c-46ee-972c-1db52558ba69
Add support for separate HTTP/2 listener protocol in OCI Load Balancer
2 parents 1a1cd15 + d73893b commit 25b9ce1

File tree

2 files changed

+86
-10
lines changed

2 files changed

+86
-10
lines changed

pkg/cloudprovider/providers/oci/load_balancer_spec.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ const (
146146
// loadbalancer traffic policy("ROUND_ROBIN", "LEAST_CONNECTION", "IP_HASH")
147147
ServiceAnnotationLoadBalancerPolicy = "oci.oraclecloud.com/loadbalancer-policy"
148148

149+
// ServiceAnnotationLoadBalancerProtocol is a service annotation for specifying
150+
// the load balancer listener protocol ("HTTP", "HTTP2", "TCP").
151+
ServiceAnnotationLoadBalancerProtocol = "oci.oraclecloud.com/oci-load-balancer-protocol"
152+
149153
// ServiceAnnotationLoadBalancerInitialDefinedTagsOverride is a service annotation for specifying
150154
// defined tags on the LB
151155
ServiceAnnotationLoadBalancerInitialDefinedTagsOverride = "oci.oraclecloud.com/initial-defined-tags-override"
@@ -1092,19 +1096,32 @@ func getListenersOciLoadBalancer(svc *v1.Service, sslCfg *SSLConfig) (map[string
10921096

10931097
listeners := make(map[string]client.GenericListener)
10941098
for _, servicePort := range svc.Spec.Ports {
1095-
protocol := string(servicePort.Protocol)
1096-
// Annotation overrides the protocol.
1099+
backendProtocol := string(servicePort.Protocol)
1100+
// Backend protocol annotation overrides the protocol.
10971101
if p, ok := svc.Annotations[ServiceAnnotationLoadBalancerBEProtocol]; ok {
10981102
// Default
10991103
if p == "" {
11001104
p = DefaultLoadBalancerBEProtocol
11011105
}
11021106
if strings.EqualFold(p, "HTTP") || strings.EqualFold(p, "TCP") || strings.EqualFold(p, "GRPC") {
1103-
protocol = p
1107+
backendProtocol = p
11041108
} else {
11051109
return nil, fmt.Errorf("invalid backend protocol %q requested for load balancer listener. Only 'HTTP', 'TCP' and 'GRPC' protocols supported", p)
11061110
}
11071111
}
1112+
1113+
// Listener protocol - starts with backend protocol but can be overridden
1114+
listenerProtocol := backendProtocol
1115+
if p, ok := svc.Annotations[ServiceAnnotationLoadBalancerProtocol]; ok {
1116+
if p != "" {
1117+
if strings.EqualFold(p, "HTTP") || strings.EqualFold(p, "HTTP2") || strings.EqualFold(p, "TCP") || strings.EqualFold(p, "GRPC") {
1118+
listenerProtocol = p
1119+
} else {
1120+
return nil, fmt.Errorf("invalid listener protocol %q requested for load balancer listener. Only 'HTTP', 'HTTP2', 'TCP' and 'GRPC' protocols supported", p)
1121+
}
1122+
}
1123+
}
1124+
11081125
port := int(servicePort.Port)
11091126

11101127
var secretName string
@@ -1118,21 +1135,21 @@ func getListenersOciLoadBalancer(svc *v1.Service, sslCfg *SSLConfig) (map[string
11181135
return nil, err
11191136
}
11201137
}
1121-
if strings.EqualFold(protocol, "GRPC") {
1122-
protocol = ProtocolGrpc
1138+
if strings.EqualFold(listenerProtocol, "GRPC") {
1139+
listenerProtocol = ProtocolGrpc
11231140
if sslConfiguration == nil {
11241141
return nil, fmt.Errorf("SSL configuration cannot be empty for GRPC protocol")
11251142
}
11261143
if sslConfiguration.CipherSuiteName == nil {
11271144
sslConfiguration.CipherSuiteName = common.String(DefaultCipherSuiteForGRPC)
11281145
}
11291146
}
1130-
name := getListenerName(protocol, port)
1147+
name := getListenerName(listenerProtocol, port)
11311148

11321149
listener := client.GenericListener{
11331150
Name: &name,
11341151
DefaultBackendSetName: common.String(getBackendSetName(string(servicePort.Protocol), int(servicePort.Port))),
1135-
Protocol: &protocol,
1152+
Protocol: &listenerProtocol,
11361153
Port: &port,
11371154
RuleSetNames: rs,
11381155
SslConfiguration: sslConfiguration,
@@ -1145,10 +1162,11 @@ func getListenersOciLoadBalancer(svc *v1.Service, sslCfg *SSLConfig) (map[string
11451162
if proxyProtocolVersion != nil && connectionIdleTimeout == nil {
11461163
// At that point LB only supports HTTP and TCP
11471164
defaultIdleTimeoutPerProtocol := map[string]int64{
1148-
"HTTP": lbConnectionIdleTimeoutHTTP,
1149-
"TCP": lbConnectionIdleTimeoutTCP,
1165+
"HTTP": lbConnectionIdleTimeoutHTTP,
1166+
"HTTP2": lbConnectionIdleTimeoutHTTP, // HTTP2 uses same timeout as HTTP
1167+
"TCP": lbConnectionIdleTimeoutTCP,
11501168
}
1151-
actualConnectionIdleTimeout = common.Int64(defaultIdleTimeoutPerProtocol[strings.ToUpper(protocol)])
1169+
actualConnectionIdleTimeout = common.Int64(defaultIdleTimeoutPerProtocol[strings.ToUpper(listenerProtocol)])
11521170
}
11531171

11541172
if actualConnectionIdleTimeout != nil {

pkg/cloudprovider/providers/oci/load_balancer_spec_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8943,6 +8943,64 @@ func Test_getListeners(t *testing.T) {
89438943
},
89448944
},
89458945
},
8946+
{
8947+
name: "HTTP2 listener protocol with HTTP backend protocol",
8948+
service: &v1.Service{
8949+
Spec: v1.ServiceSpec{
8950+
Ports: []v1.ServicePort{
8951+
{
8952+
Protocol: v1.ProtocolTCP,
8953+
Port: int32(443),
8954+
},
8955+
},
8956+
},
8957+
ObjectMeta: metav1.ObjectMeta{
8958+
Annotations: map[string]string{
8959+
ServiceAnnotationLoadBalancerBEProtocol: "HTTP",
8960+
ServiceAnnotationLoadBalancerProtocol: "HTTP2",
8961+
},
8962+
},
8963+
},
8964+
listenerBackendIpVersion: []string{IPv4},
8965+
sslConfig: nil,
8966+
want: map[string]client.GenericListener{
8967+
"HTTP2-443": {
8968+
Name: common.String("HTTP2-443"),
8969+
Port: common.Int(443),
8970+
Protocol: common.String("HTTP2"),
8971+
DefaultBackendSetName: common.String("TCP-443"),
8972+
},
8973+
},
8974+
},
8975+
{
8976+
name: "HTTP listener protocol with HTTP backend protocol",
8977+
service: &v1.Service{
8978+
Spec: v1.ServiceSpec{
8979+
Ports: []v1.ServicePort{
8980+
{
8981+
Protocol: v1.ProtocolTCP,
8982+
Port: int32(80),
8983+
},
8984+
},
8985+
},
8986+
ObjectMeta: metav1.ObjectMeta{
8987+
Annotations: map[string]string{
8988+
ServiceAnnotationLoadBalancerBEProtocol: "HTTP",
8989+
ServiceAnnotationLoadBalancerProtocol: "HTTP",
8990+
},
8991+
},
8992+
},
8993+
listenerBackendIpVersion: []string{IPv4},
8994+
sslConfig: nil,
8995+
want: map[string]client.GenericListener{
8996+
"HTTP-80": {
8997+
Name: common.String("HTTP-80"),
8998+
Port: common.Int(80),
8999+
Protocol: common.String("HTTP"),
9000+
DefaultBackendSetName: common.String("TCP-80"),
9001+
},
9002+
},
9003+
},
89469004
}
89479005
for _, tt := range tests {
89489006
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)