@@ -146,6 +146,10 @@ const (
146
146
// loadbalancer traffic policy("ROUND_ROBIN", "LEAST_CONNECTION", "IP_HASH")
147
147
ServiceAnnotationLoadBalancerPolicy = "oci.oraclecloud.com/loadbalancer-policy"
148
148
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
+
149
153
// ServiceAnnotationLoadBalancerInitialDefinedTagsOverride is a service annotation for specifying
150
154
// defined tags on the LB
151
155
ServiceAnnotationLoadBalancerInitialDefinedTagsOverride = "oci.oraclecloud.com/initial-defined-tags-override"
@@ -1092,19 +1096,32 @@ func getListenersOciLoadBalancer(svc *v1.Service, sslCfg *SSLConfig) (map[string
1092
1096
1093
1097
listeners := make (map [string ]client.GenericListener )
1094
1098
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.
1097
1101
if p , ok := svc .Annotations [ServiceAnnotationLoadBalancerBEProtocol ]; ok {
1098
1102
// Default
1099
1103
if p == "" {
1100
1104
p = DefaultLoadBalancerBEProtocol
1101
1105
}
1102
1106
if strings .EqualFold (p , "HTTP" ) || strings .EqualFold (p , "TCP" ) || strings .EqualFold (p , "GRPC" ) {
1103
- protocol = p
1107
+ backendProtocol = p
1104
1108
} else {
1105
1109
return nil , fmt .Errorf ("invalid backend protocol %q requested for load balancer listener. Only 'HTTP', 'TCP' and 'GRPC' protocols supported" , p )
1106
1110
}
1107
1111
}
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
+
1108
1125
port := int (servicePort .Port )
1109
1126
1110
1127
var secretName string
@@ -1118,21 +1135,21 @@ func getListenersOciLoadBalancer(svc *v1.Service, sslCfg *SSLConfig) (map[string
1118
1135
return nil , err
1119
1136
}
1120
1137
}
1121
- if strings .EqualFold (protocol , "GRPC" ) {
1122
- protocol = ProtocolGrpc
1138
+ if strings .EqualFold (listenerProtocol , "GRPC" ) {
1139
+ listenerProtocol = ProtocolGrpc
1123
1140
if sslConfiguration == nil {
1124
1141
return nil , fmt .Errorf ("SSL configuration cannot be empty for GRPC protocol" )
1125
1142
}
1126
1143
if sslConfiguration .CipherSuiteName == nil {
1127
1144
sslConfiguration .CipherSuiteName = common .String (DefaultCipherSuiteForGRPC )
1128
1145
}
1129
1146
}
1130
- name := getListenerName (protocol , port )
1147
+ name := getListenerName (listenerProtocol , port )
1131
1148
1132
1149
listener := client.GenericListener {
1133
1150
Name : & name ,
1134
1151
DefaultBackendSetName : common .String (getBackendSetName (string (servicePort .Protocol ), int (servicePort .Port ))),
1135
- Protocol : & protocol ,
1152
+ Protocol : & listenerProtocol ,
1136
1153
Port : & port ,
1137
1154
RuleSetNames : rs ,
1138
1155
SslConfiguration : sslConfiguration ,
@@ -1145,10 +1162,11 @@ func getListenersOciLoadBalancer(svc *v1.Service, sslCfg *SSLConfig) (map[string
1145
1162
if proxyProtocolVersion != nil && connectionIdleTimeout == nil {
1146
1163
// At that point LB only supports HTTP and TCP
1147
1164
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 ,
1150
1168
}
1151
- actualConnectionIdleTimeout = common .Int64 (defaultIdleTimeoutPerProtocol [strings .ToUpper (protocol )])
1169
+ actualConnectionIdleTimeout = common .Int64 (defaultIdleTimeoutPerProtocol [strings .ToUpper (listenerProtocol )])
1152
1170
}
1153
1171
1154
1172
if actualConnectionIdleTimeout != nil {
0 commit comments