From 792d2f5b80a10aedb0a12511ff87761b5263f264 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Fri, 26 Sep 2025 06:56:48 +0200 Subject: [PATCH] chore(lint): fix linting issues (#344) * chore(lint): fix linting issues Signed-off-by: Marc Nuri * feat(ci): add linting to build and build-all-platforms target Signed-off-by: Marc Nuri --------- Signed-off-by: Marc Nuri --- Makefile | 4 ++-- pkg/mcp/common_test.go | 2 +- pkg/mcp/mcp.go | 10 +++++----- pkg/mcp/toolsets_test.go | 2 +- pkg/toolsets/core/namespaces.go | 5 ++--- pkg/toolsets/core/resources.go | 3 +-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 02ba932..7f4e427 100644 --- a/Makefile +++ b/Makefile @@ -47,12 +47,12 @@ clean: ## Clean up all build artifacts rm -rf $(CLEAN_TARGETS) .PHONY: build -build: clean tidy format ## Build the project +build: clean tidy format lint ## Build the project go build $(COMMON_BUILD_ARGS) -o $(BINARY_NAME) ./cmd/kubernetes-mcp-server .PHONY: build-all-platforms -build-all-platforms: clean tidy format ## Build the project for all platforms +build-all-platforms: clean tidy format lint ## Build the project for all platforms $(foreach os,$(OSES),$(foreach arch,$(ARCHS), \ GOOS=$(os) GOARCH=$(arch) go build $(COMMON_BUILD_ARGS) -o $(BINARY_NAME)-$(os)-$(arch)$(if $(findstring windows,$(os)),.exe,) ./cmd/kubernetes-mcp-server; \ )) diff --git a/pkg/mcp/common_test.go b/pkg/mcp/common_test.go index 8706489..15f2b56 100644 --- a/pkg/mcp/common_test.go +++ b/pkg/mcp/common_test.go @@ -436,7 +436,7 @@ func (s *BaseMcpSuite) SetupTest() { func (s *BaseMcpSuite) TearDownTest() { if s.McpClient != nil { - s.McpClient.Close() + s.Close() } if s.mcpServer != nil { s.mcpServer.Close() diff --git a/pkg/mcp/mcp.go b/pkg/mcp/mcp.go index c8eca79..95e16ec 100644 --- a/pkg/mcp/mcp.go +++ b/pkg/mcp/mcp.go @@ -48,16 +48,16 @@ func (c *Configuration) ListOutput() output.Output { } func (c *Configuration) isToolApplicable(tool api.ServerTool) bool { - if c.StaticConfig.ReadOnly && !ptr.Deref(tool.Tool.Annotations.ReadOnlyHint, false) { + if c.ReadOnly && !ptr.Deref(tool.Tool.Annotations.ReadOnlyHint, false) { return false } - if c.StaticConfig.DisableDestructive && ptr.Deref(tool.Tool.Annotations.DestructiveHint, false) { + if c.DisableDestructive && ptr.Deref(tool.Tool.Annotations.DestructiveHint, false) { return false } - if c.StaticConfig.EnabledTools != nil && !slices.Contains(c.StaticConfig.EnabledTools, tool.Tool.Name) { + if c.EnabledTools != nil && !slices.Contains(c.EnabledTools, tool.Tool.Name) { return false } - if c.StaticConfig.DisabledTools != nil && slices.Contains(c.StaticConfig.DisabledTools, tool.Tool.Name) { + if c.DisabledTools != nil && slices.Contains(c.DisabledTools, tool.Tool.Name) { return false } return true @@ -79,7 +79,7 @@ func NewServer(configuration Configuration) (*Server, error) { server.WithLogging(), server.WithToolHandlerMiddleware(toolCallLoggingMiddleware), ) - if configuration.StaticConfig.RequireOAuth && false { // TODO: Disabled scope auth validation for now + if configuration.RequireOAuth && false { // TODO: Disabled scope auth validation for now serverOptions = append(serverOptions, server.WithToolHandlerMiddleware(toolScopedAuthorizationMiddleware)) } diff --git a/pkg/mcp/toolsets_test.go b/pkg/mcp/toolsets_test.go index 5f9668a..fa8a95f 100644 --- a/pkg/mcp/toolsets_test.go +++ b/pkg/mcp/toolsets_test.go @@ -29,7 +29,7 @@ func (s *ToolsetsSuite) SetupTest() { s.originalToolsets = toolsets.Toolsets() s.MockServer = test.NewMockServer() s.Cfg = configuration.Default() - s.Cfg.KubeConfig = s.MockServer.KubeconfigFile(s.T()) + s.Cfg.KubeConfig = s.KubeconfigFile(s.T()) } func (s *ToolsetsSuite) TearDownTest() { diff --git a/pkg/toolsets/core/namespaces.go b/pkg/toolsets/core/namespaces.go index 8465007..71995d8 100644 --- a/pkg/toolsets/core/namespaces.go +++ b/pkg/toolsets/core/namespaces.go @@ -8,7 +8,6 @@ import ( "k8s.io/utils/ptr" "github.com/containers/kubernetes-mcp-server/pkg/api" - "github.com/containers/kubernetes-mcp-server/pkg/kubernetes" internalk8s "github.com/containers/kubernetes-mcp-server/pkg/kubernetes" ) @@ -52,7 +51,7 @@ func initNamespaces(o internalk8s.Openshift) []api.ServerTool { } func namespacesList(params api.ToolHandlerParams) (*api.ToolCallResult, error) { - ret, err := params.NamespacesList(params, kubernetes.ResourceListOptions{AsTable: params.ListOutput.AsTable()}) + ret, err := params.NamespacesList(params, internalk8s.ResourceListOptions{AsTable: params.ListOutput.AsTable()}) if err != nil { return api.NewToolCallResult("", fmt.Errorf("failed to list namespaces: %v", err)), nil } @@ -60,7 +59,7 @@ func namespacesList(params api.ToolHandlerParams) (*api.ToolCallResult, error) { } func projectsList(params api.ToolHandlerParams) (*api.ToolCallResult, error) { - ret, err := params.ProjectsList(params, kubernetes.ResourceListOptions{AsTable: params.ListOutput.AsTable()}) + ret, err := params.ProjectsList(params, internalk8s.ResourceListOptions{AsTable: params.ListOutput.AsTable()}) if err != nil { return api.NewToolCallResult("", fmt.Errorf("failed to list projects: %v", err)), nil } diff --git a/pkg/toolsets/core/resources.go b/pkg/toolsets/core/resources.go index 2c14b77..a3536f5 100644 --- a/pkg/toolsets/core/resources.go +++ b/pkg/toolsets/core/resources.go @@ -10,7 +10,6 @@ import ( "k8s.io/utils/ptr" "github.com/containers/kubernetes-mcp-server/pkg/api" - "github.com/containers/kubernetes-mcp-server/pkg/kubernetes" internalk8s "github.com/containers/kubernetes-mcp-server/pkg/kubernetes" "github.com/containers/kubernetes-mcp-server/pkg/output" ) @@ -152,7 +151,7 @@ func resourcesList(params api.ToolHandlerParams) (*api.ToolCallResult, error) { namespace = "" } labelSelector := params.GetArguments()["labelSelector"] - resourceListOptions := kubernetes.ResourceListOptions{ + resourceListOptions := internalk8s.ResourceListOptions{ AsTable: params.ListOutput.AsTable(), }