mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 05:52:10 +00:00
☸️ feat: Add Optional Channel Gateway Helm Deployment (#17786)
* feat: deploy optional channel gateway with Helm * fix: make gateway release selection and workload identity explicit * refactor: share chart platform settings with the gateway * feat: validate gateway titles and route webhook ingress
This commit is contained in:
parent
d269d35a2c
commit
1e4d97812b
8 changed files with 576 additions and 34 deletions
6
.github/workflows/channel-gateway.yml
vendored
6
.github/workflows/channel-gateway.yml
vendored
|
|
@ -17,6 +17,7 @@ on:
|
|||
- '.github/workflows/tag-images.yml'
|
||||
- '.github/workflows/main-image-workflow.yml'
|
||||
- '.github/workflows/docker-publish.yml'
|
||||
- 'helm/librechat/**'
|
||||
- 'docker-compose.mongo-replica.yml'
|
||||
- 'utils/docker/init-replica.js'
|
||||
- '.env.example'
|
||||
|
|
@ -38,6 +39,7 @@ on:
|
|||
- '.github/workflows/tag-images.yml'
|
||||
- '.github/workflows/main-image-workflow.yml'
|
||||
- '.github/workflows/docker-publish.yml'
|
||||
- 'helm/librechat/**'
|
||||
- 'docker-compose.mongo-replica.yml'
|
||||
- 'utils/docker/init-replica.js'
|
||||
- '.env.example'
|
||||
|
|
@ -76,6 +78,10 @@ jobs:
|
|||
run: npm run build --workspace @librechat/channel-gateway
|
||||
- name: Verify release image provenance
|
||||
run: node .github/scripts/test-channel-release.mjs
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v5
|
||||
- name: Verify gateway Helm configuration
|
||||
run: node helm/librechat/tests/channel_gateway_render_test.mjs
|
||||
- name: Verify release and source Compose configuration
|
||||
run: node .github/scripts/test-channel-compose.mjs
|
||||
- name: Verify local replica conversion and restart
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ type: application
|
|||
# This is the chart version. This version number should be incremented each time you make changes
|
||||
# to the chart and its templates, including the app version.
|
||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||
version: 3.0.0
|
||||
version: 3.1.0
|
||||
|
||||
# This is the version number of the application being deployed. This version number should be
|
||||
# incremented each time you make changes to the application. Versions are not expected to
|
||||
|
|
|
|||
|
|
@ -38,8 +38,10 @@ Standard labels for chart-managed workloads.
|
|||
{{- $root := .root -}}
|
||||
helm.sh/chart: {{ include "librechat.chart" $root }}
|
||||
{{ .selectorLabels }}
|
||||
{{- if $root.Chart.AppVersion }}
|
||||
app.kubernetes.io/version: {{ $root.Chart.AppVersion | quote }}
|
||||
{{- $version := $root.Chart.AppVersion -}}
|
||||
{{- if hasKey . "version" -}}{{- $version = .version -}}{{- end -}}
|
||||
{{- if $version }}
|
||||
app.kubernetes.io/version: {{ $version | quote }}
|
||||
{{- end }}
|
||||
app.kubernetes.io/managed-by: {{ $root.Release.Service }}
|
||||
{{- end -}}
|
||||
|
|
@ -244,3 +246,55 @@ Define apiVersion of HorizontalPodAutoscaler
|
|||
{{- print "autoscaling/v2beta1" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Keep the gateway suffix even when the application name reaches 63 characters. */}}
|
||||
{{- define "librechat.channelGateway.fullname" -}}
|
||||
{{- $base := include "librechat.fullname" . -}}
|
||||
{{- $name := printf "%s-channel-gateway" $base -}}
|
||||
{{- if gt (len $name) 63 -}}
|
||||
{{- $name = printf "%s-channel-gateway-%s" ($base | trunc 38 | trimSuffix "-") ($base | sha256sum | trunc 8) -}}
|
||||
{{- end -}}
|
||||
{{- if eq $name $base -}}
|
||||
{{- fail "The gateway name collides with the application name; choose a different fullnameOverride" -}}
|
||||
{{- end -}}
|
||||
{{- $name -}}
|
||||
{{- end }}
|
||||
|
||||
{{- define "librechat.channelGateway.selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "librechat.channelGateway.fullname" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "librechat.channelGateway.labels" -}}
|
||||
{{- $version := include "librechat.channelGateway.imageTag" . | trunc 63 -}}
|
||||
{{- $version = regexReplaceAll "^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$" $version "" -}}
|
||||
{{- include "librechat.standardLabels" (dict "root" . "selectorLabels" (include "librechat.channelGateway.selectorLabels" .) "version" $version) }}
|
||||
{{- end }}
|
||||
|
||||
{{/* Shared platform controls; application secrets, storage and probes stay workload-owned. */}}
|
||||
{{- define "librechat.podSettings" -}}
|
||||
{{- $settings := dict "serviceAccountName" (include "librechat.serviceAccountName" .) -}}
|
||||
{{- range $key := list "hostAliases" "dnsPolicy" "dnsConfig" "imagePullSecrets" "nodeSelector" "affinity" "tolerations" -}}
|
||||
{{- with index $.Values $key -}}{{- $_ := set $settings $key . -}}{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if kindIs "bool" .Values.enableServiceLinks -}}
|
||||
{{- $_ := set $settings "enableServiceLinks" .Values.enableServiceLinks -}}
|
||||
{{- end -}}
|
||||
{{- toYaml $settings -}}
|
||||
{{- end }}
|
||||
|
||||
{{- define "librechat.channelGateway.imageTag" -}}
|
||||
{{- $tag := required "Set image.tag to a published LibreChat release containing Channels before enabling channelGateway" .Values.image.tag -}}
|
||||
{{- .Values.channelGateway.image.tag | default $tag -}}
|
||||
{{- end }}
|
||||
|
||||
{{/* Match the gateway runtime title contract, including UTF-16 length. */}}
|
||||
{{- define "librechat.channelGateway.appTitle" -}}
|
||||
{{- $raw := .Values.channelGateway.appTitle | default (get (default dict .Values.librechat.configEnv) "APP_TITLE") | default "LibreChat" | toString -}}
|
||||
{{- $title := regexReplaceAll "^[\\s\\p{Z}\\x{FEFF}]+|[\\s\\p{Z}\\x{FEFF}]+$" $raw "" -}}
|
||||
{{- $units := add (len (regexFindAll "." $title -1)) (len (regexFindAll "[\\x{10000}-\\x{10FFFF}]" $title -1)) -}}
|
||||
{{- if or (empty $title) (gt $units 40) (regexMatch "[<>|\\p{Cc}]" $title) -}}
|
||||
{{- fail "Set channelGateway.appTitle to a compatible title: 1-40 UTF-16 characters, without <, >, | or control characters" -}}
|
||||
{{- end -}}
|
||||
{{- $title -}}
|
||||
{{- end }}
|
||||
|
|
|
|||
41
helm/librechat/templates/channel-gateway-ingress.yaml
Normal file
41
helm/librechat/templates/channel-gateway-ingress.yaml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{{- $ingress := .Values.channelGateway.ingress -}}
|
||||
{{- if $ingress.enabled -}}
|
||||
{{- if not .Values.channelGateway.enabled -}}
|
||||
{{- fail "Enable channelGateway.enabled before enabling its ingress" -}}
|
||||
{{- end -}}
|
||||
{{- if not (semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion) -}}
|
||||
{{- fail "The gateway Ingress requires Kubernetes 1.19 or newer" -}}
|
||||
{{- end -}}
|
||||
{{- $name := include "librechat.channelGateway.fullname" . -}}
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: {{ $name }}
|
||||
labels:
|
||||
{{- include "librechat.channelGateway.labels" . | nindent 4 }}
|
||||
{{- with $ingress.annotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- with $ingress.className | default .Values.ingress.className }}
|
||||
ingressClassName: {{ . | quote }}
|
||||
{{- end }}
|
||||
{{- with $ingress.tls }}
|
||||
tls:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
rules:
|
||||
- host: {{ required "channelGateway.ingress.host is required when its ingress is enabled" $ingress.host | quote }}
|
||||
http:
|
||||
paths:
|
||||
{{- range list "/slack/events" "/slack/interactions" }}
|
||||
- path: {{ . }}
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: {{ $name }}
|
||||
port:
|
||||
number: 8080
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
103
helm/librechat/templates/channel-gateway.yaml
Normal file
103
helm/librechat/templates/channel-gateway.yaml
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
{{- if .Values.channelGateway.enabled }}
|
||||
{{- $gateway := .Values.channelGateway }}
|
||||
{{- $tag := include "librechat.channelGateway.imageTag" . }}
|
||||
{{- $secret := required "channelGateway.existingSecretName or global.librechat.existingSecretName is required" ($gateway.existingSecretName | default .Values.global.librechat.existingSecretName) }}
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "librechat.channelGateway.fullname" . }}
|
||||
labels:
|
||||
{{- merge (include "librechat.channelGateway.labels" . | fromYaml) (default dict .Values.deploymentLabels) | toYaml | nindent 4 }}
|
||||
{{- with .Values.deploymentAnnotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "librechat.channelGateway.selectorLabels" . | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
checksum/channel-gateway: {{ toYaml $gateway | sha256sum }}
|
||||
{{- with mergeOverwrite (deepCopy (default dict .Values.podAnnotations)) (default dict $gateway.podAnnotations) }}
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- merge (include "librechat.channelGateway.labels" . | fromYaml) (default dict .Values.podLabels) | toYaml | nindent 8 }}
|
||||
spec:
|
||||
automountServiceAccountToken: false
|
||||
{{- include "librechat.podSettings" . | nindent 6 }}
|
||||
securityContext:
|
||||
{{- mergeOverwrite (dict "runAsNonRoot" true "seccompProfile" (dict "type" "RuntimeDefault")) (deepCopy (default dict .Values.podSecurityContext)) | toYaml | nindent 8 }}
|
||||
containers:
|
||||
- name: channel-gateway
|
||||
image: "{{ $gateway.image.repository }}:{{ $tag }}"
|
||||
imagePullPolicy: {{ $gateway.image.pullPolicy }}
|
||||
securityContext:
|
||||
{{- mergeOverwrite (dict "allowPrivilegeEscalation" false "readOnlyRootFilesystem" true "runAsNonRoot" true "runAsUser" 1000 "capabilities" (dict "drop" (list "ALL"))) (deepCopy (default dict .Values.securityContext)) | toYaml | nindent 12 }}
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
env:
|
||||
- name: APP_TITLE
|
||||
value: {{ include "librechat.channelGateway.appTitle" . | quote }}
|
||||
- name: PORT
|
||||
value: "8080"
|
||||
- name: LISTEN_HOST
|
||||
value: "0.0.0.0"
|
||||
- name: LIBRECHAT_INTERNAL_URL
|
||||
value: {{ $gateway.internalUrl | default (printf "http://%s:%v" (include "librechat.fullname" .) .Values.service.port) | quote }}
|
||||
- name: CHANNEL_ID
|
||||
value: {{ required "channelGateway.channelId is required when enabled" $gateway.channelId | quote }}
|
||||
- name: CHANNEL_TENANT_ID
|
||||
value: {{ $gateway.tenantId | quote }}
|
||||
- name: CHANNEL_SERVICE_TOKEN
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ $secret | quote }}
|
||||
key: CHANNEL_SERVICE_TOKEN
|
||||
{{- with $gateway.slackAppTokenKey }}
|
||||
- name: SLACK_APP_TOKEN
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ $secret | quote }}
|
||||
key: {{ . | quote }}
|
||||
{{- end }}
|
||||
startupProbe:
|
||||
httpGet:
|
||||
path: /livez
|
||||
port: http
|
||||
periodSeconds: 5
|
||||
failureThreshold: 24
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /livez
|
||||
port: http
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /readyz
|
||||
port: http
|
||||
periodSeconds: 5
|
||||
resources:
|
||||
{{- toYaml $gateway.resources | nindent 12 }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ include "librechat.channelGateway.fullname" . }}
|
||||
labels:
|
||||
{{- include "librechat.channelGateway.labels" . | nindent 4 }}
|
||||
spec:
|
||||
type: ClusterIP
|
||||
ports:
|
||||
- name: http
|
||||
port: 8080
|
||||
targetPort: http
|
||||
selector:
|
||||
{{- include "librechat.channelGateway.selectorLabels" . | nindent 4 }}
|
||||
{{- end }}
|
||||
|
|
@ -33,25 +33,7 @@ spec:
|
|||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- with .Values.hostAliases }}
|
||||
hostAliases:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- if .Values.dnsPolicy }}
|
||||
dnsPolicy: {{ .Values.dnsPolicy }}
|
||||
{{- end }}
|
||||
{{- with .Values.dnsConfig }}
|
||||
dnsConfig:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.imagePullSecrets }}
|
||||
imagePullSecrets:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
serviceAccountName: {{ include "librechat.serviceAccountName" . }}
|
||||
{{- if kindIs "bool" .Values.enableServiceLinks }}
|
||||
enableServiceLinks: {{ .Values.enableServiceLinks }}
|
||||
{{- end }}
|
||||
{{- include "librechat.podSettings" . | nindent 6 }}
|
||||
securityContext:
|
||||
{{- toYaml .Values.podSecurityContext | nindent 8 }}
|
||||
{{- if .Values.initContainers }}
|
||||
|
|
@ -146,15 +128,3 @@ spec:
|
|||
{{- if .Values.volumes }}
|
||||
{{- toYaml .Values.volumes | nindent 6 }}
|
||||
{{- end }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
|
|
|
|||
331
helm/librechat/tests/channel_gateway_render_test.mjs
Normal file
331
helm/librechat/tests/channel_gateway_render_test.mjs
Normal file
|
|
@ -0,0 +1,331 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { copyFileSync, mkdtempSync, readFileSync, rmSync, mkdirSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { resolve, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import yaml from 'js-yaml';
|
||||
import { loadConfig } from '../../../packages/channel-gateway/src/config.ts';
|
||||
|
||||
const chart = fileURLToPath(new URL('..', import.meta.url));
|
||||
const fixture = mkdtempSync(join(tmpdir(), 'channel-gateway-chart-'));
|
||||
try {
|
||||
// Render the real gateway and main Service without downloading unrelated subcharts.
|
||||
mkdirSync(join(fixture, 'templates'));
|
||||
const metadata = yaml.load(readFileSync(resolve(chart, 'Chart.yaml'), 'utf8'));
|
||||
delete metadata.dependencies;
|
||||
writeFileSync(join(fixture, 'Chart.yaml'), yaml.dump(metadata));
|
||||
const defaults = yaml.load(readFileSync(resolve(chart, 'values.yaml'), 'utf8'));
|
||||
for (const name of ['mongodb', 'meilisearch', 'redis']) defaults[name].enabled = false;
|
||||
writeFileSync(join(fixture, 'values.yaml'), yaml.dump(defaults));
|
||||
for (const file of [
|
||||
'_helpers.tpl',
|
||||
'service.yaml',
|
||||
'deployment.yaml',
|
||||
'configmap-env.yaml',
|
||||
'serviceaccount.yaml',
|
||||
'channel-gateway.yaml',
|
||||
'channel-gateway-ingress.yaml',
|
||||
'ingress.yaml',
|
||||
]) {
|
||||
copyFileSync(resolve(chart, 'templates', file), join(fixture, 'templates', file));
|
||||
}
|
||||
function render(values = {}, platform = {}, kubeVersion) {
|
||||
writeFileSync(join(fixture, 'platform.yaml'), yaml.dump(platform));
|
||||
return yaml
|
||||
.loadAll(
|
||||
execFileSync(
|
||||
'helm',
|
||||
[
|
||||
'template',
|
||||
'fixture',
|
||||
fixture,
|
||||
'-f',
|
||||
join(fixture, 'platform.yaml'),
|
||||
...(kubeVersion ? ['--kube-version', kubeVersion] : []),
|
||||
...Object.entries(values).flatMap(([key, value]) => [
|
||||
typeof value === 'boolean' ? '--set' : '--set-string',
|
||||
`${key}=${value}`,
|
||||
]),
|
||||
],
|
||||
{ encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] },
|
||||
),
|
||||
)
|
||||
.filter(Boolean);
|
||||
}
|
||||
assert.equal(
|
||||
render().filter((doc) => doc.kind === 'Deployment').length,
|
||||
1,
|
||||
'disabled gateway must leave only the application Deployment',
|
||||
);
|
||||
const enabled = {
|
||||
'channelGateway.enabled': true,
|
||||
'channelGateway.channelId': 'connection',
|
||||
'image.tag': 'v1.2.3',
|
||||
};
|
||||
assert.throws(() => render({ 'channelGateway.enabled': true }), /Set image.tag/);
|
||||
assert.throws(() => render({ ...enabled, 'image.tag': '' }), /Set image.tag/);
|
||||
assert.throws(
|
||||
() => render({ ...enabled, 'image.tag': '', 'channelGateway.image.tag': 'v1.2.3' }),
|
||||
/Set image.tag/,
|
||||
);
|
||||
assert.throws(
|
||||
() => render({ ...enabled, 'channelGateway.channelId': '' }),
|
||||
/channelGateway.channelId/,
|
||||
);
|
||||
assert.throws(
|
||||
() => render({ ...enabled, 'global.librechat.existingSecretName': '' }),
|
||||
/existingSecretName/,
|
||||
);
|
||||
for (const overrides of [
|
||||
{},
|
||||
{ 'librechat.configEnv.APP_TITLE': 'Example Agents' },
|
||||
{ 'librechat.configEnv.APP_TITLE': 'é'.repeat(40) },
|
||||
{ 'librechat.configEnv.APP_TITLE': '😀'.repeat(20) },
|
||||
{ 'librechat.configEnv.APP_TITLE': '\ufeff Example Agents \ufeff' },
|
||||
{ 'librechat.configEnv.APP_TITLE': 'x'.repeat(41), 'channelGateway.appTitle': 'Short Title' },
|
||||
{
|
||||
'librechat.configEnv.APP_TITLE': 'Example Agents',
|
||||
'channelGateway.appTitle': 'Custom Agents',
|
||||
},
|
||||
{ fullnameOverride: 'a'.repeat(47) + '-channel-gateway' },
|
||||
{ 'channelGateway.image.tag': 'a'.repeat(128) },
|
||||
{ 'channelGateway.image.tag': '_custom_' },
|
||||
{ 'image.tag': 'v1.2.3-rc1', 'service.port': '9090' },
|
||||
{
|
||||
'channelGateway.image.tag': 'v1.2.4',
|
||||
'channelGateway.existingSecretName': 'gateway-only',
|
||||
'channelGateway.slackAppTokenKey': '',
|
||||
fullnameOverride: 'a'.repeat(63),
|
||||
},
|
||||
]) {
|
||||
const docs = render({ ...enabled, ...overrides });
|
||||
const deployment = docs.find(
|
||||
(doc) =>
|
||||
doc.kind === 'Deployment' &&
|
||||
doc.spec.template.spec.containers.some((container) => container.name === 'channel-gateway'),
|
||||
);
|
||||
const service = docs.find(
|
||||
(doc) => doc.metadata.name === deployment.metadata.name && doc.kind === 'Service',
|
||||
);
|
||||
const mainService = docs.find((doc) => doc.kind === 'Service' && doc !== service);
|
||||
const pod = deployment.spec.template;
|
||||
const container = pod.spec.containers[0];
|
||||
const env = Object.fromEntries(container.env.map((entry) => [entry.name, entry]));
|
||||
const matches = (selector) =>
|
||||
Object.entries(selector).every(([key, value]) => pod.metadata.labels[key] === value);
|
||||
assert(!matches(mainService.spec.selector), 'application traffic must never reach the gateway');
|
||||
assert(matches(service.spec.selector));
|
||||
assert(matches(deployment.spec.selector.matchLabels));
|
||||
assert(deployment.metadata.name.length <= 63);
|
||||
const version =
|
||||
overrides['channelGateway.image.tag'] || overrides['image.tag'] || enabled['image.tag'];
|
||||
const labelVersion = version.slice(0, 63).replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, '');
|
||||
assert.equal(deployment.metadata.labels['app.kubernetes.io/version'], labelVersion);
|
||||
assert.equal(pod.metadata.labels['app.kubernetes.io/version'], labelVersion);
|
||||
assert.equal(service.metadata.labels['app.kubernetes.io/version'], labelVersion);
|
||||
assert.equal(service.spec.type, 'ClusterIP');
|
||||
assert.equal(
|
||||
container.image,
|
||||
`ghcr.io/librechat-ai/librechat-channel-gateway:${overrides['channelGateway.image.tag'] || overrides['image.tag'] || enabled['image.tag']}`,
|
||||
);
|
||||
assert.equal(
|
||||
env.LIBRECHAT_INTERNAL_URL.value,
|
||||
`http://${mainService.metadata.name}:${overrides['service.port'] || 3080}`,
|
||||
);
|
||||
assert.equal(
|
||||
env.CHANNEL_SERVICE_TOKEN.valueFrom.secretKeyRef.name,
|
||||
overrides['channelGateway.existingSecretName'] || 'librechat-credentials-env',
|
||||
);
|
||||
assert.equal(
|
||||
container.envFrom,
|
||||
undefined,
|
||||
'gateway must not import unrelated application secrets',
|
||||
);
|
||||
assert.equal(
|
||||
env.APP_TITLE.value,
|
||||
(
|
||||
overrides['channelGateway.appTitle'] ||
|
||||
overrides['librechat.configEnv.APP_TITLE'] ||
|
||||
'LibreChat'
|
||||
).trim(),
|
||||
);
|
||||
const runtime = loadConfig({
|
||||
CHANNEL_SERVICE_TOKEN: 'fixture',
|
||||
CHANNEL_TENANT_ID: '_',
|
||||
CHANNEL_ID: 'fixture',
|
||||
APP_TITLE: env.APP_TITLE.value,
|
||||
});
|
||||
assert.equal(
|
||||
runtime.APP_TITLE,
|
||||
env.APP_TITLE.value,
|
||||
'accepted Helm titles must satisfy the actual runtime schema',
|
||||
);
|
||||
assert.notEqual(deployment.metadata.name, mainService.metadata.name);
|
||||
assert.equal(Boolean(env.SLACK_APP_TOKEN), overrides['channelGateway.slackAppTokenKey'] !== '');
|
||||
assert.equal(container.livenessProbe.httpGet.path, '/livez');
|
||||
assert.equal(container.readinessProbe.httpGet.path, '/readyz');
|
||||
assert.equal(pod.spec.automountServiceAccountToken, false);
|
||||
assert.equal(container.securityContext.readOnlyRootFilesystem, true);
|
||||
assert.equal(deployment.spec.strategy.type, 'Recreate');
|
||||
}
|
||||
for (const title of ['x'.repeat(41), '😀'.repeat(21), '<title>', 'a|b', '\u0085', '\ufeff']) {
|
||||
assert.throws(
|
||||
() => render(enabled, { librechat: { configEnv: { APP_TITLE: title } } }),
|
||||
/channelGateway.appTitle/,
|
||||
);
|
||||
assert.throws(
|
||||
() => render({ ...enabled, 'channelGateway.appTitle': title }),
|
||||
/channelGateway.appTitle/,
|
||||
);
|
||||
}
|
||||
assert.doesNotThrow(
|
||||
() => render({}, { librechat: { configEnv: { APP_TITLE: 'x'.repeat(41) } } }),
|
||||
'disabled gateways must not restrict the application title',
|
||||
);
|
||||
assert.throws(
|
||||
() => render({}, { channelGateway: { ingress: { enabled: true } } }),
|
||||
/Enable channelGateway/,
|
||||
);
|
||||
assert.throws(
|
||||
() => render(enabled, { channelGateway: { ingress: { enabled: true } } }),
|
||||
/ingress.host/,
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
render(
|
||||
enabled,
|
||||
{ channelGateway: { ingress: { enabled: true, host: 'gateway.example.test' } } },
|
||||
'1.18.20',
|
||||
),
|
||||
/Kubernetes 1.19/,
|
||||
);
|
||||
const webhooks = render(enabled, {
|
||||
ingress: {
|
||||
enabled: true,
|
||||
className: 'platform-controller',
|
||||
annotations: { apiOnly: 'fixture' },
|
||||
hosts: [{ host: 'gateway.example.test', paths: [{ path: '/', pathType: 'Prefix' }] }],
|
||||
},
|
||||
channelGateway: {
|
||||
slackAppTokenKey: '',
|
||||
ingress: {
|
||||
enabled: true,
|
||||
host: 'gateway.example.test',
|
||||
annotations: { callback: 'fixture' },
|
||||
tls: [{ hosts: ['gateway.example.test'], secretName: 'gateway-tls' }],
|
||||
},
|
||||
},
|
||||
});
|
||||
const webhookDeployment = webhooks.find(
|
||||
(doc) =>
|
||||
doc.kind === 'Deployment' && doc.spec.template.spec.containers[0].name === 'channel-gateway',
|
||||
);
|
||||
const webhookIngress = webhooks.find(
|
||||
(doc) => doc.kind === 'Ingress' && doc.metadata.name === webhookDeployment.metadata.name,
|
||||
);
|
||||
const apiIngress = webhooks.find((doc) => doc.kind === 'Ingress' && doc !== webhookIngress);
|
||||
assert.equal(webhookIngress.spec.ingressClassName, 'platform-controller');
|
||||
assert.equal(webhookIngress.spec.tls[0].secretName, 'gateway-tls');
|
||||
assert.equal(
|
||||
webhookIngress.metadata.annotations.apiOnly,
|
||||
undefined,
|
||||
'API rewrite annotations must not alter gateway callbacks',
|
||||
);
|
||||
assert.deepEqual(
|
||||
webhookIngress.spec.rules[0].http.paths.map((route) => route.path),
|
||||
['/slack/events', '/slack/interactions'],
|
||||
);
|
||||
for (const route of webhookIngress.spec.rules[0].http.paths) {
|
||||
assert.equal(route.pathType, 'Prefix');
|
||||
assert.equal(route.backend.service.name, webhookDeployment.metadata.name);
|
||||
assert.equal(route.backend.service.port.number, 8080);
|
||||
assert.notEqual(
|
||||
route.backend.service.name,
|
||||
apiIngress.spec.rules[0].http.paths[0].backend.service.name,
|
||||
);
|
||||
}
|
||||
assert(
|
||||
!webhookDeployment.spec.template.spec.containers[0].env.some(
|
||||
(entry) => entry.name === 'SLACK_APP_TOKEN',
|
||||
),
|
||||
);
|
||||
const ownClass = render(enabled, {
|
||||
channelGateway: {
|
||||
ingress: { enabled: true, host: 'gateway.example.test', className: 'gateway-controller' },
|
||||
},
|
||||
}).find((doc) => doc.kind === 'Ingress');
|
||||
assert.equal(ownClass.spec.ingressClassName, 'gateway-controller');
|
||||
const platform = {
|
||||
serviceAccount: { create: false, name: 'workload-account' },
|
||||
enableServiceLinks: false,
|
||||
hostAliases: [{ ip: '127.0.0.2', hostnames: ['fixture.invalid'] }],
|
||||
dnsPolicy: 'ClusterFirst',
|
||||
dnsConfig: { options: [{ name: 'ndots', value: '2' }] },
|
||||
imagePullSecrets: [{ name: 'registry-credentials' }],
|
||||
nodeSelector: { 'kubernetes.io/os': 'linux' },
|
||||
tolerations: [{ key: 'dedicated', operator: 'Exists', effect: 'NoSchedule' }],
|
||||
affinity: { podAntiAffinity: { preferredDuringSchedulingIgnoredDuringExecution: [] } },
|
||||
podAnnotations: { platform: 'fixture' },
|
||||
podLabels: { platform: 'fixture' },
|
||||
deploymentAnnotations: { platform: 'fixture' },
|
||||
deploymentLabels: { platform: 'fixture' },
|
||||
securityContext: { runAsUser: 10001 },
|
||||
};
|
||||
const deployments = render(enabled, platform).filter((doc) => doc.kind === 'Deployment');
|
||||
const gateway = deployments.find(
|
||||
(doc) => doc.spec.template.spec.containers[0].name === 'channel-gateway',
|
||||
);
|
||||
const app = deployments.find((doc) => doc !== gateway);
|
||||
const spec = gateway.spec.template.spec;
|
||||
for (const key of [
|
||||
'serviceAccountName',
|
||||
'enableServiceLinks',
|
||||
'hostAliases',
|
||||
'dnsPolicy',
|
||||
'dnsConfig',
|
||||
'imagePullSecrets',
|
||||
'nodeSelector',
|
||||
'tolerations',
|
||||
'affinity',
|
||||
]) {
|
||||
assert.deepEqual(spec[key], app.spec.template.spec[key], `gateway must honor shared ${key}`);
|
||||
if (key !== 'serviceAccountName')
|
||||
assert.deepEqual(spec[key], platform[key], `configured ${key} must survive rendering`);
|
||||
}
|
||||
assert.equal(spec.serviceAccountName, 'workload-account');
|
||||
assert.equal(spec.enableServiceLinks, false);
|
||||
assert.equal(spec.containers[0].securityContext.runAsUser, 10001);
|
||||
assert.equal(spec.containers[0].securityContext.readOnlyRootFilesystem, true);
|
||||
assert.equal(spec.automountServiceAccountToken, false);
|
||||
assert.equal(gateway.spec.template.metadata.annotations.platform, 'fixture');
|
||||
assert.equal(gateway.spec.template.metadata.labels.platform, 'fixture');
|
||||
assert.equal(gateway.metadata.annotations.platform, 'fixture');
|
||||
assert.equal(gateway.metadata.labels.platform, 'fixture');
|
||||
assert.equal(spec.containers[0].envFrom, undefined);
|
||||
const defaultGateway = render(enabled).find(
|
||||
(doc) =>
|
||||
doc.kind === 'Deployment' && doc.spec.template.spec.containers[0].name === 'channel-gateway',
|
||||
);
|
||||
assert.equal(defaultGateway.spec.template.spec.serviceAccountName, 'fixture-librechat');
|
||||
assert.equal(defaultGateway.spec.template.spec.enableServiceLinks, true);
|
||||
const clearedSecurity = render(enabled, { securityContext: null, podSecurityContext: null }).find(
|
||||
(doc) =>
|
||||
doc.kind === 'Deployment' && doc.spec.template.spec.containers[0].name === 'channel-gateway',
|
||||
);
|
||||
assert.equal(clearedSecurity.spec.template.spec.containers[0].securityContext.runAsUser, 1000);
|
||||
assert.deepEqual(
|
||||
clearedSecurity.spec.template.spec.containers[0].securityContext.capabilities.drop,
|
||||
['ALL'],
|
||||
);
|
||||
assert.equal(
|
||||
app.metadata.labels['app.kubernetes.io/version'],
|
||||
metadata.appVersion,
|
||||
'existing application labels must remain unchanged',
|
||||
);
|
||||
console.log(
|
||||
'PASS: optional gateway rendering, image matching, secret isolation, selectors and probes',
|
||||
);
|
||||
} finally {
|
||||
rmSync(fixture, { recursive: true, force: true });
|
||||
}
|
||||
|
|
@ -293,6 +293,43 @@ dnsConfig: {}
|
|||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
|
||||
# Optional Slack gateway. Enable channel/background policy separately in librechat.yaml.
|
||||
# Requires transaction-capable MongoDB; this does not change database topology.
|
||||
channelGateway:
|
||||
enabled: false
|
||||
image:
|
||||
repository: ghcr.io/librechat-ai/librechat-channel-gateway
|
||||
# Defaults to image.tag, which must explicitly select a release containing Channels.
|
||||
tag: ""
|
||||
pullPolicy: IfNotPresent
|
||||
# Defaults to librechat.configEnv.APP_TITLE or LibreChat. Set explicitly when
|
||||
# the application title comes from a Secret or global.librechat.env, or exceeds
|
||||
# the gateway limit (40 UTF-16 characters, no <, >, | or control characters).
|
||||
appTitle: ""
|
||||
channelId: ""
|
||||
tenantId: "_"
|
||||
# Empty derives the in-cluster LibreChat Service URL.
|
||||
internalUrl: ""
|
||||
# Must contain CHANNEL_SERVICE_TOKEN with the same value used by LibreChat.
|
||||
# Empty uses global.librechat.existingSecretName. Other API secrets are not imported.
|
||||
existingSecretName: ""
|
||||
# Set to "" for webhook transport; Socket Mode needs this existing Secret key.
|
||||
slackAppTokenKey: SLACK_APP_TOKEN
|
||||
resources: {}
|
||||
podAnnotations: {}
|
||||
# Optional webhook routing. Socket Mode requires no public ingress.
|
||||
# Set server transport/gatewayUrl separately; only Slack callbacks are exposed.
|
||||
ingress:
|
||||
enabled: false
|
||||
# Empty uses ingress.className (or the cluster default).
|
||||
className: ""
|
||||
annotations: {}
|
||||
host: ""
|
||||
tls: []
|
||||
# Pod identity, DNS, networking and scheduling use the chart's shared settings.
|
||||
# Global security contexts are honored; gateway defaults also enable seccomp,
|
||||
# a read-only root filesystem and disable privilege escalation/API token mounting.
|
||||
|
||||
langfuseFanout:
|
||||
enabled: false
|
||||
replicaCount: 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue