Skip to content

Commit 430fc60

Browse files
committed
update linter to 2.0.2
1 parent 125f4b7 commit 430fc60

File tree

15 files changed

+31
-19
lines changed

15 files changed

+31
-19
lines changed

.github/workflows/golangci-lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ jobs:
1818
- name: golangci-lint
1919
uses: golangci/golangci-lint-action@v6
2020
with:
21-
version: v1.64.8
21+
version: v2.0.2
2222
args: --timeout 5m

CONTRIBUTION.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ In addition to describing test case, you might need to setup some resources in K
6262
For how that could be done check methods such as `createPod` in [main_test.go](./main_test.go).
6363
You can either use `kubectl` command or `client-go` library to create and wait for initialization of resources before foxytest test runner starts.
6464

65+
## Linting
66+
67+
This project uses [golangci-lint](https://golangci-lint.run/) for linting.
68+
Version in use currently is `v2.0.2`.
69+
70+
Once you have installed linter, you can run it with the following command:
71+
72+
```bash
73+
golangci-lint run
74+
```
75+
6576
## Development
6677

6778
You can run the project with automatic reload if you firstly install arelo:

internal/k8s/apps/v1/deployment/list_deployments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func ListDeployments(clientset kubernetes.Interface, namespace string) *mcp.Call
4949
return deployments.Items[i].Namespace < deployments.Items[j].Namespace
5050
})
5151

52-
var contents []interface{} = make([]interface{}, len(deployments.Items))
52+
var contents = make([]interface{}, len(deployments.Items))
5353
for i, deployment := range deployments.Items {
5454
// Calculate age
5555
age := time.Since(deployment.CreationTimestamp.Time)

internal/k8s/core/v1/pod/list_pods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func ListPods(clientset kubernetes.Interface, k8sNamespace string) *mcp.CallTool
2424
return pods.Items[i].Name < pods.Items[j].Name
2525
})
2626

