Skip to content

Commit 6b97bef

Browse files
feat: adds linter and resolves issues & creates dedicated PR and main branch pipelines (#38)
* feat: adds linter and adds separate pipelines Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com> * indent Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com> * resolves some lint issues Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com> * Potential fix for code scanning alert no. 8: Workflow does not contain permissions Thank you Mr Bot. Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for code scanning alert no. 11: Workflow does not contain permissions Thank you Mr Bot. Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * removes ci file as deprecated: removes ci actions as deprecated for "run-on-pr.yml" and "run-on-main.yml" Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com> * fix: addresses lint issues Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com> --------- Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 9debeb5 commit 6b97bef

30 files changed

+884
-615
lines changed

.github/workflows/ci.yml renamed to .github/workflows/build.yml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,22 @@
1-
name: CI
1+
name: Build artifacts
22

33
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
4+
workflow_call:
85

9-
jobs:
10-
lint:
11-
name: Lint
12-
runs-on: ubuntu-latest
13-
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@v4
6+
permissions:
7+
contents: read
168

17-
- name: Set up Go
18-
uses: actions/setup-go@v5
19-
with:
20-
go-version-file: 'go.mod'
21-
cache: true
22-
23-
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v8
25-
with:
26-
version: latest
9+
jobs:
2710

2811
build:
2912
name: Build and Test
3013
runs-on: ubuntu-latest
3114
steps:
3215
- name: Checkout code
33-
uses: actions/checkout@v4
16+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
3417

3518
- name: Set up Go
36-
uses: actions/setup-go@v5
19+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5
3720
with:
3821
go-version-file: 'go.mod'
3922
cache: true

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Linting
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5
18+
with:
19+
go-version-file: 'go.mod'
20+
cache: true
21+
22+
- name: Run golangci-lint
23+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
24+
with:
25+
args: --timeout=5m

.github/workflows/run-on-main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# These set of workflows run on every push to the main branch
2+
name: Main build
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches: [ main ]
10+
11+
jobs:
12+
linting:
13+
name: Linting
14+
uses: ./.github/workflows/lint.yml
15+
tests:
16+
name: Tests
17+
uses: ./.github/workflows/test.yml
18+
build:
19+
name: Build
20+
uses: ./.github/workflows/build.yml

.github/workflows/run-on-pr.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# These set of workflows run on every push to the main branch
2+
name: PR Checks
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
10+
jobs:
11+
linting:
12+
name: Linting
13+
uses: ./.github/workflows/lint.yml
14+
tests:
15+
name: Tests
16+
uses: ./.github/workflows/test.yml

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Tests
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5
18+
with:
19+
go-version-file: 'go.mod'
20+
cache: true
21+
22+
- name: Install Task
23+
uses: arduino/setup-task@v2
24+
with:
25+
version: '3.x'
26+
repo-token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Test
29+
run: task test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ Thumbs.db
3232

3333
# Kubeconfig files
3434
kubeconfig
35-
.kubeconfig
35+
.kubeconfig
36+
**/.claude/settings.local.json

.golangci.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
version: "2"
2+
run:
3+
issues-exit-code: 1
4+
output:
5+
formats:
6+
text:
7+
path: stdout
8+
print-linter-name: true
9+
print-issued-lines: true
10+
linters:
11+
default: none
12+
enable:
13+
- depguard
14+
- exhaustive
15+
- goconst
16+
- gocyclo
17+
- gosec
18+
- govet
19+
- ineffassign
20+
- lll
21+
- paralleltest
22+
- promlinter
23+
- revive
24+
- staticcheck
25+
- thelper
26+
- tparallel
27+
- unparam
28+
- unused
29+
settings:
30+
depguard:
31+
rules:
32+
prevent_unmaintained_packages:
33+
list-mode: lax
34+
files:
35+
- $all
36+
- '!$test'
37+
deny:
38+
- pkg: io/ioutil
39+
desc: this is deprecated
40+
gocyclo:
41+
min-complexity: 15
42+
gosec:
43+
excludes:
44+
- G601
45+
lll:
46+
line-length: 130
47+
revive:
48+
severity: warning
49+
rules:
50+
- name: blank-imports
51+
severity: warning
52+
- name: context-as-argument
53+
- name: context-keys-type
54+
- name: duplicated-imports
55+
- name: error-naming
56+
- name: error-return
57+
- name: exported
58+
severity: error
59+
- name: if-return
60+
- name: identical-branches
61+
- name: indent-error-flow
62+
- name: import-shadowing
63+
- name: package-comments
64+
- name: redefines-builtin-id
65+
- name: struct-tag
66+
- name: unconditional-recursion
67+
- name: unnecessary-stmt
68+
- name: unreachable-code
69+
- name: unused-parameter
70+
- name: unused-receiver
71+
- name: unhandled-error
72+
disabled: true
73+
exclusions:
74+
generated: lax
75+
rules:
76+
- linters:
77+
- lll
78+
- gocyclo
79+
- errcheck
80+
- dupl
81+
- gosec
82+
- paralleltest
83+
path: (.+)_test\.go
84+
- linters:
85+
- lll
86+
path: .golangci.yml
87+
paths:
88+
- third_party$
89+
- builtin$
90+
- examples$
91+
formatters:
92+
enable:
93+
- gci
94+
- gofmt
95+
settings:
96+
gci:
97+
sections:
98+
- standard
99+
- default
100+
- prefix(github.com/StacklokLabs/mkp)
101+
exclusions:
102+
generated: lax
103+
paths:
104+
- third_party$
105+
- builtin$
106+
- examples$

Taskfile.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ tasks:
2222
cmds:
2323
- ./{{.BUILD_DIR}}/{{.BINARY_NAME}}
2424

25+
lint:
26+
desc: Run linting tools
27+
cmds:
28+
- golangci-lint run ./...
29+
- go vet ./...
30+
31+
lint-fix:
32+
desc: Run linting tools, and apply fixes.
33+
cmds:
34+
- golangci-lint run --fix ./...
35+
2536
test:
2637
desc: Run tests
2738
cmds:

cmd/server/main.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main provides the entry point for the mkp server application
12
package main
23

34
import (
@@ -17,9 +18,12 @@ func main() {
1718
// Parse command line flags
1819
kubeconfig := flag.String("kubeconfig", "", "Path to kubeconfig file. If not provided, in-cluster config will be used")
1920
addr := flag.String("addr", ":8080", "Address to listen on")
20-
serveResources := flag.Bool("serve-resources", false, "Whether to serve cluster resources as MCP resources. Setting to false can reduce context size for LLMs when working with large clusters")
21-
readWrite := flag.Bool("read-write", false, "Whether to allow write operations on the cluster. When false, the server operates in read-only mode")
22-
kubeconfigRefreshInterval := flag.Duration("kubeconfig-refresh-interval", 0, "Interval to periodically re-read the kubeconfig (e.g., 5m for 5 minutes). If 0, no refresh will be performed")
21+
serveResources := flag.Bool("serve-resources", false,
22+
"Whether to serve cluster resources as MCP resources. Setting to false reduces context size for LLMs with large clusters")
23+
readWrite := flag.Bool("read-write", false,
24+
"Whether to allow write operations on the cluster. When false, the server operates in read-only mode")
25+
kubeconfigRefreshInterval := flag.Duration("kubeconfig-refresh-interval", 0,
26+
"Interval to periodically re-read the kubeconfig (e.g., 5m for 5 minutes). If 0, no refresh will be performed")
2327
flag.Parse()
2428

2529
// Create a context that can be cancelled
@@ -40,7 +44,7 @@ func main() {
4044
if err != nil {
4145
log.Fatalf("Failed to create Kubernetes client: %v", err)
4246
}
43-
47+
4448
// Start periodic refresh if interval is set
4549
if *kubeconfigRefreshInterval > 0 {
4650
log.Printf("Starting periodic kubeconfig refresh every %v", *kubeconfigRefreshInterval)
@@ -66,10 +70,10 @@ func main() {
6670

6771
// Create SSE server
6872
sseServer := mcp.CreateSSEServer(mcpServer)
69-
73+
7074
// Channel to receive server errors
7175
serverErrCh := make(chan error, 1)
72-
76+
7377
// Start the server in a goroutine
7478
go func() {
7579
log.Printf("Starting MCP server on %s", *addr)
@@ -78,19 +82,19 @@ func main() {
7882
serverErrCh <- err
7983
}
8084
}()
81-
85+
8286
// Wait for either a server error or a shutdown signal
8387
select {
8488
case err := <-serverErrCh:
8589
log.Fatalf("Server failed to start: %v", err)
8690
case <-ctx.Done():
8791
log.Println("Shutting down server...")
8892
}
89-
93+
9094
// Create a context with timeout for shutdown
9195
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
9296
defer shutdownCancel()
93-
97+
9498
// Attempt to shut down the server gracefully
9599
shutdownCh := make(chan error, 1)
96100
go func() {
@@ -102,7 +106,7 @@ func main() {
102106
shutdownCh <- err
103107
close(shutdownCh)
104108
}()
105-
109+
106110
// Wait for shutdown to complete or timeout
107111
select {
108112
case err, ok := <-shutdownCh:
@@ -118,7 +122,7 @@ func main() {
118122
// Force exit after timeout
119123
os.Exit(1)
120124
}
121-
125+
122126
log.Println("Server shutdown complete, exiting...")
123127
// Ensure we exit the program
124128
os.Exit(0)

0 commit comments

Comments
 (0)