forked from containers/kubernetes-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 32
NE-2488: Add OpenShift router tools to NetworkEdge toolset #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alebedev87
wants to merge
2
commits into
openshift:main
Choose a base branch
from
alebedev87:router-toolset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| # Network Ingress&DNS (netedge) Toolset | ||
|
|
||
| This document provides guidance on using the Network Ingress&DNS (formerly known as Network Edge) toolset with the Kubernetes MCP Server. | ||
|
|
||
| ## Available Tools | ||
|
|
||
| The netedge toolset provides tools for monitoring and troubleshooting OpenShift network ingress and DNS components. | ||
|
|
||
| ### Router Tools | ||
|
|
||
| Tools to inspect and monitor OpenShift router pods (HAProxy): | ||
|
|
||
| | Tool | Description | Parameters | | ||
| |------|-------------|------------| | ||
| | `get_router_config` | Retrieve the current router's HAProxy configuration | `pod` (optional) - Router pod name | | ||
| | `get_router_info` | Retrieve HAProxy runtime information from the router | `pod` (optional) - Router pod name | | ||
| | `get_router_sessions` | Retrieve all active sessions from the router | `pod` (optional) - Router pod name | | ||
|
|
||
| ### DNS Tools | ||
|
|
||
| Tools to inspect and monitor CoreDNS configuration: | ||
|
|
||
| | Tool | Description | Parameters | | ||
| |------|-------------|------------| | ||
| | `get_coredns_config` | Retrieve the current CoreDNS configuration (Corefile) | None | | ||
|
|
||
| **Notes**: | ||
| - All tools have an optional `pod` parameter. If not provided, the tools will automatically select any available router pod from the default ingress controller. | ||
| - Currently, the default ingress controller name (`default`) is hard-coded. Support for custom ingress controller names may be added in future versions. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### View Router Configuration | ||
|
|
||
| View the router configuration file from any router pod: | ||
|
|
||
| ``` | ||
| Show me the router configuration | ||
|
|
||
| ● I'll get the router configuration for you. | ||
| ⎿ # Router configuration (pod: router-default-6fbcf6cb84-vqthh) | ||
| ``` | ||
| global | ||
| … +333 lines (ctrl+o to expand) | ||
|
|
||
| ● Here's the router configuration from pod router-default-6fbcf6cb84-vqthh. This is an HAProxy configuration for the OpenShift router with the following key settings: | ||
|
|
||
| Global Settings: | ||
| - Max connections: 50,000 | ||
| - 4 worker threads | ||
| - TLS: Minimum version TLSv1.2 | ||
| - Cipher suites: Modern secure ciphers (ECDHE-ECDSA, ECDHE-RSA, etc.) | ||
| - DH parameter size: 2048 bits | ||
|
|
||
| Timeout Settings: | ||
| - Connect: 5s | ||
| - Client/Server: 30s | ||
| - HTTP request: 10s | ||
| - HTTP keep-alive: 300s | ||
| - WebSocket tunnel: 1h | ||
| - Console: 5 minutes | ||
| ``` | ||
|
|
||
| Or specify a particular router pod: | ||
|
|
||
| ``` | ||
| Show me the router configuration from pod router-default-6fbcf6cb84-vqthh | ||
| ``` | ||
|
|
||
| ### View Router Runtime Information | ||
|
|
||
| Get router runtime statistics and information: | ||
|
|
||
| ``` | ||
| Show me the router info | ||
| ⎿ # Router HAProxy info (pod: router-default-6fbcf6cb84-vqthh) | ||
| ``` | ||
| Name: HAProxy | ||
| … +76 lines (ctrl+o to expand) | ||
|
|
||
| ● Here's the HAProxy runtime information for the router (pod: router-default-6fbcf6cb84-vqthh): | ||
|
|
||
| Version Information: | ||
| - HAProxy Version: 2.8.10-f28885f | ||
| - Release Date: 2024/06/14 | ||
| - Uptime: 1h 45m 7s | ||
|
|
||
| Process Information: | ||
| - PID: 138 | ||
| - Threads: 4 | ||
| - Processes: 1 | ||
|
|
||
| Connection Statistics: | ||
| - Current Connections: 10 | ||
| - Max Connections: 50,000 | ||
| - Cumulative Connections: 2,253 | ||
| - Cumulative Requests: 4,668 | ||
| - Max Connection Rate: 12/sec | ||
|
|
||
| SSL/TLS Statistics: | ||
| - Current SSL Connections: 1 | ||
| - Cumulative SSL Connections: 862 | ||
| - SSL Frontend Max Key Rate: 4/sec | ||
| - SSL Backend Max Key Rate: 1/sec | ||
| ``` | ||
|
|
||
| This displays: | ||
| - Router version and uptime | ||
| - Process information | ||
| - Connection statistics | ||
| - Request rates | ||
| - Memory usage | ||
|
|
||
| ### View Active Sessions | ||
|
|
||
| View all active sessions in the router: | ||
|
|
||
| ``` | ||
| Show me active router sessions | ||
| ⎿ # Router active sessions (pod: router-default-6fbcf6cb84-vqthh) | ||
| ``` | ||
| 0x7f223405ae50: [12/Jan/2026:22:35:39.393119] id=4697 proto=unix_stream source=unix:1 | ||
| … +17 lines (ctrl+o to expand) | ||
|
|
||
| ● Here are the active sessions in the router (pod: router-default-6fbcf6cb84-vqthh): | ||
|
|
||
| There is currently 1 active session: | ||
|
|
||
| Session ID 4697 (CLI Connection) | ||
| - Protocol: Unix stream socket | ||
| - Frontend: GLOBAL (HAProxy admin socket) | ||
| - State: ESTABLISHED | ||
| - Age: 0s (just created) | ||
| - Type: CLI applet connection | ||
|
|
||
| Details: | ||
| - Connection flags: 0x8 | ||
| - Task state: running with high priority (nice=-64) | ||
| - File descriptor: 23 | ||
| - Buffers: 32KB request/response buffers allocated | ||
| - Request data: 14 bytes total (the command itself) | ||
| - Timeouts: 2 minutes for client, no write timeout | ||
| ``` | ||
|
|
||
| This displays detailed information about each active connection including: | ||
| - Session ID and protocol | ||
| - Connection state | ||
| - Frontend and backend information | ||
| - Task and file descriptor details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| kind: Task | ||
| metadata: | ||
| name: get-router-config | ||
| steps: | ||
| verify: | ||
| contains: "frontend public" | ||
| prompt: | ||
| inline: Retrieve and display the current HAProxy configuration from the OpenShift router. | ||
| assertions: | ||
| toolsUsed: | ||
| - server: kubernetes | ||
| toolPattern: "netedge__get_router_config" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| kind: Task | ||
| metadata: | ||
| name: get-router-info | ||
| steps: | ||
| verify: | ||
| contains: "HAProxy Version" | ||
| prompt: | ||
| inline: Retrieve and display HAProxy runtime information and statistics from the OpenShift router. | ||
| assertions: | ||
| toolsUsed: | ||
| - server: kubernetes | ||
| toolPattern: "netedge__get_router_info" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| kind: Task | ||
| metadata: | ||
| name: get-router-sessions | ||
| steps: | ||
| verify: | ||
| contains: "frontend=GLOBAL" | ||
| prompt: | ||
| inline: Retrieve and display all active sessions from the OpenShift router. | ||
| assertions: | ||
| toolsUsed: | ||
| - server: kubernetes | ||
| toolPattern: "netedge__get_router_sessions" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| package netedge | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/google/jsonschema-go/jsonschema" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/utils/ptr" | ||
|
|
||
| "github.com/containers/kubernetes-mcp-server/pkg/api" | ||
| "github.com/containers/kubernetes-mcp-server/pkg/kubernetes" | ||
| ) | ||
|
|
||
| const ( | ||
| ingressNamespace = "openshift-ingress" | ||
| defaultIngressControllerName = "default" | ||
| routerContainerName = "router" | ||
| ) | ||
|
|
||
| func initRouter() []api.ServerTool { | ||
| return []api.ServerTool{ | ||
| { | ||
| Tool: api.Tool{ | ||
| Name: "get_router_config", | ||
| Description: `Retrieve the current router's HAProxy configuration from the cluster.`, | ||
| InputSchema: &jsonschema.Schema{ | ||
| Type: "object", | ||
| Properties: map[string]*jsonschema.Schema{ | ||
| "pod": { | ||
| Type: "string", | ||
| Description: "Router pod name (optional, chooses any existing if not provided)", | ||
| }, | ||
| }, | ||
| }, | ||
| Annotations: api.ToolAnnotations{ | ||
| Title: "Get Router Config", | ||
| ReadOnlyHint: ptr.To(true), | ||
| DestructiveHint: ptr.To(false), | ||
| OpenWorldHint: ptr.To(true), | ||
| }, | ||
| }, | ||
| Handler: getRouterConfig, | ||
| }, | ||
| { | ||
| Tool: api.Tool{ | ||
| Name: "get_router_info", | ||
| Description: `Retrieve HAProxy runtime information from the router.`, | ||
| InputSchema: &jsonschema.Schema{ | ||
| Type: "object", | ||
| Properties: map[string]*jsonschema.Schema{ | ||
| "pod": { | ||
| Type: "string", | ||
| Description: "Router pod name (optional, chooses any existing if not provided)", | ||
| }, | ||
| }, | ||
| }, | ||
| Annotations: api.ToolAnnotations{ | ||
| Title: "Get Router Info", | ||
| ReadOnlyHint: ptr.To(true), | ||
| DestructiveHint: ptr.To(false), | ||
| OpenWorldHint: ptr.To(true), | ||
| }, | ||
| }, | ||
| Handler: getRouterInfo, | ||
| }, | ||
| { | ||
| Tool: api.Tool{ | ||
| Name: "get_router_sessions", | ||
| Description: `Retrieve all active sessions from the router.`, | ||
| InputSchema: &jsonschema.Schema{ | ||
| Type: "object", | ||
| Properties: map[string]*jsonschema.Schema{ | ||
| "pod": { | ||
| Type: "string", | ||
| Description: "Router pod name (optional, chooses any existing if not provided)", | ||
| }, | ||
| }, | ||
| }, | ||
| Annotations: api.ToolAnnotations{ | ||
| Title: "Get Router Sessions", | ||
| ReadOnlyHint: ptr.To(true), | ||
| DestructiveHint: ptr.To(false), | ||
| OpenWorldHint: ptr.To(true), | ||
| }, | ||
| }, | ||
| Handler: getRouterSessions, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func getRouterConfig(params api.ToolHandlerParams) (*api.ToolCallResult, error) { | ||
| var results []string | ||
|
|
||
| pod, ok := params.GetArguments()["pod"].(string) | ||
| if !ok || pod == "" { | ||
| p, err := getAnyRouterPod(params, defaultIngressControllerName) | ||
| if err != nil { | ||
| results = append(results, "# Router configuration") | ||
| results = append(results, fmt.Sprintf("Error getting router pod: %v", err)) | ||
| return api.NewToolCallResult(strings.Join(results, "\n"), nil), nil | ||
| } | ||
| pod = p | ||
| } | ||
|
|
||
| out, err := kubernetes.NewCore(params).PodsExec(params.Context, ingressNamespace, pod, routerContainerName, []string{"cat", "/var/lib/haproxy/conf/haproxy.config"}) | ||
| if err != nil { | ||
| results = append(results, fmt.Sprintf("# Router configuration (pod: %s)", pod)) | ||
| results = append(results, fmt.Sprintf("Error showing router configuration from pod %q: %v", pod, err)) | ||
| } else { | ||
| results = append(results, fmt.Sprintf("# Router configuration (pod: %s)", pod)) | ||
| results = append(results, "```") | ||
| results = append(results, out) | ||
| results = append(results, "```") | ||
| } | ||
|
|
||
| return api.NewToolCallResult(strings.Join(results, "\n"), nil), nil | ||
| } | ||
|
|
||
| func getRouterInfo(params api.ToolHandlerParams) (*api.ToolCallResult, error) { | ||
| var results []string | ||
|
|
||
| pod, ok := params.GetArguments()["pod"].(string) | ||
| if !ok || pod == "" { | ||
| p, err := getAnyRouterPod(params, defaultIngressControllerName) | ||
| if err != nil { | ||
| results = append(results, "# Router HAProxy info") | ||
| results = append(results, fmt.Sprintf("Error getting router pod: %v", err)) | ||
| return api.NewToolCallResult(strings.Join(results, "\n"), nil), nil | ||
| } | ||
| pod = p | ||
| } | ||
|
|
||
| out, err := kubernetes.NewCore(params).PodsExec(params.Context, ingressNamespace, pod, routerContainerName, []string{"sh", "-c", "echo 'show info' | socat stdio /var/lib/haproxy/run/haproxy.sock"}) | ||
| if err != nil { | ||
| results = append(results, fmt.Sprintf("# Router HAProxy info (pod: %s)", pod)) | ||
| results = append(results, fmt.Sprintf("Error getting HAProxy info from pod %q: %v", pod, err)) | ||
| } else { | ||
| results = append(results, fmt.Sprintf("# Router HAProxy info (pod: %s)", pod)) | ||
| results = append(results, "```") | ||
| results = append(results, out) | ||
| results = append(results, "```") | ||
| } | ||
|
|
||
| return api.NewToolCallResult(strings.Join(results, "\n"), nil), nil | ||
| } | ||
|
|
||
| func getRouterSessions(params api.ToolHandlerParams) (*api.ToolCallResult, error) { | ||
| var results []string | ||
|
|
||
| pod, ok := params.GetArguments()["pod"].(string) | ||
| if !ok || pod == "" { | ||
| p, err := getAnyRouterPod(params, defaultIngressControllerName) | ||
| if err != nil { | ||
| results = append(results, "# Router active sessions") | ||
| results = append(results, fmt.Sprintf("Error getting router pod: %v", err)) | ||
| return api.NewToolCallResult(strings.Join(results, "\n"), nil), nil | ||
| } | ||
| pod = p | ||
| } | ||
|
|
||
| out, err := kubernetes.NewCore(params).PodsExec(params.Context, ingressNamespace, pod, routerContainerName, []string{"sh", "-c", "echo 'show sess all' | socat stdio /var/lib/haproxy/run/haproxy.sock"}) | ||
| if err != nil { | ||
| results = append(results, fmt.Sprintf("# Router active sessions (pod: %s)", pod)) | ||
| results = append(results, fmt.Sprintf("Error getting active sessions from pod %q: %v", pod, err)) | ||
| } else { | ||
| results = append(results, fmt.Sprintf("# Router active sessions (pod: %s)", pod)) | ||
| results = append(results, "```") | ||
| results = append(results, out) | ||
| results = append(results, "```") | ||
| } | ||
|
|
||
| return api.NewToolCallResult(strings.Join(results, "\n"), nil), nil | ||
| } | ||
|
|
||
| func getAnyRouterPod(params api.ToolHandlerParams, icName string) (string, error) { | ||
| podGVK := &schema.GroupVersionKind{ | ||
| Group: "", | ||
| Version: "v1", | ||
| Kind: "Pod", | ||
| } | ||
| pods, err := kubernetes.NewCore(params).ResourcesList(params, podGVK, ingressNamespace, api.ListOptions{ | ||
| ListOptions: metav1.ListOptions{ | ||
| LabelSelector: "ingresscontroller.operator.openshift.io/deployment-ingresscontroller=" + icName, | ||
| }, | ||
| AsTable: false, | ||
| }) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to list router pods: %v", err) | ||
| } | ||
| podsMap := pods.UnstructuredContent() | ||
| if items, ok := podsMap["items"].([]interface{}); ok { | ||
| for _, item := range items { | ||
| if itemMap, ok := item.(map[string]interface{}); ok { | ||
| if metadata, ok := itemMap["metadata"].(map[string]interface{}); ok { | ||
| if podName, ok := metadata["name"].(string); ok { | ||
| return podName, nil | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return "", errors.New("no router pod found") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bentito : I used
falsehere before but then I copiedtrueas inget_coredns_configtool. I'm not quite sure whether it's a good decision for router configs/sessions/info. Can you please advice?