Files
mg4/k8s/server.yaml
T
nilsandClaude Opus 5.5 a5db5604d3 Code review fixes: app 2.9.0, server 2.2.0
Telemetry no longer loses queued batches. The server drops a bad value,
or a sample without a plausible time, instead of rejecting the batch,
and answers 200 with what it dropped. The app sends only values inside
the server's ranges (speed as a magnitude, so reversing is fine) and no
samples before the head unit's clock is set.

Server:
- Pairing hands out and accepts a token only after the device is saved;
  a failed save leaves the request pending.
- A paired token serves only the installation id it was paired with
  (403 otherwise); the shared INGEST_TOKEN still serves any.
- Wrong-password lockouts and open pairing requests are limited per
  client address (last X-Forwarded-For entry), so a stranger cannot
  lock the owner out; a car starting again replaces its own request.
- ABRP forwarding skips samples stamped ahead of the server's clock,
  which used to stop it until a restart.

App:
- Settings written to plaintext during a keystore failure move back
  into encrypted storage; the stored installation id wins.
- The installation id is derived from ANDROID_ID on first start, so a
  reinstall finds its history; a stored or imported id still wins.
- The scanned config file is deleted after import (it holds the token).
- GPS stops while live telemetry is off or the server unconfigured, and
  pauses while parked and idle, keeping the fix the car parked with.
- Range estimates use the monotonic clock.
- One HTTP helper (ServerHttp) for telemetry, sync and pairing.
- Last Turkish strings translated; mise logs shows the NilsMG4 tags.

Grafana reads InfluxDB with its own read-only token (new grafana-influx
Secret, created by hand as described in k8s/README.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QLJfZQZeAKAwSqViTmLzki
2026-10-18 00:36:19 +02:00

95 lines
2.6 KiB
YAML

# The car server (Go). One replica on purpose: the ABRP rate limit is kept in memory, and
# two replicas would each forward to ABRP at the full rate.
apiVersion: apps/v1
kind: Deployment
metadata:
name: mg4-server
namespace: mg4
labels:
app.kubernetes.io/name: mg4-server
app.kubernetes.io/part-of: mg4
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app.kubernetes.io/name: mg4-server
template:
metadata:
labels:
app.kubernetes.io/name: mg4-server
app.kubernetes.io/part-of: mg4
spec:
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
seccompProfile:
type: RuntimeDefault
containers:
- name: server
# 2.2.0, pinned by digest so a re-pushed tag cannot change what runs.
image: git.stinnesbeck.com/nils/mg4-server@sha256:09eb151ff65300b3990a74063cc44a14d24bef810461e4e0e63451cfbcfd8258
ports:
- name: http
containerPort: 8080
env:
- name: INFLUX_URL
value: http://influxdb.mg4.svc:8086
- name: INFLUX_ORG
value: mg4
- name: INFLUX_BUCKET
value: mg4
# Where a phone reaches the server; the pairing QR code points here.
- name: PUBLIC_URL
value: https://car.k8s.stinnesbeck.com
- name: INFLUX_TOKEN
valueFrom:
secretKeyRef:
name: influxdb-auth
key: admin-token
# INGEST_TOKEN, APPROVAL_PASSWORD, ABRP_API_KEY, ABRP_USER_TOKEN,
# ABRP_MIN_INTERVAL_SECONDS.
envFrom:
- secretRef:
name: mg4-server
readinessProbe:
httpGet:
path: /v1/health
port: http
periodSeconds: 10
livenessProbe:
httpGet:
path: /v1/health
port: http
initialDelaySeconds: 5
periodSeconds: 30
resources:
requests:
cpu: 10m
memory: 32Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
---
apiVersion: v1
kind: Service
metadata:
name: mg4-server
namespace: mg4
labels:
app.kubernetes.io/name: mg4-server
app.kubernetes.io/part-of: mg4
spec:
selector:
app.kubernetes.io/name: mg4-server
ports:
- name: http
port: 80
targetPort: http