add_node_taint
Manage Kubernetes node behavior by adding taints to control pod scheduling. Specify context, node, taint key, value, and effect (NoSchedule, PreferNoSchedule, NoExecute) to restrict or influence pod placement. Returns updated node taints as JSON.
Instructions
Add a taint to a node.
Args: context_name: The Kubernetes context name node_name: The name of the node to modify taint_key: The taint key to add taint_value: The taint value to set taint_effect: The taint effect (NoSchedule, PreferNoSchedule, or NoExecute)
Returns: JSON string containing the updated node taints
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| node_name | Yes | ||
| taint_effect | Yes | ||
| taint_key | Yes | ||
| taint_value | Yes |
Implementation Reference
- tools/node.py:190-277 (handler)The handler function for the 'add_node_taint' tool. It adds or updates a taint on a specified Kubernetes node by patching the node's spec with the new taint using the Kubernetes CoreV1Api. Validates the taint effect and handles both new and existing taints. Returns JSON with the updated node name and taints list. Registered via @mcp.tool() decorator.@mcp.tool() @use_current_context def add_node_taint(context_name: str, node_name: str, taint_key: str, taint_value: str, taint_effect: str): """ Add a taint to a node. Args: context_name: The Kubernetes context name node_name: The name of the node to modify taint_key: The taint key to add taint_value: The taint value to set taint_effect: The taint effect (NoSchedule, PreferNoSchedule, or NoExecute) Returns: JSON string containing the updated node taints """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] # Validate the taint effect valid_effects = ["NoSchedule", "PreferNoSchedule", "NoExecute"] if taint_effect not in valid_effects: result = { "error": f"Invalid taint effect. Must be one of {', '.join(valid_effects)}" } return json.dumps(result) # Get the current node node = core_v1.read_node(node_name) # Prepare the taints current_taints = [] if node.spec.taints: current_taints = node.spec.taints # Check if taint with this key already exists exists = False for i, taint in enumerate(current_taints): if taint.key == taint_key: # Update existing taint current_taints[i] = V1Taint( key=taint_key, value=taint_value, effect=taint_effect ) exists = True break # Add new taint if it doesn't exist if not exists: current_taints.append(V1Taint( key=taint_key, value=taint_value, effect=taint_effect )) # Apply the patch body = { "spec": { "taints": [ { "key": taint.key, "value": taint.value, "effect": taint.effect } for taint in current_taints ] } } patched_node = core_v1.patch_node(node_name, body) # Format the taints for response response_taints = [] if patched_node.spec.taints: response_taints = [ { "key": taint.key, "value": taint.value, "effect": taint.effect } for taint in patched_node.spec.taints ] result = { "name": patched_node.metadata.name, "taints": response_taints } return json.dumps(result)
- tools/node.py:190-190 (registration)The @mcp.tool() decorator registers the add_node_taint function as an MCP tool.@mcp.tool()