Skip to content

Commit 82a4ef2

Browse files
Merge pull request containers#41 from matzew/sync-downstream
NO-JIRA: Sync downstream with the latest changes in upstream
2 parents f76474c + 06fd5d4 commit 82a4ef2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3104
-648
lines changed

.snyk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# https://docs.snyk.io/snyk-cli/commands/ignore
44
exclude:
55
global:
6+
- internal/tools/update-readme/main.go
67
- vendor/**
78
- "**/*_test.go"
89
- python/**

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ clean: ## Clean up all build artifacts
4747
rm -rf $(CLEAN_TARGETS)
4848

4949
.PHONY: build
50-
build: clean tidy format ## Build the project
50+
build: clean tidy format lint ## Build the project
5151
go build $(COMMON_BUILD_ARGS) -o $(BINARY_NAME) ./cmd/kubernetes-mcp-server
5252

5353

5454
.PHONY: build-all-platforms
55-
build-all-platforms: clean tidy format ## Build the project for all platforms
55+
build-all-platforms: clean tidy format lint ## Build the project for all platforms
5656
$(foreach os,$(OSES),$(foreach arch,$(ARCHS), \
5757
GOOS=$(os) GOARCH=$(arch) go build $(COMMON_BUILD_ARGS) -o $(BINARY_NAME)-$(os)-$(arch)$(if $(findstring windows,$(os)),.exe,) ./cmd/kubernetes-mcp-server; \
5858
))

README.md

Lines changed: 148 additions & 215 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ go 1.24.1
44

55
require (
66
github.com/BurntSushi/toml v1.5.0
7-
github.com/coreos/go-oidc/v3 v3.15.0
7+
github.com/coreos/go-oidc/v3 v3.16.0
88
github.com/fsnotify/fsnotify v1.9.0
9-
github.com/go-jose/go-jose/v4 v4.1.2
9+
github.com/go-jose/go-jose/v4 v4.1.3
1010
github.com/google/jsonschema-go v0.3.0
11-
github.com/mark3labs/mcp-go v0.40.0
11+
github.com/mark3labs/mcp-go v0.41.1
1212
github.com/pkg/errors v0.9.1
1313
github.com/spf13/afero v1.15.0
1414
github.com/spf13/cobra v1.10.1

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
4848
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
4949
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
5050
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
51-
github.com/coreos/go-oidc/v3 v3.15.0 h1:R6Oz8Z4bqWR7VFQ+sPSvZPQv4x8M+sJkDO5ojgwlyAg=
52-
github.com/coreos/go-oidc/v3 v3.15.0/go.mod h1:HaZ3szPaZ0e4r6ebqvsLWlk2Tn+aejfmrfah6hnSYEU=
51+
github.com/coreos/go-oidc/v3 v3.16.0 h1:qRQUCFstKpXwmEjDQTIbyY/5jF00+asXzSkmkoa/mow=
52+
github.com/coreos/go-oidc/v3 v3.16.0/go.mod h1:wqPbKFrVnE90vty060SB40FCJ8fTHTxSwyXJqZH+sI8=
5353
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
5454
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
5555
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
@@ -99,8 +99,8 @@ github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxI
9999
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
100100
github.com/go-gorp/gorp/v3 v3.1.0 h1:ItKF/Vbuj31dmV4jxA1qblpSwkl9g1typ24xoe70IGs=
101101
github.com/go-gorp/gorp/v3 v3.1.0/go.mod h1:dLEjIyyRNiXvNZ8PSmzpt1GsWAUK8kjVhEpjH8TixEw=
102-
github.com/go-jose/go-jose/v4 v4.1.2 h1:TK/7NqRQZfgAh+Td8AlsrvtPoUyiHh0LqVvokh+1vHI=
103-
github.com/go-jose/go-jose/v4 v4.1.2/go.mod h1:22cg9HWM1pOlnRiY+9cQYJ9XHmya1bYW8OeDM6Ku6Oo=
102+
github.com/go-jose/go-jose/v4 v4.1.3 h1:CVLmWDhDVRa6Mi/IgCgaopNosCaHz7zrMeF9MlZRkrs=
103+
github.com/go-jose/go-jose/v4 v4.1.3/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
104104
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
105105
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
106106
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
@@ -187,8 +187,8 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhn
187187
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
188188
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
189189
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
190-
github.com/mark3labs/mcp-go v0.40.0 h1:M0oqK412OHBKut9JwXSsj4KanSmEKpzoW8TcxoPOkAU=
191-
github.com/mark3labs/mcp-go v0.40.0/go.mod h1:T7tUa2jO6MavG+3P25Oy/jR7iCeJPHImCZHRymCn39g=
190+
github.com/mark3labs/mcp-go v0.41.1 h1:w78eWfiQam2i8ICL7AL0WFiq7KHNJQ6UB53ZVtH4KGA=
191+
github.com/mark3labs/mcp-go v0.41.1/go.mod h1:T7tUa2jO6MavG+3P25Oy/jR7iCeJPHImCZHRymCn39g=
192192
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
193193
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
194194
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=

internal/test/kubernetes.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@ func KubeConfigFake() *clientcmdapi.Config {
88
fakeConfig := clientcmdapi.NewConfig()
99
fakeConfig.Clusters["fake"] = clientcmdapi.NewCluster()
1010
fakeConfig.Clusters["fake"].Server = "https://127.0.0.1:6443"
11-
fakeConfig.Clusters["additional-cluster"] = clientcmdapi.NewCluster()
1211
fakeConfig.AuthInfos["fake"] = clientcmdapi.NewAuthInfo()
13-
fakeConfig.AuthInfos["additional-auth"] = clientcmdapi.NewAuthInfo()
1412
fakeConfig.Contexts["fake-context"] = clientcmdapi.NewContext()
1513
fakeConfig.Contexts["fake-context"].Cluster = "fake"
1614
fakeConfig.Contexts["fake-context"].AuthInfo = "fake"
17-
fakeConfig.Contexts["additional-context"] = clientcmdapi.NewContext()
18-
fakeConfig.Contexts["additional-context"].Cluster = "additional-cluster"
19-
fakeConfig.Contexts["additional-context"].AuthInfo = "additional-auth"
2015
fakeConfig.CurrentContext = "fake-context"
2116
return fakeConfig
2217
}

internal/test/mock_server.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ func (m *MockServer) Kubeconfig() *api.Config {
7373
}
7474

7575
func (m *MockServer) KubeconfigFile(t *testing.T) string {
76-
kubeconfig := filepath.Join(t.TempDir(), "config")
77-
err := clientcmd.WriteToFile(*m.Kubeconfig(), kubeconfig)
76+
return KubeconfigFile(t, m.Kubeconfig())
77+
}
78+
79+
func KubeconfigFile(t *testing.T, kubeconfig *api.Config) string {
80+
kubeconfigFile := filepath.Join(t.TempDir(), "config")
81+
err := clientcmd.WriteToFile(*kubeconfig, kubeconfigFile)
7882
require.NoError(t, err, "Expected no error writing kubeconfig file")
79-
return kubeconfig
83+
return kubeconfigFile
8084
}
8185

8286
func WriteObject(w http.ResponseWriter, obj runtime.Object) {

internal/tools/update-readme/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"maps"
77
"os"
8+
"path/filepath"
89
"slices"
910
"strings"
1011

@@ -25,7 +26,14 @@ func (o *OpenShift) IsOpenShift(ctx context.Context) bool {
2526
var _ internalk8s.Openshift = (*OpenShift)(nil)
2627

2728
func main() {
28-
readme, err := os.ReadFile(os.Args[1])
29+
// Snyk reports false positive unless we flow the args through filepath.Clean and filepath.Localize in this specific order
30+
var err error
31+
localReadmePath := filepath.Clean(os.Args[1])
32+
localReadmePath, err = filepath.Localize(localReadmePath)
33+
if err != nil {
34+
panic(err)
35+
}
36+
readme, err := os.ReadFile(localReadmePath)
2937
if err != nil {
3038
panic(err)
3139
}
@@ -81,7 +89,7 @@ func main() {
8189
toolsetTools.String(),
8290
)
8391

84-
if err := os.WriteFile(os.Args[1], []byte(updated), 0o644); err != nil {
92+
if err := os.WriteFile(localReadmePath, []byte(updated), 0o644); err != nil {
8593
panic(err)
8694
}
8795
}

pkg/api/toolsets.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,29 @@ import (
1010
)
1111

1212
type ServerTool struct {
13-
Tool Tool
14-
Handler ToolHandlerFunc
13+
Tool Tool
14+
Handler ToolHandlerFunc
15+
ClusterAware *bool
16+
TargetListProvider *bool
17+
}
18+
19+
// IsClusterAware indicates whether the tool can accept a "cluster" or "context" parameter
20+
// to operate on a specific Kubernetes cluster context.
21+
// Defaults to true if not explicitly set
22+
func (s *ServerTool) IsClusterAware() bool {
23+
if s.ClusterAware != nil {
24+
return *s.ClusterAware
25+
}
26+
return true
27+
}
28+
29+
// IsTargetListProvider indicates whether the tool is used to provide a list of targets (clusters/contexts)
30+
// Defaults to false if not explicitly set
31+
func (s *ServerTool) IsTargetListProvider() bool {
32+
if s.TargetListProvider != nil {
33+
return *s.TargetListProvider
34+
}
35+
return false
1536
}
1637

1738
type Toolset interface {

pkg/api/toolsets_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package api
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/suite"
7+
"k8s.io/utils/ptr"
8+
)
9+
10+
type ToolsetsSuite struct {
11+
suite.Suite
12+
}
13+
14+
func (s *ToolsetsSuite) TestServerTool() {
15+
s.Run("IsClusterAware", func() {
16+
s.Run("defaults to true", func() {
17+
tool := &ServerTool{}
18+
s.True(tool.IsClusterAware(), "Expected IsClusterAware to be true by default")
19+
})
20+
s.Run("can be set to false", func() {
21+
tool := &ServerTool{ClusterAware: ptr.To(false)}
22+
s.False(tool.IsClusterAware(), "Expected IsClusterAware to be false when set to false")
23+
})
24+
s.Run("can be set to true", func() {
25+
tool := &ServerTool{ClusterAware: ptr.To(true)}
26+
s.True(tool.IsClusterAware(), "Expected IsClusterAware to be true when set to true")
27+
})
28+
})
29+
s.Run("IsTargetListProvider", func() {
30+
s.Run("defaults to false", func() {
31+
tool := &ServerTool{}
32+
s.False(tool.IsTargetListProvider(), "Expected IsTargetListProvider to be false by default")
33+
})
34+
s.Run("can be set to false", func() {
35+
tool := &ServerTool{TargetListProvider: ptr.To(false)}
36+
s.False(tool.IsTargetListProvider(), "Expected IsTargetListProvider to be false when set to false")
37+
})
38+
s.Run("can be set to true", func() {
39+
tool := &ServerTool{TargetListProvider: ptr.To(true)}
40+
s.True(tool.IsTargetListProvider(), "Expected IsTargetListProvider to be true when set to true")
41+
})
42+
})
43+
}
44+
45+
func TestToolsets(t *testing.T) {
46+
suite.Run(t, new(ToolsetsSuite))
47+
}

0 commit comments

Comments
 (0)