Skip to content

feat: Add namespace support to resources_create_or_update as in kubectl apply -n namespace#1135

Open
ash-thakur-rh wants to merge 1 commit into
containers:mainfrom
ash-thakur-rh:features/tool_namespace_support
Open

feat: Add namespace support to resources_create_or_update as in kubectl apply -n namespace#1135
ash-thakur-rh wants to merge 1 commit into
containers:mainfrom
ash-thakur-rh:features/tool_namespace_support

Conversation

@ash-thakur-rh
Copy link
Copy Markdown

Closes: #536

Root Cause

The resource parameter description in pkg/toolsets/core/resources.go only said:

"A JSON or YAML containing a representation of the Kubernetes resource. Should include top-level fields such as apiVersion, kind, metadata, and spec"

No mention of metadata.namespace or default namespace fallback behavior.

Changes

1. Tool description update

File: pkg/toolsets/core/resources.go:102

Updated the resource parameter description to include namespace guidance:

- "A JSON or YAML containing a representation of the Kubernetes resource.
-  Should include top-level fields such as apiVersion,kind,metadata, and spec"
+ "A JSON or YAML containing a representation of the Kubernetes resource.
+  Should include top-level fields such as apiVersion, kind, metadata, and spec.
+  For namespaced resources, include metadata.namespace to specify the target
+  namespace; if omitted, the configured default namespace is used"

2. Test proving non-default namespace is respected

File: pkg/mcp/resources_test.go

Added subtest resources_create_or_update respects namespace from resource metadata inside TestResourcesCreateOrUpdate. Existing tests all used namespace: default, which coincides with the envtest default, they would pass even if namespace handling was broken.

The new test:

  • Creates a ConfigMap with metadata.namespace: ns-1 (a non-default namespace already set up in common_test.go:136)
  • Asserts the ConfigMap exists in ns-1 with the correct namespace value
  • Asserts the ConfigMap does not exist in default, proving the namespace was not silently ignored

References

Signed-off-by: Ashish Thakur <ashishth@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

resources_create_or_update missing namespace

1 participant