Make app protocol case insensitive

This commit is contained in:
shreealt 2025-08-20 19:30:08 +05:30 committed by GitHub
parent c60815ed08
commit 3b33ffa245
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 122 additions and 2 deletions

View File

@ -59,3 +59,13 @@ spec:
weight: 1 weight: 1
kind: Service kind: Service
group: "" group: ""
- name: whoami-HTTP
port: 80
weight: 1
kind: Service
group: ""
- name: whoami-HTTPS
port: 443
weight: 1
kind: Service
group: ""

View File

@ -430,6 +430,80 @@ spec:
name: wss name: wss
appProtocol: kubernetes.io/wss appProtocol: kubernetes.io/wss
---
kind: EndpointSlice
apiVersion: discovery.k8s.io/v1
metadata:
name: whoami-HTTPS-abc
namespace: default
labels:
kubernetes.io/service-name: whoami-HTTPS
addressType: IPv4
ports:
- name: websecure
port: 8443
endpoints:
- addresses:
- 10.10.0.16
conditions:
ready: true
---
apiVersion: v1
kind: Service
metadata:
name: whoami-HTTPS
namespace: default
spec:
ports:
- name: websecure
protocol: TCP
appProtocol: HTTPS
port: 443
targetPort: websecure
selector:
app: containous
task: whoami-HTTPS
---
kind: EndpointSlice
apiVersion: discovery.k8s.io/v1
metadata:
name: whoami-HTTP-abc
namespace: default
labels:
kubernetes.io/service-name: whoami-HTTP
addressType: IPv4
ports:
- name: web
port: 8080
endpoints:
- addresses:
- 10.10.0.17
conditions:
ready: true
---
apiVersion: v1
kind: Service
metadata:
name: whoami-HTTP
namespace: default
spec:
ports:
- name: web
protocol: TCP
port: 80
appProtocol: HTTP
targetPort: web
selector:
app: containous
task: whoami-HTTP
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service

View File

@ -430,7 +430,7 @@ func getGRPCServiceProtocol(portSpec corev1.ServicePort) (string, error) {
return schemeH2C, nil return schemeH2C, nil
} }
switch ap := *portSpec.AppProtocol; ap { switch ap := strings.ToLower(*portSpec.AppProtocol); ap {
case appProtocolH2C: case appProtocolH2C:
return schemeH2C, nil return schemeH2C, nil
case appProtocolHTTPS: case appProtocolHTTPS:

View File

@ -817,7 +817,7 @@ func getHTTPServiceProtocol(portSpec corev1.ServicePort) (string, error) {
return protocol, nil return protocol, nil
} }
switch ap := *portSpec.AppProtocol; ap { switch ap := strings.ToLower(*portSpec.AppProtocol); ap {
case appProtocolH2C: case appProtocolH2C:
return schemeH2C, nil return schemeH2C, nil
case appProtocolHTTP, appProtocolWS: case appProtocolHTTP, appProtocolWS:

View File

@ -2959,6 +2959,14 @@ func TestLoadHTTPRoutes_backendExtensionRef(t *testing.T) {
Name: "default-whoami-wss-http-80", Name: "default-whoami-wss-http-80",
Weight: ptr.To(1), Weight: ptr.To(1),
}, },
{
Name: "default-whoami-HTTP-http-80",
Weight: ptr.To(1),
},
{
Name: "default-whoami-HTTPS-http-443",
Weight: ptr.To(1),
},
}, },
}, },
}, },
@ -3004,6 +3012,34 @@ func TestLoadHTTPRoutes_backendExtensionRef(t *testing.T) {
}, },
}, },
}, },
"default-whoami-HTTPS-http-443": {
LoadBalancer: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
Servers: []dynamic.Server{
{
URL: "https://10.10.0.16:8443",
},
},
PassHostHeader: ptr.To(true),
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
},
},
"default-whoami-HTTP-http-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
Servers: []dynamic.Server{
{
URL: "http://10.10.0.17:8080",
},
},
PassHostHeader: ptr.To(true),
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
},
},
}, },
ServersTransports: map[string]*dynamic.ServersTransport{}, ServersTransports: map[string]*dynamic.ServersTransport{},
}, },