Multiplayer agent harness for work.
{{- range $component, $host := dict "admin" "web-ui" "auth" "portal" }}
{{- if and (index $.Values.services $component).enabled (not (index $.Values.services $host).enabled) }}
{{- fail (printf "%s requires services.%s.enabled=true" $component $host) }}
{{- end }}
{{- end }}
{{- $root := . -}}
{{- range $name, $svc := .Values.services }}
{{- if and $svc.enabled (ne $name "admin") (ne $name "auth") }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "qm.fullname" $root }}-{{ $name }}
labels:
{{- include "qm.labels" $root | nindent 4 }}
app.kubernetes.io/component: {{ $name }}
spec:
replicas: {{ $svc.replicas }}
{{- if and (eq $name "core") $svc.persistence.enabled }}
{{- if gt (int $svc.replicas) 1 }}
{{- fail "core persistence supports at most one replica; shared-storage multi-replica operation is not supported" }}
{{- end }}
strategy:
type: Recreate
rollingUpdate: null
{{- end }}
selector:
matchLabels:
{{- include "qm.selectorLabels" $root | nindent 6 }}
app.kubernetes.io/component: {{ $name }}
template:
metadata:
annotations:
checksum/secret-env: {{ include (print $root.Template.BasePath "/secret.yaml") $root | sha256sum }}
labels:
{{- include "qm.selectorLabels" $root | nindent 8 }}
app.kubernetes.io/component: {{ $name }}
spec:
{{- with $root.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "qm.serviceAccountName" $root }}
{{- if and (eq $name "core") $svc.persistence.enabled }}
securityContext:
fsGroup: 1000
fsGroupChangePolicy: OnRootMismatch
volumes:
- name: data
persistentVolumeClaim:
claimName: {{ $svc.persistence.existingClaim | default (printf "%s-core-data" (include "qm.fullname" $root)) | quote }}
{{- end }}
containers:
- name: {{ $name }}
image: {{ include "qm.image" (dict "root" $root "name" $name "service" $svc) | quote }}
{{- if and (eq $name "core") $svc.persistence.enabled }}
volumeMounts:
- name: data
mountPath: /data
{{- end }}
imagePullPolicy: {{ $root.Values.image.pullPolicy }}
{{- with $svc.command }}
command:
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: {{ ternary "http" "proxy" (eq $svc.type "web") }}
containerPort: {{ $svc.port }}
{{- $wired := dict }}
{{- $svcHost := printf "%s-%%s.%s.svc.cluster.local" (include "qm.fullname" $root) $root.Release.Namespace }}
{{- if ne $name "core" }}
{{- $_ := set $wired "CORE_API_URL" (printf "http://%s:%v" (printf $svcHost "core") (index $root.Values.services "core").port) }}
{{- end }}
{{- $authEnabled := (index $root.Values.services "auth").enabled }}
{{- $authUpstream := "http://127.0.0.1:8099" }}
{{- $base := trimSuffix "/" ($root.Values.publicUrl | default "") }}
{{- $issuer := printf "%s/idp" $base }}
{{- if eq $name "portal" }}
{{- $_ := set $wired "WEB_UI_UPSTREAM" (printf "http://%s:%v" (printf $svcHost "web-ui") (index $root.Values.services "web-ui").port) }}
{{- $_ := set $wired "ADMIN_UPSTREAM" (printf "http://%s:%v/admin" (printf $svcHost "web-ui") (index $root.Values.services "web-ui").port) }}
{{- if $authEnabled }}
{{- $_ := set $wired "AUTH_BROKER_UPSTREAM" $authUpstream }}
{{- $_ := set $wired "AUTH_EMBEDDED" "1" }}
{{- $_ := set $wired "AUTH_BROKER_PREFIX" "/idp" }}
{{- end }}
{{- end }}
{{- if $root.Values.publicUrl }}
{{- if eq $name "core" }}
{{- $_ := set $wired "AGENT_API_URL" $root.Values.publicUrl }}
{{- $_ := set $wired "PUBLIC_WEB_URL" $root.Values.publicUrl }}
{{- end }}
{{- if eq $name "portal" }}
{{- $_ := set $wired "PORTAL_PUBLIC_URL" $root.Values.publicUrl }}
{{- if $authEnabled }}
{{- $_ := set $wired "OIDC_ISSUER" $issuer }}
{{- $_ := set $wired "OIDC_AUTH_ENDPOINT" (printf "%s/authorize" $issuer) }}
{{- $_ := set $wired "OIDC_TOKEN_ENDPOINT" (printf "%s/token" $authUpstream) }}
{{- $_ := set $wired "OIDC_USERINFO_ENDPOINT" (printf "%s/userinfo" $authUpstream) }}
{{- $_ := set $wired "OIDC_JWKS_URI" (printf "%s/.well-known/jwks.json" $authUpstream) }}
{{- $_ := set $wired "OIDC_SCOPES" "openid email" }}
{{- $_ := set $wired "OIDC_PRINCIPAL_CLAIM" "email" }}
{{- end }}
{{- end }}
{{- if and (eq $name "portal") $authEnabled }}
{{- $_ := set $wired "AUTH_ISSUER" $issuer }}
{{- $_ := set $wired "AUTH_REDIRECT_URI" (printf "%s/auth/callback" $base) }}
{{- end }}
{{- if eq $name "web-ui" }}
{{- $_ := set $wired "WEB_UI_PUBLIC_URL" $root.Values.publicUrl }}
{{- end }}
{{- end }}
{{- if eq $name "web-ui" }}
{{- $_ := set $wired "ADMIN_BASE_PATH" "/admin" }}
{{- $_ := set $wired "ADMIN_ENABLED" (ternary "1" "0" (index $root.Values.services "admin").enabled) }}
{{- end }}
{{- $componentEnv := deepCopy ($svc.env | default dict) }}
{{- $component := "" }}
{{- if eq $name "portal" }}{{- $component = "auth" }}{{- end }}
{{- if eq $name "web-ui" }}{{- $component = "admin" }}{{- end }}
{{- if and $component (index $root.Values.services $component).enabled }}
{{- range $k, $v := (index $root.Values.services $component).env }}
{{- if ne $k "PORT" }}
{{- if and (hasKey $componentEnv $k) (ne (toString (index $componentEnv $k)) (toString $v)) }}
{{- fail (printf "Conflicting %s settings in %s and %s" $k $name $component) }}
{{- end }}
{{- $_ := set $componentEnv $k $v }}
{{- end }}
{{- end }}
{{- end }}
{{- $env := mergeOverwrite (deepCopy $wired) (deepCopy ($root.Values.env | default dict)) $componentEnv }}
{{- if eq $name "egress-proxy" }}
{{- if ne (int $svc.port) 48080 }}
{{- fail "services.egress-proxy.port must be 48080: the Envoy listener is fixed in the image" }}
{{- end }}
{{- else }}
{{- if and (hasKey $env "PORT") (ne (toString (index $env "PORT")) (toString $svc.port)) }}
{{- fail (printf "%s PORT conflicts with services.%s.port; configure the port there" $name $name) }}
{{- end }}
{{- $_ := set $env "PORT" (toString $svc.port) }}
{{- end }}
{{- if and (eq $name "core") $svc.persistence.enabled }}
{{- if and (hasKey $env "DATA_DIR") (ne (index $env "DATA_DIR") "/data") }}
{{- fail "core persistence requires DATA_DIR=/data" }}
{{- end }}
{{- $_ := set $env "DATA_DIR" "/data" }}
{{- end }}
{{- if and (eq $name "portal") $authEnabled (not $root.Values.envFrom) }}
{{- range $authKey, $oidcKey := dict "AUTH_ALLOWED_EMAILS" "OIDC_ALLOWED_EMAILS" "AUTH_ALLOWED_EMAIL_DOMAIN" "OIDC_ALLOWED_EMAIL_DOMAIN" }}
{{- if and (not (hasKey $env $oidcKey)) (not (index $root.Values.secretEnv $oidcKey)) }}
{{- if hasKey $env $authKey }}
{{- $_ := set $env $oidcKey (index $env $authKey) }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if $env }}
env:
{{- range $k, $v := $env }}
- name: {{ $k }}
value: {{ $v | quote }}
{{- end }}
{{- end }}
{{- if or (include "qm.hasSecretEnv" $root) $root.Values.envFrom }}
envFrom:
{{- if include "qm.hasSecretEnv" $root }}
- secretRef:
name: {{ include "qm.fullname" $root }}-env
{{- end }}
{{- with $root.Values.envFrom }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- if $svc.startupProbe }}
startupProbe:
{{- toYaml $svc.startupProbe | nindent 12 }}
{{- end }}
{{- if $svc.healthPath }}
readinessProbe:
timeoutSeconds: 2
httpGet:
path: {{ $svc.readinessPath | default $svc.healthPath }}
port: {{ $svc.port }}
livenessProbe:
httpGet:
path: {{ $svc.healthPath }}
port: {{ $svc.port }}
{{- else }}
readinessProbe:
tcpSocket:
port: {{ $svc.port }}
livenessProbe:
tcpSocket:
port: {{ $svc.port }}
{{- end }}
{{- with $svc.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $svc.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- end }}