Skip to content

Commit c3f3217

Browse files
committed
fix: align tests with PR #591 and update to new API from PR #589
Signed-off-by: Rohit Patil <ropatil@redhat.com>
1 parent 75b285a commit c3f3217

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

pkg/mcp/mcp_watch_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ func (s *WatchKubeConfigSuite) TestNotifiesToolsChangeMultipleTimes() {
8383
notification := s.WaitForNotification(5*time.Second, "notifications/tools/list_changed")
8484
// Then
8585
s.NotNil(notification, "WatchKubeConfig did not notify on iteration %d", i)
86-
s.True(
87-
notification.Method == "notifications/tools/list_changed" || notification.Method == "notifications/prompts/list_changed",
88-
"WatchKubeConfig did not notify tools or prompts change on iteration %d, got: %s", i, notification.Method,
89-
)
86+
s.Equalf("notifications/tools/list_changed", notification.Method, "WatchKubeConfig did not notify tools change on iteration %d", i)
9087
}
9188
}
9289

@@ -193,10 +190,7 @@ func (s *WatchClusterStateSuite) TestNotifiesToolsChangeMultipleTimes() {
193190
s.AddAPIGroup(`{"name":"` + name + `.example.com","versions":[{"groupVersion":"` + name + `.example.com/v1","version":"v1"}],"preferredVersion":{"groupVersion":"` + name + `.example.com/v1","version":"v1"}}`)
194191
notification := s.WaitForNotification(5*time.Second, "notifications/tools/list_changed")
195192
s.NotNil(notification, "cluster state watcher did not notify on iteration %d", i)
196-
s.True(
197-
notification.Method == "notifications/tools/list_changed" || notification.Method == "notifications/prompts/list_changed",
198-
"cluster state watcher did not notify tools or prompts change on iteration %d, got: %s", i, notification.Method,
199-
)
193+
s.Equalf("notifications/tools/list_changed", notification.Method, "cluster state watcher did not notify tools change on iteration %d", i)
200194
}
201195
}
202196

pkg/toolsets/core/health_check.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"k8s.io/apimachinery/pkg/runtime/schema"
1010

1111
"github.com/containers/kubernetes-mcp-server/pkg/api"
12+
"github.com/containers/kubernetes-mcp-server/pkg/kubernetes"
1213
)
1314

1415
// clusterHealthCheckHandler implements the cluster health check prompt
@@ -29,7 +30,7 @@ func clusterHealthCheckHandler(params api.PromptHandlerParams) (*api.PromptCallR
2930
Version: "v1",
3031
Kind: "Namespace",
3132
}
32-
_, err := params.ResourcesGet(params, nsGVK, "", namespace)
33+
_, err := kubernetes.NewCore(params).ResourcesGet(params, nsGVK, "", namespace)
3334
if err != nil {
3435
// Namespace doesn't exist - show warning and proceed with cluster-wide check
3536
namespaceWarning = fmt.Sprintf("Namespace '%s' not found or not accessible. Showing cluster-wide information instead.", namespace)
@@ -149,7 +150,7 @@ func gatherClusterDiagnostics(params api.PromptHandlerParams, namespace string,
149150
}
150151

151152
// Count namespaces
152-
namespaceList, err := params.NamespacesList(params, api.ListOptions{})
153+
namespaceList, err := kubernetes.NewCore(params).NamespacesList(params, api.ListOptions{})
153154
if err == nil {
154155
if items, ok := namespaceList.UnstructuredContent()["items"].([]interface{}); ok {
155156
diag.TotalNamespaces = len(items)
@@ -167,7 +168,7 @@ func gatherNodeDiagnostics(params api.PromptHandlerParams) (string, error) {
167168
Kind: "Node",
168169
}
169170

170-
nodeList, err := params.ResourcesList(params, gvk, "", api.ListOptions{})
171+
nodeList, err := kubernetes.NewCore(params).ResourcesList(params, gvk, "", api.ListOptions{})
171172
if err != nil {
172173
return "", err
173174
}
@@ -240,9 +241,9 @@ func gatherPodDiagnostics(params api.PromptHandlerParams, namespace string) (str
240241
var err error
241242

242243
if namespace != "" {
243-
podList, err = params.PodsListInNamespace(params, namespace, api.ListOptions{})
244+
podList, err = kubernetes.NewCore(params).PodsListInNamespace(params, namespace, api.ListOptions{})
244245
} else {
245-
podList, err = params.PodsListInAllNamespaces(params, api.ListOptions{})
246+
podList, err = kubernetes.NewCore(params).PodsListInAllNamespaces(params, api.ListOptions{})
246247
}
247248

248249
if err != nil {
@@ -334,7 +335,7 @@ func gatherWorkloadDiagnostics(params api.PromptHandlerParams, kind string, name
334335
Kind: kind,
335336
}
336337

337-
workloadList, err := params.ResourcesList(params, gvk, namespace, api.ListOptions{})
338+
workloadList, err := kubernetes.NewCore(params).ResourcesList(params, gvk, namespace, api.ListOptions{})
338339
if err != nil {
339340
return "", err
340341
}
@@ -420,7 +421,7 @@ func gatherPVCDiagnostics(params api.PromptHandlerParams, namespace string) (str
420421
Kind: "PersistentVolumeClaim",
421422
}
422423

423-
pvcList, err := params.ResourcesList(params, gvk, namespace, api.ListOptions{})
424+
pvcList, err := kubernetes.NewCore(params).ResourcesList(params, gvk, namespace, api.ListOptions{})
424425
if err != nil {
425426
return "", err
426427
}
@@ -469,7 +470,7 @@ func gatherClusterOperatorDiagnostics(params api.PromptHandlerParams) (string, e
469470
Kind: "ClusterOperator",
470471
}
471472

472-
operatorList, err := params.ResourcesList(params, gvk, "", api.ListOptions{})
473+
operatorList, err := kubernetes.NewCore(params).ResourcesList(params, gvk, "", api.ListOptions{})
473474
if err != nil {
474475
// Not an OpenShift cluster
475476
return "", err
@@ -546,7 +547,7 @@ func gatherEventDiagnostics(params api.PromptHandlerParams, namespace string) (s
546547
namespaces = []string{"default", "kube-system"}
547548

548549
// Add OpenShift namespaces
549-
nsList, err := params.NamespacesList(params, api.ListOptions{})
550+
nsList, err := kubernetes.NewCore(params).NamespacesList(params, api.ListOptions{})
550551
if err == nil {
551552
if items, ok := nsList.UnstructuredContent()["items"].([]interface{}); ok {
552553
for _, item := range items {
@@ -570,7 +571,7 @@ func gatherEventDiagnostics(params api.PromptHandlerParams, namespace string) (s
570571
recentEvents := []string{}
571572

572573
for _, ns := range namespaces {
573-
eventMaps, err := params.EventsList(params, ns)
574+
eventMaps, err := kubernetes.NewCore(params).EventsList(params, ns)
574575
if err != nil {
575576
continue
576577
}

0 commit comments

Comments
 (0)