Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazyload using envoy as global sidecar to support h1/h2 #375

Merged
merged 8 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ metadata:
spec:
ports:
{{- range $gsSvcPorts }}
- name: http-{{ . }}
- name: http2-{{ . }}
port: {{ int . }}
protocol: TCP
targetPort: {{ int . }}
Expand All @@ -53,6 +53,18 @@ spec:
type: ClusterIP
{{- end }}
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: global-sidecar
namespace: {{ $clusterGsNamespace }}
spec:
host: global-sidecar.{{ $clusterGsNamespace }}.svc.cluster.local
trafficPolicy:
connectionPool:
http:
useClientProtocol: true
---
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down Expand Up @@ -362,11 +374,12 @@ spec:
- header:
key: "Slime-Orig-Dest"
value: "%DOWNSTREAM_LOCAL_ADDRESS%"
append: true
append: false
{{- if ne $addEnvHeaderViaLua "true" }}
- header:
key: "Slime-Source-Ns"
value: "%ENVIRONMENT(POD_NAMESPACE)%"
append: false
{{- end }}
{{- if eq $addEnvHeaderViaLua "true" }}
- applyTo: HTTP_FILTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ metadata:
spec:
ports:
{{- range $gsSvcPorts }}
- name: http-{{ . }}
- name: http2-{{ . }}
port: {{ int . }}
protocol: TCP
targetPort: {{ int . }}
Expand All @@ -52,6 +52,18 @@ spec:
type: ClusterIP
{{- end }}
---
apiVersion: networking.istio.io/v1beta1
Copy link
Contributor

@MouceL MouceL Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

又验证了下,下发这个dr后

看起来不需要再修改global-sidecar 为http2-80

grpc请求兜底到global-sidecar

[2023-06-25T07:56:54.322Z] "POST /proto.CustomerService/ListPerson HTTP/2" 200 - via_upstream - "-" 5 249 15 1 "127.0.0.6" "grpc-python/1.19.0 grpc-c/7.0.0 (linux; chttp2; gold)" "b5bc288c-d478-4b38-aa4c-237efe9ee18c" "backend:50051" "10.96.192.135:50051" PassthroughCluster 10.244.0.29:60078 10.96.192.135:50051 127.0.0.6:0 - -
[2023-06-25T07:56:54.321Z] "POST /proto.CustomerService/ListPerson HTTP/2" 200 - via_upstream - "-" 5 249 17 2 "-" "grpc-python/1.19.0 grpc-c/7.0.0 (linux; chttp2; gold)" "42179a91-e024-4c6e-bdb6-e0aec7f1033a" "backend:50051" "10.244.0.29:80" inbound|80|| 127.0.0.6:60535 10.244.0.29:80 10.244.0.28:36956 outbound_.80_._.global-sidecar.mesh-operator.svc.cluster.local default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个等我有空在确认一下

kind: DestinationRule
metadata:
name: global-sidecar
namespace: {{ $ns }}
spec:
host: global-sidecar.{{ $ns }}.svc.cluster.local
trafficPolicy:
connectionPool:
http:
useClientProtocol: true
---
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down Expand Up @@ -329,11 +341,11 @@ spec:
- header:
key: "Slime-Orig-Dest"
value: "%DOWNSTREAM_LOCAL_ADDRESS%"
append: true
append: false
- header:
key: "Slime-Source-Ns"
value: {{ $ns }}
append: true
append: false
- applyTo: VIRTUAL_HOST
match:
proxy:
Expand Down Expand Up @@ -456,4 +468,4 @@ Now that we've rendered all the resources for the global-sidecar, restore the in
{{- end }}

{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM envoyproxy/envoy:v1.26-latest

WORKDIR /

COPY proxy.yaml .

ENTRYPOINT ["envoy","-c","./proxy.yaml"]
115 changes: 115 additions & 0 deletions staging/src/slime.io/slime/modules/lazyload/cmd/envoyproxy/proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 20000
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
access_log:
- name: envoy.access_loggers.stdout
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
codec_type: AUTO
stat_prefix: health
use_remote_address: true
route_config:
name: health
virtual_hosts:
- name: all
domains:
- "*"
routes:
- match:
prefix: "/"
direct_response:
status: 200
body:
inline_string: "success"
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
- address:
socket_address:
address: 0.0.0.0
port_value: 80
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: AUTO
access_log:
- name: envoy.access_loggers.stdout
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
stat_prefix: egress_http
common_http_protocol_options:
idle_timeout: 840s
use_remote_address: true
route_config:
name: proxy
request_headers_to_remove:
- "Slime-Orig-Dest"
virtual_hosts:
- name: all
domains:
- "*"
routes:
- match:
prefix: "/"
route:
cluster: original_dst_cluster
http_filters:
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
default_source_code:
YonkaFang marked this conversation as resolved.
Show resolved Hide resolved
inline_string:
function insert_namespace(host, namespace)
if string.find(host, '%.') then
return host
end
if not namespace or namespace == '' then
return host
end
local idx = string.find(host, ':')
if idx then
local prefix = string.sub(host, 1, idx-1)
local suffix = string.sub(host, idx)
return prefix .. "." .. namespace .. suffix
end
return host .. '.' .. namespace
end

function envoy_on_request(request_handle)
local sourceNs = request_handle:headers():get("Slime-Source-Ns")
local reqHost = request_handle:headers():get(":authority")
reqHost = insert_namespace(reqHost, sourceNs)
request_handle:headers():replace(":authority", reqHost)
end
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- cleanupInterval: 8640000s
connectTimeout: 10s
lbPolicy: CLUSTER_PROVIDED
name: original_dst_cluster
type: ORIGINAL_DST
original_dst_lb_config:
use_http_header: true
http_header_name: "Slime-Orig-Dest"
typedExtensionProtocolOptions:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
useDownstreamProtocolConfig:
http2ProtocolOptions:
maxConcurrentStreams: 1073741824
httpProtocolOptions: {}


Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ func isHttp(port corev1.ServicePort) bool {
return false
}
p := strings.Split(port.Name, "-")[0]
return PortProtocol(p) == HTTP
protocol := PortProtocol(p)
return protocol == HTTP || protocol == GRPC || protocol == HTTP2
}

func updateWormholePort(wormholePort []string, portProtocolCache *PortProtocolCache) ([]string, bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *ServicefenceReconciler) RegisterSeHandler() {
func (r *ServicefenceReconciler) cachePort(istioSvcs []*model.Service) {
for _, svc := range istioSvcs {
for _, port := range svc.Ports {
if port.Protocol != model.HTTP {
if port.Protocol != model.HTTP && port.Protocol != model.GRPC && port.Protocol != model.HTTP2 {
continue
}
p := int32(port.Port)
Expand Down