Repository navigation
fix(operator): allow multiple keys of one Secret in spec.secrets - #6690
Conversation
SecretRef entries are per-key -- name and key are both required -- and the env builder maps each entry to its own secretKeyRef, so referencing two keys of the same Secret is expected usage. The list was keyed on name only, so the API server rejected the second entry as a duplicate. Fixes stacklok#6686 Signed-off-by: lights <115397533+lightsabit@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6690 +/- ##
==========================================
- Coverage 79.34% 79.28% -0.07%
==========================================
Files 802 802
Lines 81211 81211
==========================================
- Hits 64436 64385 -51
- Misses 16770 16821 +51
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Sanskarzz
left a comment
There was a problem hiding this comment.
@lightsabit Thanks for raising the PR.
The (name, key) schema change looks right, and the generated CRDs cover both served versions. Could you add a regression test that applies an MCPServer with two keys from the same Secret through API admission? The existing Go test does not exercise the validation failure in #6686. Please also update the PR body using the repository template: include Fixes #6686, select Bug fix, list the checks you actually ran, and assess API compatibility. Your post-renderer test is useful context; please clarify whether you also tested the CRDs generated by this PR. The issue would benefit from a minimal failing manifest and the exact server-side dry-run command.
…) list-map keys envtest suite installing the chart-shipped MCPServer CRDs and driving the stacklok#6686 shape through API admission: two entries referencing different keys of the same Secret are admitted (create and server-side apply, v1beta1 and v1alpha1) and stored as two entries, while an exact (name, key) duplicate is still rejected. Against the unpatched CRDs the two-key cases fail with the stacklok#6686 error, so the suite guards the regression it was written for.
|
@Sanskarzz thanks for the review — all four asks are addressed:
|
…suite t.Parallel in every test scope, per the paralleltest linter. The three server-side-apply calls keep the deprecated client.Apply patch constant under a scoped //nolint:staticcheck — the new Client.Apply API requires generated ApplyConfiguration types, which this repo does not generate, so the typed patch path is the only way to exercise SSA here.
TestForwarding_Logging_RealBackend timed out under CI load — the exact flake tracked upstream in stacklok#5962 (same failure mode, previously deflaked in stacklok#5963). Passes locally on this head; no code change, empty commit to re-run the failed jobs.
JAORMX
left a comment
There was a problem hiding this comment.
lgtm. Thanks @Sanskarzz for the heads up
Summary
spec.secretsentries are per-key references —nameandkeyare both required, and the operator's env builder turns each entry into its ownsecretKeyRefenv var — but the list was declaredx-kubernetes-list-type: mapkeyed on[name]alone (MCPServer spec.secrets list-map-keys=[name] makes two keys from one Secret unrepresentable #6686). Two entries sharing a Secret name are therefore treated as duplicate list keys and rejected at admission withduplicate entries for key [name="..."].keyas a second+listMapKeyonMCPServerSpec.Secretsand regenerated the CRDs.v1alpha1.MCPServerSpecisv1beta1.MCPServerSpec, so both served versions pick up the new merge keys from the single marker change.Fixes #6686
Type of change
Test plan
task test) — via CI on this PRtask test-e2e) — via CI on this PR (E2E core + operator suites, kind 1.33–1.35)task lint-fix) — via CI on this PRManual:
[name, key]schema change has been running on a live cluster as a Helm post-renderer over the releasedoperator-crdschart since the 0.49.0 release, through 0.50.0 and now 0.51.3. Two MCPServers there — e.g. one that logs in with a username/password pair held in a single Secret — reference 5 and 2 keys of that Secret and reconcile correctly, with real tool calls round-tripping through the gateway.deploy/charts/operator-crds/files/crds, and an MCPServer referencing two keys of one Secret is admitted through bothcreateand server-side apply onv1beta1andv1alpha1, with both entries stored. An exact(name, key)duplicate is still rejected. Run locally with envtest 1.31.0 (the versiontask operator-test-integrationpins) and 1.35.0, via the same ginkgo invocation Operator CI uses.mainCRDs swapped in, the same suite fails exactly as MCPServer spec.secrets list-map-keys=[name] makes two keys from one Secret unrepresentable #6686 describes (duplicate entries for key [name="shared-secret"]), so the tests exercise the original validation failure rather than passing vacuously.API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Touches the v1beta1 surface but is a relaxation only: adding
keyto the list-map keys accepts every previously valid object and newly accepts same-Secret multi-key lists that were previously rejected. TheCRD Schema Compatibilitycheck passes.Changes
cmd/thv-operator/api/v1beta1/mcpserver_types.go+listMapKey=keyonSecretsdeploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_mcpservers.yamlkeyadded tox-kubernetes-list-map-keys(both served versions)deploy/charts/operator-crds/templates/toolhive.stacklok.dev_mcpservers.yamlcmd/thv-operator/test-integration/mcp-server-secrets-admission/secrets_admission_test.goDoes this introduce a user-facing change?
Yes — MCPServer objects that reference multiple keys of the same Secret in
spec.secretsnow pass CRD validation instead of failing withduplicate entries for key [name="..."].Special notes for reviewers
secretsfield is schema-identical to this PR's generated CRDs (both served versions keyed onname+key).