27-
var contents []interface{} = make([]interface{}, len(pods.Items))
27+
var contents = make([]interface{}, len(pods.Items))
2828
for i, pod := range pods.Items {
2929
content, err := content.NewJsonContent(PodInList{
3030
Name: pod.Name,

internal/k8s/core/v1/service/list_services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ListServices(clientset kubernetes.Interface, k8sNamespace string) *mcp.Call
3434
return services.Items[i].Name < services.Items[j].Name
3535
})
3636

37-
var contents []interface{} = make([]interface{}, len(services.Items))
37+
var contents = make([]interface{}, len(services.Items))
3838
for i, service := range services.Items {
3939
serviceContent := ServiceContent{
4040
Name: service.Name,

internal/prompts/namespaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewListNamespacesPrompt(pool k8s.ClientPool) fxctx.Prompt {
5656
ofContextMsg = fmt.Sprintf(", context '%s'", currentContext)
5757
}
5858

59-
var messages []mcp.PromptMessage = make(
59+
var messages = make(
6060
[]mcp.PromptMessage,
6161
len(namespaces.Items)+1,
6262
)

internal/prompts/pods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func NewListPodsPrompt(pool k8s.ClientPool) fxctx.Prompt {
6060
namespaceInMessage = fmt.Sprintf("namespace '%s'", k8sNamespace)
6161
}
6262

63-
var messages []mcp.PromptMessage = make(
63+
var messages = make(
6464
[]mcp.PromptMessage,
6565
len(pods.Items)+1,
6666
)

internal/resources/contexts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewContextsResourceProvider() fxctx.ResourceProvider {
4949
return nil, fmt.Errorf("context not found: %s", name)
5050
}
5151

52-
var contents []interface{} = make([]interface{}, 1)
52+
var contents = make([]interface{}, 1)
5353
contents[0] = &struct {
5454
Uri string `json:"uri"`
5555
Text string `json:"text"`
@@ -85,7 +85,7 @@ func getContextsContent(uri string, cfg api.Config) []interface{} {
8585
}
8686
}
8787

88-
var contents []interface{} = make([]interface{}, allowedContextsCount)
88+
var contents = make([]interface{}, allowedContextsCount)
8989
i := 0
9090

9191
for name, c := range cfg.Contexts {

internal/tools/contexts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func getListContextsToolContent(cfg api.Config, current string) []interface{} {
5656
}
5757
}
5858

59-
var contents []interface{} = make([]interface{}, allowedContextsCount)
59+
var contents = make([]interface{}, allowedContextsCount)
6060
i := 0
6161

6262
for name, c := range cfg.Contexts {

internal/tools/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewListEventsTool(pool k8s.ClientPool) fxctx.Tool {
5959
return errResponse(err)
6060
}
6161

62-
var contents []interface{} = make([]interface{}, len(events.Items))
62+
var contents = make([]interface{}, len(events.Items))
6363
for i, event := range events.Items {
6464
eventInList := EventInList{
6565
Action: event.Action,

internal/tools/list_resources_tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func NewListResourcesTool(pool k8s.ClientPool) fxctx.Tool {
112112
return utils.ErrResponse(err)
113113
}
114114

115-
var contents []interface{} = make([]interface{}, len(unstructured.Items))
115+
var contents = make([]interface{}, len(unstructured.Items))
116116
for i, item := range unstructured.Items {
117117
// we try to list only metadata to avoid too big outputs
118118
metadata, ok := item.Object["metadata"].(map[string]interface{})

internal/tools/namespaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewListNamespacesTool(pool k8s.ClientPool) fxctx.Tool {
4949
return namespace.Items[i].Name < namespace.Items[j].Name
5050
})
5151

52-
var contents []interface{} = make([]interface{}, len(namespace.Items))
52+
var contents = make([]interface{}, len(namespace.Items))
5353
for i, namespace := range namespace.Items {
5454
content, err := NewJsonContent(NamespacesInList{
5555
Name: namespace.Name,

internal/tools/nodes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewListNodesTool(pool k8s.ClientPool) fxctx.Tool {
5151
return nodes.Items[i].Name < nodes.Items[j].Name
5252
})
5353

54-
var contents []interface{} = make([]interface{}, len(nodes.Items))
54+
var contents = make([]interface{}, len(nodes.Items))
5555
for i, ns := range nodes.Items {
5656
// Calculate age
5757
age := time.Since(ns.CreationTimestamp.Time)

internal/tools/pod_exec_cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func cmdExecuter(
115115
}
116116

117117
if len(pod.Spec.Containers) == 0 {
118-
return execResult, fmt.Errorf("Pod %s has no containers", podName)
118+
return execResult, fmt.Errorf("pod %s has no containers", podName)
119119
}
120120

121121
containerName := pod.Spec.Containers[0].Name

main_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12+
"github.com/stretchr/testify/require"
1213
"github.com/strowk/foxy-contexts/pkg/foxytest"
1314
"github.com/strowk/mcp-k8s-go/internal/k8s"
1415

@@ -20,8 +21,8 @@ func TestListContexts(t *testing.T) {
2021
if err != nil {
2122
t.Fatal(err)
2223
}
23-
os.Setenv("KUBECONFIG", "./testdata/k8s_contexts/kubeconfig")
24-
defer os.Unsetenv("KUBECONFIG")
24+
require.NoError(t, os.Setenv("KUBECONFIG", "./testdata/k8s_contexts/kubeconfig"))
25+
defer require.NoError(t, os.Unsetenv("KUBECONFIG"))
2526
ts.WithExecutable("go", []string{"run", "main.go"})
2627
cntrl := foxytest.NewTestRunner(t)
2728
ts.Run(cntrl)
@@ -33,8 +34,8 @@ func TestWithAllowedContexts(t *testing.T) {
3334
if err != nil {
3435
t.Fatal(err)
3536
}
36-
os.Setenv("KUBECONFIG", "./testdata/k8s_contexts/kubeconfig")
37-
defer os.Unsetenv("KUBECONFIG")
37+
require.NoError(t, os.Setenv("KUBECONFIG", "./testdata/k8s_contexts/kubeconfig"))
38+
defer require.NoError(t, os.Unsetenv("KUBECONFIG"))
3839
ts.WithExecutable("go", []string{"run", "main.go", "--allowed-contexts=allowed-ctx"})
3940
cntrl := foxytest.NewTestRunner(t)
4041
ts.Run(cntrl)
@@ -188,7 +189,7 @@ func createK3dCluster(t *testing.T, name string) {
188189
}
189190

190191
func saveKubeconfig(t *testing.T, name string) {
191-
os.Setenv("KUBECONFIG", kubeconfigPath)
192+
require.NoError(t, os.Setenv("KUBECONFIG", kubeconfigPath))
192193

193194
// write kubeconfig to file
194195
data, err := exec.Command("k3d", "kubeconfig", "get", name).Output()

0 commit comments

Comments
 (0)