Add mcp route command for managing mc-proxy routes
New top-level command with list, add, remove subcommands. Supports -n/--node to target a specific node. Adds AddProxyRoute and RemoveProxyRoute RPCs to the agent. Moves route listing from mcp node routes to mcp route list. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,22 @@ func (p *ProxyRouter) GetStatus(ctx context.Context) (*mcproxy.Status, error) {
|
||||
return p.client.GetStatus(ctx)
|
||||
}
|
||||
|
||||
// AddRoute adds a single route to mc-proxy.
|
||||
func (p *ProxyRouter) AddRoute(ctx context.Context, listenerAddr string, route mcproxy.Route) error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("mc-proxy not configured")
|
||||
}
|
||||
return p.client.AddRoute(ctx, listenerAddr, route)
|
||||
}
|
||||
|
||||
// RemoveRoute removes a single route from mc-proxy.
|
||||
func (p *ProxyRouter) RemoveRoute(ctx context.Context, listenerAddr, hostname string) error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("mc-proxy not configured")
|
||||
}
|
||||
return p.client.RemoveRoute(ctx, listenerAddr, hostname)
|
||||
}
|
||||
|
||||
// RegisterRoutes registers all routes for a service component with mc-proxy.
|
||||
// It uses the assigned host ports from the registry.
|
||||
func (p *ProxyRouter) RegisterRoutes(ctx context.Context, serviceName string, routes []registry.Route, hostPorts map[string]int) error {
|
||||
|
||||
@@ -4,7 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.wntrmute.dev/mc/mc-proxy/client/mcproxy"
|
||||
mcpv1 "git.wntrmute.dev/mc/mcp/gen/mcp/v1"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
@@ -44,3 +47,65 @@ func (a *Agent) ListProxyRoutes(ctx context.Context, _ *mcpv1.ListProxyRoutesReq
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// AddProxyRoute adds a route to mc-proxy.
|
||||
func (a *Agent) AddProxyRoute(ctx context.Context, req *mcpv1.AddProxyRouteRequest) (*mcpv1.AddProxyRouteResponse, error) {
|
||||
if req.GetListenerAddr() == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "listener_addr is required")
|
||||
}
|
||||
if req.GetHostname() == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "hostname is required")
|
||||
}
|
||||
if req.GetBackend() == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "backend is required")
|
||||
}
|
||||
|
||||
if a.Proxy == nil {
|
||||
return nil, status.Error(codes.FailedPrecondition, "mc-proxy not configured")
|
||||
}
|
||||
|
||||
route := mcproxy.Route{
|
||||
Hostname: req.GetHostname(),
|
||||
Backend: req.GetBackend(),
|
||||
Mode: req.GetMode(),
|
||||
BackendTLS: req.GetBackendTls(),
|
||||
}
|
||||
|
||||
if err := a.Proxy.AddRoute(ctx, req.GetListenerAddr(), route); err != nil {
|
||||
return nil, fmt.Errorf("add route: %w", err)
|
||||
}
|
||||
|
||||
a.Logger.Info("route added",
|
||||
"listener", req.GetListenerAddr(),
|
||||
"hostname", req.GetHostname(),
|
||||
"backend", req.GetBackend(),
|
||||
"mode", req.GetMode(),
|
||||
)
|
||||
|
||||
return &mcpv1.AddProxyRouteResponse{}, nil
|
||||
}
|
||||
|
||||
// RemoveProxyRoute removes a route from mc-proxy.
|
||||
func (a *Agent) RemoveProxyRoute(ctx context.Context, req *mcpv1.RemoveProxyRouteRequest) (*mcpv1.RemoveProxyRouteResponse, error) {
|
||||
if req.GetListenerAddr() == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "listener_addr is required")
|
||||
}
|
||||
if req.GetHostname() == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "hostname is required")
|
||||
}
|
||||
|
||||
if a.Proxy == nil {
|
||||
return nil, status.Error(codes.FailedPrecondition, "mc-proxy not configured")
|
||||
}
|
||||
|
||||
if err := a.Proxy.RemoveRoute(ctx, req.GetListenerAddr(), req.GetHostname()); err != nil {
|
||||
return nil, fmt.Errorf("remove route: %w", err)
|
||||
}
|
||||
|
||||
a.Logger.Info("route removed",
|
||||
"listener", req.GetListenerAddr(),
|
||||
"hostname", req.GetHostname(),
|
||||
)
|
||||
|
||||
return &mcpv1.RemoveProxyRouteResponse{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user