-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconfigmaps.yaml
More file actions
287 lines (277 loc) · 10.9 KB
/
Copy pathconfigmaps.yaml
File metadata and controls
287 lines (277 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
{{- /* Define the Envoy configuration in YAML at the top level */}}
{{- /* (it will be used only if envoy.external_config.load_from_configmap is false) */}}
{{- define "envoy.configuration.yaml" }}
{{- with . }}
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address:
address: 0.0.0.0
port_value: {{ .envoyAdminPort }}
static_resources:
listeners:
- name: listener_grpc
address:
socket_address:
address: 0.0.0.0
port_value: {{ .envoyGrpcPort }}
{{- with .envoy.rate_limiter.listener_level }}
{{- if .enabled }}
listener_filters:
- name: envoy.filters.listener.local_ratelimit
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.listener.local_ratelimit.v3.LocalRateLimit
stat_prefix: local_rate_limiter
token_bucket:
max_tokens: {{ .max_tokens }}
tokens_per_fill: {{ .tokens_per_fill }}
fill_interval: {{ .fill_interval }}
{{- end }}
{{- end }}
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
generate_request_id: true
{{- if (index .root.Values "opentelemetry-collector" "enabled") }}
tracing:
random_sampling:
value: {{ mulf .envoy.tracing_sampling_rate 100 }}
provider:
name: envoy.tracers.opentelemetry
typed_config:
"@type": type.googleapis.com/envoy.config.trace.v3.OpenTelemetryConfig
service_name: "${POD_NAME}"
grpc_service:
envoy_grpc:
cluster_name: opentelemetry_collector
timeout: 0.250s
{{- end }}
stat_prefix: ingress_grpc
codec_type: AUTO
route_config:
name: local_route_grpc
virtual_hosts:
- name: backend_grpc
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: triton_grpc_service
timeout: {{ .envoy.grpc_route_timeout }}
http_filters:
{{- with .envoy.rate_limiter.prometheus_based }}
{{- if .enabled }}
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
default_source_code:
filename: /etc/envoy/lua/envoy-filter.lua
{{- end }}
{{- end }}
{{- with .envoy.auth }}
{{- if .enabled }}
- name: envoy.filters.http.JwtAuthentication
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.jwt_authn.v3.JwtAuthentication
providers:
provider_icecube:
issuer: {{ .jwt_issuer }}
audiences: {{ .audiences }}
remote_jwks:
http_uri:
uri: {{ .jwt_remote_jwks_uri }}
cluster: auth_cluster
timeout: 100s
cache_duration:
seconds: 300
rules:
- match:
prefix: /
requires:
provider_name: provider_icecube
{{- end }}
{{- end }}
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
http2_protocol_options: {}
clusters:
{{- with .envoy.rate_limiter.prometheus_based }}
{{- if .enabled }}
- name: prometheus_cluster
connect_timeout: 5s
type: LOGICAL_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: prometheus_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{ include "supersonic.prometheusHost" $.root }}
port_value: {{ include "supersonic.prometheusPort" $.root }}
{{- if eq (include "supersonic.prometheusScheme" $.root) "https" }}
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
{{- end }}
{{- end }}
{{- end }}
{{- with .envoy.auth }}
{{- if .enabled }}
- name: auth_cluster
type: STRICT_DNS
connect_timeout: 500s
load_assignment:
cluster_name: auth_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{ .url }}
port_value: {{ .port }}
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
{{- end }}
{{- end }}
{{- if (index .root.Values "opentelemetry-collector" "enabled") }}
- name: opentelemetry_collector
type: STRICT_DNS
lb_policy: ROUND_ROBIN
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicit_http_config:
http2_protocol_options: {}
load_assignment:
cluster_name: opentelemetry_collector
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{ .root.Release.Name }}-opentelemetry-collector
port_value: 4317
{{- end }}
- name: triton_grpc_service
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: {{ .envoy.loadBalancerPolicy }}
http2_protocol_options: {}
load_assignment:
cluster_name: triton_grpc_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{ .tritonName }}
port_value: {{ .tritonGrpcPort }}
{{- end }}
{{- end }}
{{- /* Begin iterating over servers */}}
{{- if .Values.envoy.enabled }}
{{- /* Initialize envoyContext variable */}}
{{- $envoyContext := dict }}
{{- if not .Values.envoy.external_config.load_from_configmap }}
{{- /* Only prepare dynamic configuration context when not using external config */}}
{{- /* Define variables for ports */}}
{{- $tritonGrpcPort := "" -}}
{{- $envoyGrpcPort := "" -}}
{{- $envoyAdminPort := "" -}}
{{- range .Values.triton.service.ports }}
{{- if eq .name "grpc" }}
{{- $tritonGrpcPort = .port }}
{{- end }}
{{- end }}
{{- range .Values.envoy.service.ports }}
{{- if eq .name "grpc" }}
{{- $envoyGrpcPort = .port }}
{{- end }}
{{- if eq .name "admin" }}
{{- $envoyAdminPort = .port }}
{{- end }}
{{- end }}
{{- $tritonName := include "supersonic.tritonName" . }}
{{- /* Create a context to pass to the template */}}
{{- $envoyContext = dict
"envoyAdminPort" $envoyAdminPort
"envoyGrpcPort" $envoyGrpcPort
"tritonGrpcPort" $tritonGrpcPort
"prometheus" .Values.prometheus
"envoy" .Values.envoy
"triton" .Values.triton
"tritonName" $tritonName
"root" .
}}
{{- end }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "supersonic.name" . }}-envoy-config
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ include "supersonic.name" . }}
app.kubernetes.io/component: envoy
data:
envoy.yaml: |-
{{- if .Values.envoy.external_config.load_from_configmap }}
{{- if .Values.envoy.external_config.configmap_name }}
{{- /* Load configuration from external ConfigMap */}}
{{- $configmapName := .Values.envoy.external_config.configmap_name }}
{{- $dataKey := .Values.envoy.external_config.configmap_key | default "envoy.yaml" }}
{{- $externalConfig := (lookup "v1" "ConfigMap" .Release.Namespace $configmapName) }}
{{- if $externalConfig }}
{{- if $externalConfig.data }}
{{- if hasKey $externalConfig.data $dataKey }}
{{- /* Use the data from the external ConfigMap */}}
{{- (get $externalConfig.data $dataKey) | nindent 4 }}
{{- else }}
{{- fail (printf "Expected key '%s' not found in ConfigMap '%s/%s'" $dataKey .Release.Namespace $configmapName) }}
{{- end }}
{{- else }}
{{- fail (printf "No data found in ConfigMap '%s/%s'" .Release.Namespace $configmapName) }}
{{- end }}
{{- else }}
{{- fail (printf "External ConfigMap '%s/%s' not found. Please ensure the ConfigMap exists." .Release.Namespace $configmapName) }}
{{- end }}
{{- else }}
{{- /* Error if load_from_configmap is true but configmap_name is empty */}}
{{- fail "envoy.external_config.configmap_name must be specified when envoy.external_config.load_from_configmap is true" }}
{{- end }}
{{- else }}
{{- /* Use dynamically generated configuration */}}
{{ include "envoy.configuration.yaml" $envoyContext | indent 4 }}
{{- end }}
---
{{- if and .Values.envoy.rate_limiter.prometheus_based.enabled (not .Values.envoy.external_config.load_from_configmap) }}
{{- /* Create a ConfigMap for the Lua filter */}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "supersonic.name" . }}-lua-config
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ include "supersonic.name" . }}
app.kubernetes.io/component: envoy
data:
envoy-filter.lua: |-
{{- /* Read and process the Lua configuration file */}}
{{- $luaConfig := $.Files.Get .Values.envoy.rate_limiter.prometheus_based.luaConfig | nindent 4 }}
{{- $luaConfig = $luaConfig | replace "SERVER_LOAD_METRIC" (include "supersonic.defaultMetric" . | quote) }}
{{- $luaConfig = $luaConfig | replace "SERVER_LOAD_THRESHOLD" (quote .Values.serverLoadThreshold) }}
{{- $luaConfig = $luaConfig | replace "PROMETHEUS_SCHEME" (include "supersonic.prometheusScheme" .) }}
{{- $luaConfig = $luaConfig | replace "PROMETHEUS_HOST" (include "supersonic.prometheusHost" .) }}
{{- $luaConfig = $luaConfig | replace "PROMETHEUS_PORT" (include "supersonic.prometheusPort" .) }}
{{ $luaConfig | indent 4 }}
---
{{- end }}
{{- end }}