get_namespace_resource_quota
Retrieve resource quotas and usage for a specified namespace in a Kubernetes cluster using the context name. Returns JSON data for monitoring and managing resource allocation.
Instructions
Get current resource quotas for a namespace.
Args: context_name: The Kubernetes context name namespace: The name of the namespace
Returns: JSON string containing the current resource quotas and their usage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| namespace | Yes |
Implementation Reference
- tools/namespace.py:429-479 (handler)The handler function implementing the 'get_namespace_resource_quota' MCP tool. It is registered via the @mcp.tool() decorator. The function fetches and returns resource quotas for a specified Kubernetes namespace, including checks for namespace existence and error handling.@mcp.tool() @use_current_context def get_namespace_resource_quota(context_name: str, namespace: str): """ Get current resource quotas for a namespace. Args: context_name: The Kubernetes context name namespace: The name of the namespace Returns: JSON string containing the current resource quotas and their usage """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] try: # Check if namespace exists try: core_v1.read_namespace(namespace) except ApiException as e: if e.status == 404: return json.dumps({"error": f"Namespace '{namespace}' not found"}) else: return json.dumps({"error": f"API error: {str(e)}"}) # Get all resource quotas in the namespace quotas = core_v1.list_namespaced_resource_quota(namespace) if not quotas.items: return json.dumps({ "namespace": namespace, "message": "No resource quotas defined for this namespace" }) quota_info = [] for quota in quotas.items: quota_data = { "name": quota.metadata.name, "hard": quota.spec.hard, "used": quota.status.used if hasattr(quota.status, 'used') else {} } quota_info.append(quota_data) result = { "namespace": namespace, "quotas": quota_info } return json.dumps(result) except ApiException as e: return json.dumps({"error": f"Failed to get resource quotas: {str(e)}"})