Repository navigation
deploy: strip a hand-patched SH_MODEL_CATALOG_HOSTS env before the k8s apply - #622
Conversation
…s apply Before 5615ffd the k8s manifests never wired the catalog allow-list, so the only way to set it on k8s was a hand patch of the control plane Deployment -- a literal env value owned by another field manager. The 0.8 manifests apply that env entry as a configMapKeyRef, and server-side apply never declares `value`, so the literal survives the merge and the API server rejects the Deployment ("may not be specified when `value` is not empty"): upgrading such a stack to 0.8 dies at the apply. setup.sh now reads the live control plane Deployment before its apply and strips a literal SH_MODEL_CATALOG_HOSTS env with kubectl set env ... -. An absent entry (a stack that never hand-patched) and a valueFrom one (a stack setup.sh itself applied) are left alone, so no re-run rolls the control plane for nothing; a failed read aborts the run like configmap_json's, never passing an unreadable Deployment off as a missing one. 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 is the right fix for the 0.8 SSA value + valueFrom rejection, and the probe is well scoped (it ignores absent and valueFrom entries and fails hard on an unreadable Deployment). The problem is that on a real pre-0.8 upgrade, moca-settings has no catalog key yet. Unless the operator re-exports SH_MODEL_CATALOG_HOSTS, the strip deletes the only copy of the allow-list, and the stack comes up on the default allow-list with no error. The hand-patched value needs to be migrated into moca-settings, not just removed.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell (setup.sh, setup.test.sh mock + test), Docs (deploy/k8s/README.md), Security
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: all passing except check (pending when this was drafted)
| # by another field manager. The manifests apply that env entry as a configMapKeyRef, and | ||
| # server-side apply never declares `value`, so the literal survives the merge and the API server | ||
| # rejects the Deployment ("may not be specified when `value` is not empty"). Strip the hand patch | ||
| # before the apply; write_settings has already carried the value into moca-settings by here. A |
There was a problem hiding this comment.
must-fix — This assumption is false on exactly the stack this function exists for. On a pre-0.8 stack, moca-settings has no SH_MODEL_CATALOG_HOSTS key (5615ffd introduced it). So in write_settings, catalog_hosts is only non-empty if the operator re-exports SH_MODEL_CATALOG_HOSTS for this run. Neither the README nor the error message asks them to. In the common case (./setup.sh --target … with no new env), moca-settings gets SH_MODEL_CATALOG_HOSTS="", this strip then deletes the only copy of the hand-patched allow-list, and the apply leaves the control plane on its default allow-list. The upgrade succeeds, but listing models through the gateway silently degrades to model_catalog_unavailable.
Suggested fix: carry the literal over before write_settings writes the ConfigMap. Read the live Deployment there, and when the env var is unset and moca-settings doesn't have the key (.data | has("SH_MODEL_CATALOG_HOSTS"), because cm_value can't tell missing from empty), use the Deployment's literal value as the fallback. That value should still go through valid_catalog_hosts. Precedence then becomes env > moca-settings > hand patch, and the strip here really is safe.
There was a problem hiding this comment.
Fixed in 17494ee: write_settings now falls back to the Deployment's literal when the variable is unset and moca-settings lacks the key — jq has(), not cm_value's emptiness, so an operator-cleared empty key stays cleared. Precedence is env > moca-settings > hand patch, and the carried value goes through valid_catalog_hosts; a malformed one is refused naming deployment/moca-control-plane as where it lives. The read is deployment_json (one command like configmap_json), and hand_patched_catalog_hosts propagates a failed read through the command substitution (|| return $?) so an unreadable Deployment still aborts the run instead of reading as absent.
| >"$MOCK_STATE/moca__Deployment__moca-control-plane.json" | ||
| } | ||
| reset_state | ||
| seed_control_plane_env '{"name": "SH_MODEL_CATALOG_HOSTS", "value": "litellm.cb.example.com"}' |
There was a problem hiding this comment.
suggestion — The test seeds litellm.cb.example.com but only checks that the entry was stripped. It never checks that the value survived. Add [[ "$(setting SH_MODEL_CATALOG_HOSTS)" == litellm.cb.example.com ]] || fail 'the hand-patched allow-list was dropped, not migrated'. That catches the data loss described on setup.sh. It would also help to add a case where SH_MODEL_CATALOG_HOSTS is given explicitly, to confirm that env wins over the hand patch.
There was a problem hiding this comment.
Added all of it in 17494ee: the hand-patch case now asserts setting SH_MODEL_CATALOG_HOSTS == litellm.cb.example.com; a new case runs with SH_MODEL_CATALOG_HOSTS=gw.override.example.com and the hand patch present (the given value wins, the patch is still stripped); a third stores a value first, then re-seeds the hand patch and re-runs without the variable (the stored value wins, the patch is still stripped). Plus a malformed hand-patched value (gw.example.com:4000) refused naming the Deployment, never reaching the stack apply.
| | .env[]? | select(.name == "SH_MODEL_CATALOG_HOSTS" and has("value"))] | length != 0' \ | ||
| >/dev/null || return 0 | ||
| log 'removing the hand-patched SH_MODEL_CATALOG_HOSTS env from deployment/moca-control-plane (the allow-list now lives in moca-settings)' | ||
| kc set env deployment/moca-control-plane -n "$NS" SH_MODEL_CATALOG_HOSTS- >/dev/null |
There was a problem hiding this comment.
nit — The jq probe only looks at the control-plane container, but kubectl set env deployment/… without -c patches every container in the pod template. Today there is only one container, so it makes no difference, but -c control-plane would keep the probe and the patch in sync if a sidecar is added later. You'd need to adjust the mock's positional $3/$4 match too. Also note that the strip rolls the control plane once on its own, before apply -k rolls it again. That's acceptable for a one-time migration, but it may be worth a line in the README note.
There was a problem hiding this comment.
Done in 17494ee: the strip now passes -c control-plane and the mock's set env guard matches the flag positions, so probe and patch stay in sync. The README note now also states the carry-over and that the strip rolls the control plane once on its own, just before the apply rolls it again — a one-time cost of the upgrade.
…tripping it Review of the strip step: on a pre-0.8 stack moca-settings has no SH_MODEL_CATALOG_HOSTS key (5615ffd introduced it), so unless the operator re-exports the variable, the strip deleted the only copy of the allow-list and the stack came up on the default allow-list with no error. write_settings now falls back to the Deployment's literal when the variable is unset and the key is absent (jq has(), not cm_value's emptiness -- an empty key is the operator's cleared allow-list and stays cleared). Precedence: a value given for the run, then moca-settings, then the hand patch; the carried value still goes through valid_catalog_hosts, and a bad one is refused naming deployment/moca-control-plane as where it lives. Also from review: kubectl set env now names -c control-plane, so the strip and the probe stay in sync if a sidecar is ever added; the README note adds the carry-over and the strip's own one-time roll. 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 to the 3f83d54 review: all three items are verified fixed in 17494ee. The hand-patched allow-list is now carried into moca-settings (env > moca-settings > hand patch, has()-guarded, validated with a Deployment-named error, and a failed Deployment read aborts the run). The strip is scoped with -c control-plane, and the tests cover the carry-over, the env-wins and stored-wins cases, and the malformed-value refusal. LGTM.
Problem
Before 5615ffd the k8s manifests never wired the catalog allow-list, so the only way to set it on k8s was a hand patch of the control plane Deployment — a literal
SH_MODEL_CATALOG_HOSTSenv value owned by another field manager. The 0.8 manifests apply that same env entry as aconfigMapKeyRef, and server-side apply never declaresvalue, so the literal survives the merge and the API server rejects the Deployment:i.e. upgrading such a stack to 0.8 dies at
kc apply -k(hit live on the shared single-namespace ROKS backend).Fix
Two steps, both in
setup.sh:write_settings): on a pre-0.8 stackmoca-settingshas no catalog key, so whenSH_MODEL_CATALOG_HOSTSis unset and the key is absent (jqhas(), notcm_value's emptiness — a deliberately emptied key stays emptied), the hand-patched literal becomes the value, validated throughvalid_catalog_hosts(a malformed one is refused namingdeployment/moca-control-planeas where it lives). Precedence: a value given for the run >moca-settings> the hand patch.strip_catalog_hosts_env, beforeapply -k):kubectl set env deployment/moca-control-plane -c control-plane SH_MODEL_CATALOG_HOSTS-. An absent entry (a stack that never hand-patched) and avalueFromone (a stacksetup.shitself applied) are untouched — no re-run rolls the control plane for nothing. The strip rolls the control plane once on its own, just before the apply rolls it again: a one-time cost of the upgrade.Also documents the behavior in the
SH_MODEL_CATALOG_HOSTSbullet ofdeploy/k8s/README.md.Testing
deploy/k8s/tests/setup.test.sh: mock kubectl servesget deployment moca-control-planefrom the JSON store and implementsset env … -; seeds a hand-patched Deployment and asserts the value is carried intomoca-settings, the strip fires beforeapply -k, the entry is removed from the live object, a given and a stored value both win over the hand patch, a malformed hand-patched value is refused naming its source, and nothing is stripped without a hand patch. TDD: watched each new assertion fail before its implementation.shellcheck -x -S warning(CI's pin,shellcheck-py 0.10.0.1) andprettier --checkclean.🤖 Generated with Claude Code