-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy path_helpers.tpl
More file actions
470 lines (439 loc) · 17.3 KB
/
Copy path_helpers.tpl
File metadata and controls
470 lines (439 loc) · 17.3 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
{{/*
Common labels
*/}}
{{- define "llm-d-router.labels" -}}
app.kubernetes.io/name: {{ include "llm-d-router.name" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
{{- end }}
{{/*
Router deployment name
*/}}
{{- define "llm-d-router.name" -}}
{{- $base := .Release.Name | default "default-pool" | lower | trim | trunc 40 -}}
{{ $base }}-epp
{{- end -}}
{{/*
Cluster RBAC unique name
*/}}
{{- define "llm-d-router.cluster-rbac-name" -}}
{{- $base := .Release.Name | default "default-pool" | lower | trim | trunc 40 }}
{{- $ns := .Release.Namespace | default "default" | lower | trim | trunc 40 }}
{{- printf "%s-%s-epp" $base $ns | quote | trunc 84 }}
{{- end -}}
{{/*
Selector labels
*/}}
{{- define "llm-d-router.selectorLabels" -}}
{{- if eq .Values.router.inferencePool.create false -}}
{{- /* LOGIC FOR STANDALONE EPP MODE */ -}}
llm-d-router-standalone: {{ include "llm-d-router.name" . }}
{{- else -}}
{{- /* LOGIC FOR PARENT (LLM-D-ROUTER-GATEWAY) MODE */ -}}
llm-d-router-gateway: {{ include "llm-d-router.name" . }}
{{- end -}}
{{- end -}}
{{/*
Mode labels
*/}}
{{- define "llm-d-router.modeLabels" -}}
{{- if eq .Values.router.inferencePool.create false -}}
llm-d.ai/igw-mode: llm-d-router-standalone
{{- else -}}
llm-d.ai/igw-mode: llm-d-router-gateway
{{- end -}}
{{- end -}}
{{/*
Return the monitoring provider name.
If router.monitoring.provider.name is unset/empty, default to
prometheusoperator. For backwards compatibility, provider.name=gke still maps
to gmp when no monitoring provider is explicitly set.
*/}}
{{- define "llm-d-router.monitoring.provider.name" -}}
{{- $monitoring := .Values.router.monitoring | default dict -}}
{{- $mp := index $monitoring "provider" | default dict -}}
{{- $mpName := index $mp "name" | default "" -}}
{{- $gatewayProvider := .Values.provider | default dict -}}
{{- $gatewayProviderName := index $gatewayProvider "name" | default "" -}}
{{- if and (kindIs "string" $mpName) (ne (trim $mpName) "") -}}
{{- $mpName -}}
{{- else if eq (lower $gatewayProviderName) "gke" -}}
gmp
{{- else -}}
prometheusoperator
{{- end -}}
{{- end -}}
{{/*
Return the monitoring provider config object.
When router.monitoring.provider.name is unset/empty, use defaults.
For backwards compatibility, provider.gke.autopilot is still honored when
provider.name=gke and no monitoring provider is explicitly set.
*/}}
{{- define "llm-d-router.monitoring.provider" -}}
{{- $monitoring := .Values.router.monitoring | default dict -}}
{{- $mp := index $monitoring "provider" | default dict -}}
{{- $mpName := include "llm-d-router.monitoring.provider.name" . -}}
{{- $gatewayProvider := .Values.provider | default dict -}}
{{- $gatewayProviderName := index $gatewayProvider "name" | default "" -}}
{{- $resolved := dict "name" $mpName -}}
{{- if eq (lower $mpName) "gmp" -}}
{{- $gmp := index $mp "gmp" | default dict -}}
{{- $legacyGke := dict -}}
{{- if and (eq (lower $gatewayProviderName) "gke") (index $gatewayProvider "gke") -}}
{{- $legacyGke = index $gatewayProvider "gke" -}}
{{- end -}}
{{- $_ := set $resolved "gmp" (mergeOverwrite (deepCopy $legacyGke) (deepCopy $gmp)) -}}
{{- else -}}
{{- $_ := set $resolved "prometheusoperator" (index $mp "prometheusoperator" | default dict) -}}
{{- end -}}
{{- toYaml $resolved -}}
{{- end -}}
{{/*
Return the standalone proxy type.
*/}}
{{- define "llm-d-router.proxyType" -}}
{{- $proxy := .Values.router.proxy | default dict -}}
{{- default "envoy" ($proxy.proxyType | default "envoy") | lower -}}
{{- end -}}
{{/*
Return the standalone proxy deployment mode: "sidecar" (proxy runs in the EPP
pod) or "service" (proxy runs as its own horizontally scalable Deployment).
*/}}
{{- define "llm-d-router.proxyMode" -}}
{{- $proxy := .Values.router.proxy | default dict -}}
{{- default "sidecar" ($proxy.mode | default "sidecar") | lower -}}
{{- end -}}
{{/*
Name of the standalone proxy Deployment and Service used in service mode.
*/}}
{{- define "llm-d-router.proxyName" -}}
{{- $base := .Release.Name | default "default-pool" | lower | trim | trunc 40 -}}
{{ $base }}-proxy
{{- end -}}
{{/*
Selector labels for the service-mode proxy Deployment and Service. Distinct
from the EPP selector so the proxy and EPP pods are never co-selected.
*/}}
{{- define "llm-d-router.proxySelectorLabels" -}}
llm-d-router-proxy: {{ include "llm-d-router.proxyName" . }}
{{- end -}}
{{/*
ext_proc upstream host the proxy uses to reach EPP. Loopback in sidecar mode;
the EPP Service FQDN in service mode.
*/}}
{{- define "llm-d-router.proxy.extProcHost" -}}
{{- if eq (include "llm-d-router.proxyMode" .) "service" -}}
{{- $domain := .Values.router.clusterDomain | default "cluster.local" -}}
{{- printf "%s.%s.svc.%s" (include "llm-d-router.name" .) .Release.Namespace $domain -}}
{{- else -}}
127.0.0.1
{{- end -}}
{{- end -}}
{{/*
ext_proc cluster discovery type. STATIC for the loopback sidecar; STRICT_DNS so
the proxy resolves the EPP Service FQDN in service mode.
*/}}
{{- define "llm-d-router.proxy.extProcClusterType" -}}
{{- if eq (include "llm-d-router.proxyMode" .) "service" -}}
STRICT_DNS
{{- else -}}
STATIC
{{- end -}}
{{- end -}}
{{/*
Whether the proxy fails open (passes traffic through) when EPP is unreachable.
Defaults to true in service mode for active/passive resiliency, false in
sidecar mode; overridable via router.proxy.failOpen.
*/}}
{{- define "llm-d-router.proxy.failOpen" -}}
{{- $proxy := .Values.router.proxy | default dict -}}
{{- $failOpen := index $proxy "failOpen" -}}
{{- if kindIs "bool" $failOpen -}}
{{- $failOpen -}}
{{- else if eq (include "llm-d-router.proxyMode" .) "service" -}}
true
{{- else -}}
false
{{- end -}}
{{- end -}}
{{/*
Normalize a scalar, comma-separated string, or list of ports into a
comma-separated numeric string.
*/}}
{{- define "llm-d-router.normalizedPortList" -}}
{{- $path := .path -}}
{{- $value := .value -}}
{{- if empty $value -}}
{{- fail (printf "%s is required" $path) -}}
{{- end -}}
{{- $rawPorts := list -}}
{{- if kindIs "slice" $value -}}
{{- $rawPorts = $value -}}
{{- else -}}
{{- $rawPorts = splitList "," (toString $value) -}}
{{- end -}}
{{- $ports := list -}}
{{- range $raw := $rawPorts -}}
{{- $rawString := trim (toString $raw) -}}
{{- if not (regexMatch "^[0-9]+$" $rawString) -}}
{{- fail (printf "%s must contain only numeric ports, got %q" $path $rawString) -}}
{{- end -}}
{{- $port := int $rawString -}}
{{- if or (lt $port 1) (gt $port 65535) -}}
{{- fail (printf "%s must contain ports between 1 and 65535, got %d" $path $port) -}}
{{- end -}}
{{- $ports = append $ports (toString $port) -}}
{{- end -}}
{{- if eq (len $ports) 0 -}}
{{- fail (printf "%s must contain at least one port" $path) -}}
{{- end -}}
{{- join "," $ports -}}
{{- end -}}
{{/*
Return the standalone proxy listener port exposed by the EPP Service.
The port is selected by the Service port named "http" so selection is
deterministic even when additional Service ports are configured.
*/}}
{{- define "llm-d-router.standaloneProxyListenerPort" -}}
{{- $servicePorts := .Values.router.extraServicePorts | default list -}}
{{- $found := false -}}
{{- $listenerPort := "" -}}
{{- $targetPort := "" -}}
{{- $hasTargetPort := false -}}
{{- range $index, $servicePort := $servicePorts -}}
{{- if eq (toString (index $servicePort "name")) "http" -}}
{{- if $found -}}
{{- fail ".Values.router.extraServicePorts must contain exactly one port named \"http\" when proxyType=agentgateway" -}}
{{- end -}}
{{- $found = true -}}
{{- if not (hasKey $servicePort "port") -}}
{{- fail (printf ".Values.router.extraServicePorts[%d].port is required for the port named \"http\"" $index) -}}
{{- end -}}
{{- $listenerPort = index $servicePort "port" -}}
{{- if hasKey $servicePort "targetPort" -}}
{{- $hasTargetPort = true -}}
{{- $targetPort = index $servicePort "targetPort" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not $found -}}
{{- fail ".Values.router.extraServicePorts must contain exactly one port named \"http\" when proxyType=agentgateway" -}}
{{- end -}}
{{- if kindIs "slice" $listenerPort -}}
{{- fail ".Values.router.extraServicePorts[name=http].port must be a single numeric port" -}}
{{- end -}}
{{- $listenerPortString := trim (toString $listenerPort) -}}
{{- if not (regexMatch "^[0-9]+$" $listenerPortString) -}}
{{- fail (printf ".Values.router.extraServicePorts[name=http].port must be numeric, got %q" $listenerPortString) -}}
{{- end -}}
{{- $listenerPortNumber := int $listenerPortString -}}
{{- if or (lt $listenerPortNumber 1) (gt $listenerPortNumber 65535) -}}
{{- fail (printf ".Values.router.extraServicePorts[name=http].port must be between 1 and 65535, got %d" $listenerPortNumber) -}}
{{- end -}}
{{- if $hasTargetPort -}}
{{- $targetPortString := trim (toString $targetPort) -}}
{{- if and (ne $targetPortString $listenerPortString) (ne $targetPortString "http") -}}
{{- fail (printf ".Values.router.extraServicePorts[name=http].targetPort must be omitted, %q, or \"http\" when proxyType=agentgateway, got %q" $listenerPortString $targetPortString) -}}
{{- end -}}
{{- end -}}
{{- $listenerPortString -}}
{{- end -}}
{{/*
Return the standalone EPP model-server target ports.
*/}}
{{- define "llm-d-router.standaloneEndpointTargetPorts" -}}
{{- $ports := list -}}
{{- range .Values.router.modelServers.targetPorts -}}
{{- $ports = append $ports (toString .number) -}}
{{- end -}}
{{- join "," $ports -}}
{{- end -}}
{{/*
Return the agentgateway standalone logical backend service name.
Derives the name from .Values.router.modelServers.matchLabels.app,
falling back to .Release.Name if not set.
*/}}
{{- define "llm-d-router.agentgateway.logicalBackendName" -}}
{{- $appLabel := "" -}}
{{- if and .Values.router.modelServers .Values.router.modelServers.matchLabels -}}
{{- $appLabel = index .Values.router.modelServers.matchLabels "app" | default "" -}}
{{- end -}}
{{- if not (empty $appLabel) -}}
{{- $appLabel -}}
{{- else -}}
{{- .Release.Name -}}
{{- end -}}
{{- end -}}
{{/*
Return the resolved proxy configuration for the current chart.
Standalone uses proxy presets merged with explicit proxy overrides.
*/}}
{{- define "llm-d-router.proxy" -}}
{{- $proxy := deepCopy (.Values.router.proxy | default dict) -}}
{{- $resolved := $proxy -}}
{{- if hasPrefix "llm-d-router-standalone" .Chart.Name -}}
{{- $proxyType := include "llm-d-router.proxyType" . -}}
{{- $presets := index $proxy "presets" | default dict -}}
{{- $preset := deepCopy ((index $presets $proxyType) | default dict) -}}
{{- $resolved = mergeOverwrite $preset $proxy -}}
{{- if eq $proxyType "agentgateway" -}}
{{- $listenerPort := include "llm-d-router.standaloneProxyListenerPort" . | int -}}
{{- $ports := index $resolved "ports" | default list -}}
{{- $resolvedPorts := list (dict "containerPort" $listenerPort "name" "http") -}}
{{- range $index, $port := $ports -}}
{{- if gt $index 0 -}}
{{- $resolvedPorts = append $resolvedPorts $port -}}
{{- end -}}
{{- end -}}
{{- $_ := set $resolved "ports" $resolvedPorts -}}
{{- end -}}
{{- end -}}
{{- $resolved = omit $resolved "agentgateway" "presets" "proxyType" -}}
{{- toYaml $resolved -}}
{{- end -}}
{{/*
Return the rendered proxy ConfigMap data.
*/}}
{{- define "llm-d-router.proxyConfigMapData" -}}
{{- $proxy := include "llm-d-router.proxy" . | fromYaml | default dict -}}
{{- $configMap := index $proxy "configMap" | default dict -}}
{{- $data := deepCopy ((index $configMap "data") | default dict) -}}
{{- if hasPrefix "llm-d-router-standalone" .Chart.Name -}}
{{- $proxyType := include "llm-d-router.proxyType" . -}}
{{- if eq $proxyType "agentgateway" -}}
{{- $generated := dict "config.yaml" (include "llm-d-router.proxy.agentgatewayConfig" .) -}}
{{- $data = mergeOverwrite $data $generated -}}
{{- else if eq $proxyType "envoy" -}}
{{- /* Render only the chart-owned envoy.yaml so the ext_proc target and
fail-open directives resolve; user-supplied keys stay literal. */ -}}
{{- if hasKey $data "envoy.yaml" -}}
{{- $_ := set $data "envoy.yaml" (tpl (toString (index $data "envoy.yaml")) $) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- toYaml $data -}}
{{- end -}}
{{/*
Render the default standalone agentgateway proxy config template.
*/}}
{{- define "llm-d-router.proxy.agentgatewayConfig" -}}
{{- $serviceName := include "llm-d-router.agentgateway.logicalBackendName" . -}}
{{- $serviceNamespace := .Release.Namespace -}}
{{- $servicePorts := splitList "," (include "llm-d-router.standaloneEndpointTargetPorts" .) -}}
{{- $backendPort := index $servicePorts 0 -}}
{{- $listenerPort := include "llm-d-router.standaloneProxyListenerPort" . | int -}}
config:
statsAddr: "0.0.0.0:15020"
readinessAddr: "0.0.0.0:15021"
binds:
- port: {{ $listenerPort }}
listeners:
- name: default
protocol: HTTP
routes:
- name: standalone-epp
matches:
- path:
pathPrefix: /
backends:
- service:
name: {{ printf "%s/%s" $serviceNamespace $serviceName | quote }}
port: {{ $backendPort }}
policies:
inferenceRouting:
endpointPicker:
host: {{ printf "127.0.0.1:%v" (.Values.router.epp.extProcPort | default 9002) | quote }}
destinationMode: passthrough
services:
- name: {{ $serviceName | quote }}
namespace: {{ $serviceNamespace | quote }}
hostname: {{ $serviceName | quote }}
vips: []
ports:
{{- range $servicePort := $servicePorts }}
{{ $servicePort }}: {{ $servicePort }}
{{- end }}
{{- end -}}
{{/*
EPP resource validations
*/}}
{{- define "llm-d-router.validations.epp.resources" -}}
{{- if not .Values.router.epp.resources }}
{{- fail ".Values.router.epp.resources is required. EPP is a critical component that must have resource requests set." }}
{{- end }}
{{- if not .Values.router.epp.resources.requests }}
{{- fail ".Values.router.epp.resources.requests is required. EPP is a critical component that must have resource requests set." }}
{{- end }}
{{- $_ := required ".Values.router.epp.resources.requests.cpu is required. EPP is a critical component that must have CPU requests set." .Values.router.epp.resources.requests.cpu }}
{{- $_ := required ".Values.router.epp.resources.requests.memory is required. EPP is a critical component that must have memory requests set." .Values.router.epp.resources.requests.memory }}
{{- end -}}
{{/*
Helper to retrieve GKE preferredBackends configuration safely across chart contexts.
*/}}
{{- define "llm-d-router.gkePreferredBackends" -}}
{{- $provider := .Values.provider | default dict -}}
{{- $gke := index $provider "gke" | default dict -}}
{{- index $gke "preferredBackends" | default dict | toYaml -}}
{{- end -}}
{{/*
EPP generic validations
*/}}
{{- define "llm-d-router.validations.epp.preferredBackends" -}}
{{- $gkePB := include "llm-d-router.gkePreferredBackends" . | fromYaml | default dict -}}
{{- if $gkePB.enabled }}
{{- $preferredReplicas := $gkePB.preferredReplicas | default 1 | int }}
{{- $defaultReplicas := $gkePB.defaultReplicas | default 1 | int }}
{{- if lt $preferredReplicas 1 }}
{{- fail ".Values.provider.gke.preferredBackends.preferredReplicas must be at least 1 when preferredBackends.enabled is true" }}
{{- end }}
{{- if lt $defaultReplicas 1 }}
{{- fail ".Values.provider.gke.preferredBackends.defaultReplicas must be at least 1 when preferredBackends.enabled is true" }}
{{- end }}
{{- end }}
{{- end -}}
{{- define "llm-d-router.validations.epp" -}}
{{- include "llm-d-router.validations.deprecations" . }}
{{- include "llm-d-router.validations.epp.resources" . }}
{{- include "llm-d-router.validations.epp.inferenceObjectives" . }}
{{- include "llm-d-router.validations.epp.tokenizer" . }}
{{- include "llm-d-router.validations.epp.preferredBackends" . }}
{{- end -}}
{{/*
Tokenizer validations: require modelName for the render sidecar's command args.
*/}}
{{- define "llm-d-router.validations.epp.tokenizer" -}}
{{- $tokenizer := .Values.router.tokenizer | default dict }}
{{- if and (dig "enabled" false $tokenizer) (not (dig "modelName" "" $tokenizer)) }}
{{- fail ".Values.router.tokenizer.modelName is required when the tokenizer is enabled." }}
{{- end }}
{{- end -}}
{{/*
EPP inferenceObjectives validations
*/}}
{{- define "llm-d-router.validations.epp.inferenceObjectives" -}}
{{- if and (eq .Values.router.inferencePool.create false) .Values.router.inferenceObjectives }}
{{- fail ".Values.router.inferenceObjectives can only be configured when .Values.router.inferencePool.create is true." }}
{{- end }}
{{- end -}}
{{/*
Deprecation validations
*/}}
{{- define "llm-d-router.validations.deprecations" -}}
{{- if .Values.inferenceExtension }}
{{- fail "Top-level 'inferenceExtension' is deprecated. Please migrate your values to 'router.epp' and other 'router.*' fields." }}
{{- end }}
{{- if .Values.inferencePool }}
{{- fail "Top-level 'inferencePool' is deprecated. Please migrate your values to 'router.modelServers' and 'router.inferencePool'." }}
{{- end }}
{{- if .Values.experimentalHttpRoute }}
{{- if hasPrefix "llm-d-router-gateway" .Chart.Name }}
{{- fail "Top-level 'experimentalHttpRoute' is deprecated. Please migrate your values to 'httpRoute'." }}
{{- else }}
{{- fail "Top-level 'experimentalHttpRoute' is deprecated and not supported in this chart." }}
{{- end }}
{{- end }}
{{- if .Values.inferenceObjectives }}
{{- fail "Top-level 'inferenceObjectives' is deprecated. Please migrate your values to 'router.inferenceObjectives'." }}
{{- end }}
{{- end -}}