Skip to content

deploy: strip a hand-patched SH_MODEL_CATALOG_HOSTS env before the k8s apply - #622

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/setup-strip-catalog-hosts-env
Oct 27, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/setup-strip-catalog-hosts-env

Conversation

@pdettori

@pdettori pdettori commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

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_HOSTS env value owned by another field manager. The 0.8 manifests apply that same 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:

The Deployment "moca-control-plane" is invalid: spec.template.spec.containers[0].env[15].valueFrom:
Invalid value: "": may not be specified when `value` is not empty

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:

  1. Carry the value over (write_settings): on a pre-0.8 stack moca-settings has no catalog key, so when SH_MODEL_CATALOG_HOSTS is unset and the key is absent (jq has(), not cm_value's emptiness — a deliberately emptied key stays emptied), the hand-patched literal becomes the value, validated through valid_catalog_hosts (a malformed one is refused naming deployment/moca-control-plane as where it lives). Precedence: a value given for the run > moca-settings > the hand patch.
  2. Strip the env (strip_catalog_hosts_env, before apply -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 a valueFrom one (a stack setup.sh itself 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_HOSTS bullet of deploy/k8s/README.md.

Testing

  • New section in deploy/k8s/tests/setup.test.sh: mock kubectl serves get deployment moca-control-plane from the JSON store and implements set env … -; seeds a hand-patched Deployment and asserts the value is carried into moca-settings, the strip fires before apply -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.
  • Full suite: 103 sections passed, 0 failures (baseline 102 + the new section).
  • shellcheck -x -S warning (CI's pin, shellcheck-py 0.10.0.1) and prettier --check clean.

🤖 Generated with Claude Code

…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]>
@pdettori
pdettori requested a review from cwiklik as a code owner October 27, 2026 01:34
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 27, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread deploy/k8s/setup.sh Outdated
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"}'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread deploy/k8s/setup.sh Outdated
| .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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pdettori
pdettori merged commit b8a94b4 into rossoctl:main Oct 27, 2026
15 checks passed
@pdettori
pdettori deleted the fix/setup-strip-catalog-hosts-env branch October 27, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants