Repository navigation
deploy: set SH_MODEL_CATALOG_HOSTS through setup.sh into moca-settings - #575
Conversation
The k8s manifests never wired the model catalog allow-list (compose and the VM env examples have it, from 7085b51), so an operator had to patch the control plane Deployment by hand -- and a re-run of setup.sh would drop the patch. SH_MODEL_CATALOG_HOSTS is now a sticky input like the token lifetimes: written to moca-settings (even when empty, so every stack hashes the same nine keys), read by the control plane through an optional configMapKeyRef, and rolled by the SETTINGS_HASH stamp. Entries are validated in parse_args and write_settings -- bare hostnames only, mirroring main.ts catalogHostsEnv, which the control plane would otherwise refuse to boot on after the apply. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
This PR wires SH_MODEL_CATALOG_HOSTS through deploy/k8s/setup.sh into moca-settings. The control plane reads it with an optional configMapKeyRef, and it follows the same sticky/clear/hash-roll pattern as the token TTLs. Values are validated before anything is applied. The logic, README and tests look right, and the new key is in the SETTINGS_HASH input, so a change rolls the control plane. One blocker: the lint check fails because Prettier reformats the new valueFrom line in control-plane.yaml. There is also a small validation gap (an embedded newline) that would still let a bad value crashloop the control plane.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell, YAML/K8s, Docs, Tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: failing (lint: prettier on control-plane.yaml:95). check was still running when this was drafted. Everything else passes, including deploy-scripts (setup.test.sh), shellcheck and k8s-kind-e2e.
| # the entries, which the control plane would otherwise refuse to boot on. | ||
| - name: SH_MODEL_CATALOG_HOSTS | ||
| valueFrom: | ||
| { configMapKeyRef: { name: moca-settings, key: SH_MODEL_CATALOG_HOSTS, optional: true } } |
There was a problem hiding this comment.
must-fix — this line is why the lint check is red (pre-commit prettier hook, "Run hooks" step). It is 105 chars, over printWidth: 100, and Prettier 3.9.10 (the repo's pinned version) rewrites it as:
valueFrom:
{
configMapKeyRef:
{ name: moca-settings, key: SH_MODEL_CATALOG_HOSTS, optional: true },
}SH_SANDBOX_DEFAULT_TIER above already uses that shape (line 72-75). Running pnpm exec prettier --write deploy/k8s/base/control-plane.yaml (or make fmt) fixes it.
There was a problem hiding this comment.
Fixed in 2d3080f — the multi-line shape, and [email protected] --check now passes on the file.
| valid_catalog_hosts() { | ||
| local raw h | ||
| [[ -z "$1" ]] && return 0 | ||
| IFS=',' read -r -a _vch_parts <<<"$1" |
There was a problem hiding this comment.
suggestion — a value with an embedded newline gets past this check but not past the control plane's. read -r reads only the first line, so SH_MODEL_CATALOG_HOSTS=$'gw.example.com\nhttps://x' validates as gw.example.com, the whole string is written to moca-settings, and catalogHostsEnv (which splits on , only and trims only the ends) then fails at boot, because URL.parse drops the \n and the hostname comparison fails. That is the crashloop-after-apply this check is meant to prevent. It applies to both callers (given and stored). Rejecting it up front closes the gap: [[ "$1" == *$'\n'* ]] && return 1. A test case for it would fit in the for bad in … loop.
Also a nit: _vch_parts isn't declared local, so it leaks into the global scope of a script that other code sources (SH_SOURCE_ONLY=1). Use local raw h; local -a _vch_parts.
There was a problem hiding this comment.
Fixed in 2d3080f — *$'\''\n''* is rejected up front in valid_catalog_hosts (before the read -r), for a given value and a stored one alike, with a test in both paths. _vch_parts is local -a now too.
| # valid_catalog_hosts VALUE: empty (the control plane's default, no extra hosts) or comma-separated | ||
| # bare hostnames. Mirrors main.ts catalogHostsEnv, which trims, lower-cases and skips empty entries | ||
| # but refuses a scheme, port, path or userinfo at BOOT; this keeps to [A-Za-z0-9.-] per entry, | ||
| # which covers every real hostname and none of what that check refuses. |
There was a problem hiding this comment.
nit — the comment says this check covers "none of what that check refuses", and that's true. It is also stricter than catalogHostsEnv in two places: an underscore (a_b.svc) and a trailing-dot FQDN (gw.example.com.) both pass URL.parse in the control plane but are refused here. Neither is likely for a real gateway, and k8s Service names can't contain _. Still, one clause in the comment ("and is stricter: no _, no trailing dot") would stop a later reader from assuming the two checks are equivalent.
There was a problem hiding this comment.
Done in 2d3080f — the comment now states the check is stricter than catalogHostsEnv (no _, no trailing dot, both of which URL.parse would take) and why stricter is the safe side.
- control-plane.yaml: the SH_MODEL_CATALOG_HOSTS valueFrom line was 105 chars, over printWidth 100; the multi-line shape Prettier 3.9.10 writes. - valid_catalog_hosts: read -r reads only the first line, so a value with an embedded newline validated as that line while catalogHostsEnv refuses the whole string at boot. Rejected up front now, given or stored, with a test in both paths. - _vch_parts declared local -a (the script is sourced by SH_SOURCE_ONLY=1 callers); the doc comment now says this check is stricter than catalogHostsEnv (no `_`, no trailing dot) rather than equivalent. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up at 2d3080f: all three items from the 5615ffd review are addressed — the control-plane.yaml valueFrom now has Prettier's multi-line shape (prettier 3.9.10 --check passes locally), valid_catalog_hosts rejects an embedded newline up front with tests for both the given and the stored value, _vch_parts is local -a, and the comment notes the check is stricter than catalogHostsEnv. LGTM.
What
deploy/k8s/setup.shnow takesSH_MODEL_CATALOG_HOSTSas a sticky input, like the token lifetimes:moca-settingson every run (even when empty, so every stack hashes the same nine keys) and read by the control plane through an optionalconfigMapKeyRefinbase/control-plane.yaml; a change rolls the control plane through the existingSETTINGS_HASHstamp.api.anthropic.com+ the default inference endpoint only).parse_args(given) andwrite_settings(stored): comma-separated bare hostnames only — a scheme, port or path is refused before anything touches the cluster, mirroringmain.ts catalogHostsEnv, which the control plane would otherwise refuse to boot on after the apply.Why
The k8s manifests never wired the catalog allow-list (compose and the VM env examples got it in 7085b51; k8s did not), so an operator had to
kubectl set envthe control plane Deployment by hand — and the nextsetup.shrun would silently drop the patch. Without the allow-list, per-session model listing degrades tomodel_catalog_unavailable(ids are still accepted unverified).Usage
README §"Inputs are sticky" documents it alongside the other
moca-settingsinputs.Testing
deploy/k8s/tests/setup.test.sh: new blocks mirroring the token-lifetime tests — sticky keep, empty clears, hash changes on a change (the roll), malformed values refused both given (before anykubectl apply) and stored; the eight-keys assertions updated to nine. All pass.shellcheck -x -S warning(the pre-commit/CI severity) clean on both changed scripts.🤖 Generated with Claude Code