feat(mcp): add secret and ConfigMap support to config_envs_add tool#3685
feat(mcp): add secret and ConfigMap support to config_envs_add tool#3685Ankitsinghsisodya wants to merge 4 commits intoknative:mainfrom
Conversation
…dates - Added unit tests for handling environment variables sourced from Secrets and ConfigMaps, covering both individual keys and all keys scenarios. - Updated the tool's description to clarify supported source types and precedence rules for the Value field. - Improved argument handling in the ConfigEnvsAddInput struct to ensure correct value templates are constructed based on provided inputs. - Enhanced test coverage for the config_envs_add functionality to validate expected behavior and error handling.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ankitsinghsisodya The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Ankitsinghsisodya. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
- Standardized formatting of struct fields in ConfigEnvsAddInput for better readability. - Updated test case for config_envs_add to ensure proper argument handling and maintain functionality.
There was a problem hiding this comment.
Pull request overview
Adds Kubernetes Secret/ConfigMap-backed env var sourcing to the config_envs_add MCP tool so agents can configure non-literal environment variables through MCP in the same way the CLI/config supports.
Changes:
- Extended
ConfigEnvsAddInputwithsecretName/secretKeyandconfigMapName/configMapKeyoptional fields. - Updated
Args()to auto-generate{{ secret:... }}/{{ configMap:... }}value templates, with explicitvaluetaking precedence. - Added unit tests for secret/configmap key and “import all keys” modes plus precedence behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| pkg/mcp/tools_config_envs.go | Adds new input fields, updates tool description, and generates secret/configmap template values in args building. |
| pkg/mcp/tools_config_envs_test.go | Adds new test cases validating generated --value templates and precedence behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3685 +/- ##
==========================================
+ Coverage 56.90% 56.97% +0.07%
==========================================
Files 181 181
Lines 20933 20985 +52
==========================================
+ Hits 11912 11957 +45
- Misses 7811 7816 +5
- Partials 1210 1212 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Introduced new test cases to validate error handling for secretKey and configMapKey when provided without their corresponding names. - Added tests to ensure proper validation of secretName, secretKey, configMapName, and configMapKey against allowed character sets. - Enhanced the ConfigEnvsAddInput struct with a validate method to enforce input constraints before processing. - Updated the config_envs_add tool's functionality to return appropriate errors for invalid inputs, improving robustness and user feedback.
- Added new validation checks to ensure that the `name` field is not set when importing all keys from a Secret or ConfigMap. - Implemented mutual exclusivity validation for `secretName` and `configMapName` to prevent simultaneous usage. - Updated the `ConfigEnvsAddInput` struct to reflect these validation rules, improving error handling and user feedback. - Introduced additional test cases to validate these new constraints and ensure proper error handling in various scenarios.
What
Add secret-backed and ConfigMap-backed environment variable support to the
config_envs_addMCP tool. Previously,ConfigEnvsAddInputonly exposedNameandValuefields, leaving agents unable to configure Kubernetes-sourced env vars through MCP.Changes
pkg/mcp/tools_config_envs.go: Add four optional fields toConfigEnvsAddInput:SecretName,SecretKey,ConfigMapName, andConfigMapKey. UpdateArgs()to construct the appropriate{{ secret:… }}/{{ configMap:… }}value template automatically. ExplicitValuetakes precedence when provided alongside source fields. Update the tool description to document all sourcing modes.pkg/mcp/tools_config_envs_test.go: Add five new test cases covering single-key secret, all-keys secret, single-key ConfigMap, all-keys ConfigMap, and precedence of explicitValueoverSecretName.Sourcing modes
name,valuename,secretName,secretKey{{ secret:name:key }}secretName{{ secret:name }}name,configMapName,configMapKey{{ configMap:name:key }}configMapName{{ configMap:name }}Testing
All 11 tests in
pkg/mcppass locally.