-
Notifications
You must be signed in to change notification settings - Fork 9
Add node debug tool with tests #38
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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: harche The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold |
/hold cancel |
/hold for fixing CI issues. |
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.
Thanks for working on this @harche
The code looks good overall, left a few comments throughout
I'll test this on an OpenShift cluster tmrw
pkg/toolsets/core/nodes.go
Outdated
internalk8s "github.com/containers/kubernetes-mcp-server/pkg/kubernetes" | ||
) | ||
|
||
func initNodes(_ internalk8s.Openshift) []api.ServerTool { |
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.
Nit: maybe we can drop the internalk8s.Openshift
parameter here since we don't need it? For the initXYZ
methods, there's no requirement on this parameter existing - it seems to be present in only some of them
func initNodes(_ internalk8s.Openshift) []api.ServerTool { | |
func initNodes() []api.ServerTool { |
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.
Addressed, thanks.
pkg/kubernetes/nodes.go
Outdated
// | ||
// When namespace is empty, the configured namespace (or "default" if none) is used. When image is empty the | ||
// default debug image is used. Timeout controls how long we wait for the pod to complete. | ||
func (k *Kubernetes) NodesDebugExec( |
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.
Would it be possible to split this function up a little bit? IMO it is getting quite large and is responsible for too much
Maybe we can create functions that:
- create the debug pod
- poll for debug completion
- Retrieve the logs
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.
Addressed, thanks.
pkg/kubernetes/nodes.go
Outdated
// nodeDebugContainerName is the name used for the debug container, matching oc debug defaults. | ||
nodeDebugContainerName = "debug" | ||
// defaultNodeDebugTimeout is the maximum time to wait for the debug pod to finish executing. | ||
defaultNodeDebugTimeout = 5 * time.Minute |
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.
We may want to lower this timeout as by default this will significantly exceed the client tool call connection timeout: https://github.com/modelcontextprotocol/typescript-sdk/blob/e0de0829019a4eab7af29c05f9a7ec13364f121e/src/shared/protocol.ts#L60
We probably also want to add support for progress notifications to be sent to the client for longer running tool calls like this one (cc @mrunalp @ardaguclu @matzew @manusa )
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.
Reduced to 1 min, thanks.
pkg/kubernetes/nodes.go
Outdated
grace := int64(0) | ||
_ = podsClient.Delete(deleteCtx, created.Name, metav1.DeleteOptions{GracePeriodSeconds: &grace}) |
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.
nit: let's use ptr.To here like we do elsewhere
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.
The refactored file at pkg/ocp/nodes_debug.go, now uses ptr.To
. Thanks.
defaultNodeDebugTimeout = 5 * time.Minute | ||
) | ||
|
||
// NodesDebugExec mimics `oc debug node/<name> -- <command...>` by creating a privileged pod on the target |
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.
Since this is ocp specific;
would it make sense, to group this functionality into some pkg/ocp
package?
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.
File pkg/ocp/nodes_debug.go
is part of ocp
package.
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.
Hold on, I will move everything this PR adds from pkg/kubernetes
to pkg/ocp
so future rebasing avoids the conflicts.
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.
@harche would it be possible to improve the error messages we provide?
When running this server with claude code claude was able to call the tool, but it frequently got errors such as:
⏺ ocp-debug - Nodes: Debug Exec (MCP)(node: "ip-10-0-112-253.us-east-2.compute.internal", command: ["systemctl","status","kubelet"])
⎿ Error: command exited with code 1 (Error)
I'm not sure if there is a way to get more info about what went wrong, but with the current lack of error messages it was hard for the agent to figure out what went wrong and how to fix it
pkg/kubernetes/kubernetes.go
Outdated
type Kubernetes struct { | ||
manager *Manager | ||
manager *Manager | ||
podClientFactory func(namespace string) (corev1client.PodInterface, error) |
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.
Wouldn't these changes in here cause the divergence from upstream?. I think, in this repository we shouldn't allow any changes touching these packages such as kubernetes/, mcp/, etc.
My suggestion is to add first in upstream and simply use it in downstream. Downstream repository should touch only ocp/
directory.
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.
yes, working on it, #38 (comment)
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.
/hold
@harche: all tests passed! Full PR test history. Your PR dashboard. Instructions 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. I understand the commands that are listed here. |
Tested with claude code,