Skip to content

Commit 7601292

Browse files
authored
feat: introduce golangci-lint (#794)
Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
1 parent 47f1e56 commit 7601292

36 files changed

+122
-145
lines changed

.github/workflows/ci.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,20 @@ jobs:
214214
run: make build-${{ matrix.image }}
215215
working-directory: ./
216216

217+
go-lint:
218+
runs-on: ubuntu-latest
219+
steps:
220+
- name: Checkout repository
221+
uses: actions/checkout@v4
222+
223+
- name: Set up Go
224+
uses: actions/setup-go@v5
225+
with:
226+
go-version: "1.24"
227+
cache: true
228+
cache-dependency-path: go/go.sum
229+
- name: golangci-lint
230+
uses: golangci/golangci-lint-action@v8
231+
with:
232+
version: v2.1
233+
working-directory: go

go/.golangci.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "2"
2+
3+
linters:
4+
# Default set of linters.
5+
# The value can be:
6+
# - `standard`: https://golangci-lint.run/docs/linters/#enabled-by-default
7+
# - `all`: enables all linters by default.
8+
# - `none`: disables all linters by default.
9+
# - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`).
10+
# Default: standard
11+
default: standard

go/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.1
134134
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
135135
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
136136
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
137-
GOLANGCI_LINT_VERSION ?= v1.63.4
137+
GOLANGCI_LINT_VERSION ?= v2.4.0
138138

139139
.PHONY: controller-gen
140140
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
@@ -157,7 +157,7 @@ $(ENVTEST): $(LOCALBIN)
157157
.PHONY: golangci-lint
158158
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
159159
$(GOLANGCI_LINT): $(LOCALBIN)
160-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
160+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
161161

162162
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
163163
# $1 - target path with name of binary

go/cli/cmd/kagent/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070
invokeCmd.Flags().BoolVarP(&invokeCfg.Stream, "stream", "S", false, "Stream the response")
7171
invokeCmd.Flags().StringVarP(&invokeCfg.File, "file", "f", "", "File to read the task from")
7272
invokeCmd.Flags().StringVarP(&invokeCfg.URLOverride, "url-override", "u", "", "URL override")
73-
invokeCmd.Flags().MarkHidden("url-override")
73+
invokeCmd.Flags().MarkHidden("url-override") //nolint:errcheck
7474

7575
bugReportCmd := &cobra.Command{
7676
Use: "bug-report",
@@ -123,7 +123,7 @@ func main() {
123123
Long: `Get a kagent resource`,
124124
Run: func(cmd *cobra.Command, args []string) {
125125
fmt.Fprintf(os.Stderr, "No resource type provided\n\n")
126-
cmd.Help()
126+
cmd.Help() //nolint:errcheck
127127
os.Exit(1)
128128
},
129129
}

go/cli/internal/cli/const_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ func TestGetModelProvider(t *testing.T) {
6262
for _, tc := range testCases {
6363
t.Run(tc.name, func(t *testing.T) {
6464
if tc.envVarValue == "" {
65-
os.Unsetenv(KAGENT_DEFAULT_MODEL_PROVIDER)
65+
os.Unsetenv(KAGENT_DEFAULT_MODEL_PROVIDER) //nolint:errcheck
6666
} else {
67-
os.Setenv(KAGENT_DEFAULT_MODEL_PROVIDER, tc.expectedHelmKey)
68-
defer os.Unsetenv(KAGENT_DEFAULT_MODEL_PROVIDER)
67+
os.Setenv(KAGENT_DEFAULT_MODEL_PROVIDER, tc.expectedHelmKey) //nolint:errcheck
68+
defer os.Unsetenv(KAGENT_DEFAULT_MODEL_PROVIDER) //nolint:errcheck
6969
}
7070

7171
result := GetModelProvider()

go/cli/internal/cli/get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func GetAgentCmd(cfg *config.Config, resourceName string) {
4141
return
4242
}
4343
byt, _ := json.MarshalIndent(agent, "", " ")
44-
fmt.Fprintln(os.Stdout, string(byt))
44+
fmt.Fprintln(os.Stdout, string(byt)) //nolint:errcheck
4545
}
4646
}
4747

@@ -70,7 +70,7 @@ func GetSessionCmd(cfg *config.Config, resourceName string) {
7070
return
7171
}
7272
byt, _ := json.MarshalIndent(session, "", " ")
73-
fmt.Fprintln(os.Stdout, string(byt))
73+
fmt.Fprintln(os.Stdout, string(byt)) //nolint:errcheck
7474
}
7575
}
7676

go/cli/internal/cli/install.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ func InstallCmd(ctx context.Context, cfg *config.Config) *PortForward {
7979

8080
// split helmExtraArgs by "--set" to get additional values
8181
extraValues := strings.Split(helmExtraArgs, "--set")
82-
for _, hev := range extraValues {
83-
values = append(values, hev)
84-
}
82+
values = append(values, extraValues...)
8583

8684
// spinner for installation progress
8785
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond)
@@ -119,7 +117,7 @@ func InstallCmd(ctx context.Context, cfg *config.Config) *PortForward {
119117

120118
// Stop the spinner completely before printing the success message
121119
s.Stop()
122-
fmt.Fprintln(os.Stdout, "kagent installed successfully")
120+
fmt.Fprintln(os.Stdout, "kagent installed successfully") //nolint:errcheck
123121

124122
pf, err := NewPortForward(ctx, cfg)
125123
if err != nil {
@@ -146,11 +144,11 @@ func deleteCRDs(ctx context.Context) error {
146144
if out, err := deleteCmd.CombinedOutput(); err != nil {
147145
if !strings.Contains(string(out), "not found") {
148146
errMsg := fmt.Sprintf("Error deleting CRD %s: %s", crd, string(out))
149-
fmt.Fprintln(os.Stderr, errMsg)
147+
fmt.Fprintln(os.Stderr, errMsg) //nolint:errcheck
150148
deleteErrors = append(deleteErrors, errMsg)
151149
}
152150
} else {
153-
fmt.Fprintf(os.Stdout, "Successfully deleted CRD %s\n", crd)
151+
fmt.Fprintf(os.Stdout, "Successfully deleted CRD %s\n", crd) //nolint:errcheck
154152
}
155153
}
156154

@@ -216,5 +214,5 @@ func UninstallCmd(ctx context.Context, cfg *config.Config) {
216214
}
217215

218216
s.Stop()
219-
fmt.Fprintln(os.Stdout, "\nkagent uninstalled successfully")
217+
fmt.Fprintln(os.Stdout, "\nkagent uninstalled successfully") //nolint:errcheck
220218
}

go/cli/internal/cli/invoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ func InvokeCmd(ctx context.Context, cfg *InvokeCfg) {
134134
return
135135
}
136136

137-
fmt.Fprintf(os.Stdout, "%+v\n", string(jsn))
137+
fmt.Fprintf(os.Stdout, "%+v\n", string(jsn)) //nolint:errcheck
138138
}
139139
}

go/cli/internal/cli/utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
var (
16-
ErrServerConnection = fmt.Errorf("Error connecting to server. Please run 'install' command first.")
16+
ErrServerConnection = fmt.Errorf("error connecting to server. Please run 'install' command first")
1717
)
1818

1919
func CheckServerConnection(client *client.ClientSet) error {
@@ -70,7 +70,7 @@ func (p *PortForward) Stop() {
7070
p.cancel()
7171
// This will terminate the kubectl process in case the cancel does not work.
7272
if p.cmd.Process != nil {
73-
p.cmd.Process.Kill()
73+
p.cmd.Process.Kill() //nolint:errcheck
7474
}
7575

7676
// Don't wait for the process - just cancel the context and let it die
@@ -85,15 +85,15 @@ func StreamA2AEvents(ch <-chan protocol.StreamingMessageEvent, verbose bool) {
8585
fmt.Fprintf(os.Stderr, "Error marshaling A2A event: %v\n", err)
8686
continue
8787
}
88-
fmt.Fprintf(os.Stdout, "%+v\n", string(json))
88+
fmt.Fprintf(os.Stdout, "%+v\n", string(json)) //nolint:errcheck
8989
} else {
9090
json, err := event.MarshalJSON()
9191
if err != nil {
9292
fmt.Fprintf(os.Stderr, "Error marshaling A2A event: %v\n", err)
9393
continue
9494
}
95-
fmt.Fprintf(os.Stdout, "%+v\n", string(json))
95+
fmt.Fprintf(os.Stdout, "%+v\n", string(json)) //nolint:errcheck
9696
}
9797
}
98-
fmt.Fprintln(os.Stdout) // Add a newline after streaming is complete
98+
fmt.Fprintln(os.Stdout) //nolint:errcheck // Add a newline after streaming is complete
9999
}

go/cli/internal/cli/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ func VersionCmd(cfg *config.Config) {
2828
versionInfo["backend_version"] = version.KAgentVersion
2929
}
3030

31-
json.NewEncoder(os.Stdout).Encode(versionInfo)
31+
json.NewEncoder(os.Stdout).Encode(versionInfo) //nolint:errcheck
3232
}

0 commit comments

Comments
 (0)