Skip to content

Commit 95e6338

Browse files
authored
🌱 Check GolangCI-Lint in Github CI. (#75)
1 parent 0e78c28 commit 95e6338

24 files changed

+228
-225
lines changed

.errcheck_excludes.txt

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Golangci-Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
golangci-lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version-file: go.mod
20+
21+
- name: Run golangci-lint
22+
run: ./hack/golangci-lint.sh

.golangci.yaml

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
---
2-
linters-settings:
3-
errcheck:
4-
exclude: ./.errcheck_excludes.txt
5-
exhaustive:
6-
default-signifies-exhaustive: true
7-
gci:
8-
sections:
9-
- standard
10-
- default
11-
12-
importas:
13-
no-unaliased: true
14-
alias:
15-
# Kubernetes
16-
- pkg: k8s.io/api/core/v1
17-
alias: corev1
18-
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
19-
alias: metav1
20-
21-
misspell:
22-
locale: "US"
23-
1+
version: "2"
242
linters:
25-
disable-all: true
3+
default: standard
264
enable:
275
- bodyclose
6+
- copyloopvar
287
- errcheck
298
- errname
309
- exhaustive
31-
- exportloopref
32-
- gci
3310
- gocritic
3411
- godot
35-
- goimports
3612
- gomodguard
3713
- gosec
38-
- gosimple
3914
- govet
4015
- importas
4116
- ineffassign
4217
- misspell
4318
- prealloc
4419
- revive
4520
- staticcheck
46-
- typecheck
4721
- unparam
4822
- unused
4923
- whitespace
50-
51-
issues:
52-
exclude-rules:
53-
- path: (_test\.go|testing\.go|testsupport|e2etests)
54-
linters:
55-
- gosec
56-
- errcheck
57-
- path: internal/mocks
58-
linters:
59-
- unparam
24+
settings:
25+
exhaustive:
26+
default-signifies-exhaustive: true
27+
importas:
28+
alias:
29+
- pkg: k8s.io/api/core/v1
30+
alias: corev1
31+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
32+
alias: metav1
33+
no-unaliased: true
34+
misspell:
35+
locale: US
36+
exclusions:
37+
generated: lax
38+
presets:
39+
- comments
40+
- common-false-positives
41+
- legacy
42+
- std-error-handling
43+
rules:
44+
- linters:
45+
- errcheck
46+
- gosec
47+
path: (_test\.go|testing\.go|testsupport|e2etests)
48+
- linters:
49+
- unparam
50+
path: internal/mocks
51+
formatters:
52+
enable:
53+
- gci
54+
- goimports
55+
settings:
56+
gci:
57+
sections:
58+
- standard
59+
- default

hack/golangci-lint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
exec go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0 run ./...

hcloud/cloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func newHcloudClient(rootDir string) (*hcloud.Client, error) {
117117
klog.V(1).Infof("reading Hetzner Cloud token from directory failed. Will try env var: %s", err.Error())
118118
token = os.Getenv(hcloudTokenENVVar)
119119
if token == "" {
120-
return nil, fmt.Errorf("Either token from directory %q or environment variable %q is required", credentialsDir, hcloudTokenENVVar)
120+
return nil, fmt.Errorf("either token from directory %q or environment variable %q is required", credentialsDir, hcloudTokenENVVar)
121121
}
122122
} else {
123123
klog.V(1).Infof("reading Hetzner Cloud token from %q. The controller will reload the credentials, when the file changes", credentialsDir)

hcloud/cloud_test.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func newTestEnv() testEnv {
6161
client := hcloud.NewClient(
6262
hcloud.WithEndpoint(server.URL),
6363
hcloud.WithToken("jr5g7ZHpPptyhJzZyHw2Pqu4g9gTqDvEceYpngPf79jNZXCeTYQ4uArypFM3nh75"),
64-
hcloud.WithBackoffFunc(func(_ int) time.Duration { return 0 }),
64+
hcloud.WithRetryOpts(hcloud.RetryOpts{BackoffFunc: hcloud.ConstantBackoff(0), MaxRetries: 5}),
6565
// hcloud.WithDebugWriter(os.Stdout),
6666
)
6767
robotClient := hrobot.NewBasicAuthClient("", "")
@@ -84,7 +84,7 @@ func TestNewCloud(t *testing.T) {
8484
"HCLOUD_METRICS_ENABLED", "false",
8585
)
8686
defer resetEnv()
87-
env.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
87+
env.Mux.HandleFunc("/servers", func(w http.ResponseWriter, _ *http.Request) {
8888
json.NewEncoder(w).Encode(
8989
schema.ServerListResponse{
9090
Servers: []schema.Server{},
@@ -135,7 +135,7 @@ func TestNewCloudInvalidToken(t *testing.T) {
135135
"HCLOUD_METRICS_ENABLED", "false",
136136
)
137137
defer resetEnv()
138-
env.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
138+
env.Mux.HandleFunc("/servers", func(w http.ResponseWriter, _ *http.Request) {
139139
w.Header().Set("Content-Type", "application/json")
140140
w.WriteHeader(http.StatusUnauthorized)
141141
json.NewEncoder(w).Encode(
@@ -164,7 +164,7 @@ func TestCloud(t *testing.T) {
164164
"ROBOT_PASSWORD", "pass123",
165165
)
166166
defer resetEnv()
167-
env.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
167+
env.Mux.HandleFunc("/servers", func(w http.ResponseWriter, _ *http.Request) {
168168
json.NewEncoder(w).Encode(
169169
schema.ServerListResponse{
170170
Servers: []schema.Server{
@@ -193,7 +193,7 @@ func TestCloud(t *testing.T) {
193193
},
194194
)
195195
})
196-
env.Mux.HandleFunc("/networks/1", func(w http.ResponseWriter, r *http.Request) {
196+
env.Mux.HandleFunc("/networks/1", func(w http.ResponseWriter, _ *http.Request) {
197197
json.NewEncoder(w).Encode(
198198
schema.NetworkGetResponse{
199199
Network: schema.Network{
@@ -362,7 +362,6 @@ func TestLoadBalancerDefaultsFromEnv(t *testing.T) {
362362
}
363363

364364
for _, c := range cases {
365-
c := c // prevent scopelint from complaining
366365
t.Run(c.name, func(t *testing.T) {
367366
previousEnvVars := map[string]string{}
368367
unsetEnvVars := []string{}
@@ -450,10 +449,7 @@ func Test_updateHcloudCredentials(t *testing.T) {
450449
err = writeCredentials(credentialsDir, token2)
451450
require.NoError(t, err)
452451
start := time.Now()
453-
for {
454-
if credentials.GetHcloudReloadCounter() > oldCounter {
455-
break
456-
}
452+
for credentials.GetHcloudReloadCounter() <= oldCounter {
457453
if time.Since(start) > time.Second*3 {
458454
t.Fatal("timeout waiting for reload")
459455
}
@@ -485,7 +481,7 @@ func Test_EnsureLoadBalancer(t *testing.T) {
485481
mux := http.NewServeMux()
486482
server := httptest.NewServer(mux)
487483

488-
mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
484+
mux.HandleFunc("/servers", func(w http.ResponseWriter, _ *http.Request) {
489485
json.NewEncoder(w).Encode(
490486
schema.ServerListResponse{
491487
Servers: []schema.Server{},
@@ -496,14 +492,14 @@ func Test_EnsureLoadBalancer(t *testing.T) {
496492
ID: 0,
497493
Name: "mylb",
498494
}
499-
mux.HandleFunc("/load_balancers", func(w http.ResponseWriter, r *http.Request) {
495+
mux.HandleFunc("/load_balancers", func(w http.ResponseWriter, _ *http.Request) {
500496
json.NewEncoder(w).Encode(
501497
schema.LoadBalancerListResponse{
502498
LoadBalancers: []schema.LoadBalancer{schemaLB},
503499
},
504500
)
505501
})
506-
mux.HandleFunc("/robot/server", func(w http.ResponseWriter, r *http.Request) {
502+
mux.HandleFunc("/robot/server", func(w http.ResponseWriter, _ *http.Request) {
507503
json.NewEncoder(w).Encode([]models.ServerResponse{
508504
{
509505
Server: models.Server{

hcloud/instances_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ import (
3737
func TestInstances_InstanceExists(t *testing.T) {
3838
env := newTestEnv()
3939
defer env.Teardown()
40-
env.Mux.HandleFunc("/servers/1", func(w http.ResponseWriter, r *http.Request) {
40+
env.Mux.HandleFunc("/servers/1", func(w http.ResponseWriter, _ *http.Request) {
4141
json.NewEncoder(w).Encode(schema.ServerGetResponse{
4242
Server: schema.Server{
4343
ID: 1,
4444
Name: "foobar",
4545
},
4646
})
4747
})
48-
env.Mux.HandleFunc("/servers/2", func(w http.ResponseWriter, r *http.Request) {
48+
env.Mux.HandleFunc("/servers/2", func(w http.ResponseWriter, _ *http.Request) {
4949
w.Header().Set("Content-Type", "application/json")
5050
w.WriteHeader(http.StatusNotFound)
5151
json.NewEncoder(w).Encode(schema.ErrorResponse{Error: schema.Error{Code: string(hcloud.ErrorCodeNotFound)}})
@@ -58,7 +58,7 @@ func TestInstances_InstanceExists(t *testing.T) {
5858
json.NewEncoder(w).Encode(schema.ServerListResponse{Servers: servers})
5959
})
6060

61-
env.Mux.HandleFunc("/robot/server/321", func(w http.ResponseWriter, r *http.Request) {
61+
env.Mux.HandleFunc("/robot/server/321", func(w http.ResponseWriter, _ *http.Request) {
6262
json.NewEncoder(w).Encode(models.ServerResponse{
6363
Server: models.Server{
6464
ServerIP: "123.123.123.123",
@@ -69,13 +69,13 @@ func TestInstances_InstanceExists(t *testing.T) {
6969
})
7070
})
7171

72-
env.Mux.HandleFunc("/robot/server/322", func(w http.ResponseWriter, r *http.Request) {
72+
env.Mux.HandleFunc("/robot/server/322", func(w http.ResponseWriter, _ *http.Request) {
7373
w.Header().Set("Content-Type", "application/json")
7474
w.WriteHeader(http.StatusNotFound)
7575
json.NewEncoder(w).Encode(schema.ErrorResponse{Error: schema.Error{Code: string(models.ErrorCodeServerNotFound)}})
7676
})
7777

78-
env.Mux.HandleFunc("/robot/server", func(w http.ResponseWriter, r *http.Request) {
78+
env.Mux.HandleFunc("/robot/server", func(w http.ResponseWriter, _ *http.Request) {
7979
json.NewEncoder(w).Encode([]models.ServerResponse{
8080
{
8181
Server: models.Server{
@@ -176,7 +176,7 @@ func TestInstances_InstanceExists(t *testing.T) {
176176
func TestInstances_InstanceShutdown(t *testing.T) {
177177
env := newTestEnv()
178178
defer env.Teardown()
179-
env.Mux.HandleFunc("/servers/1", func(w http.ResponseWriter, r *http.Request) {
179+
env.Mux.HandleFunc("/servers/1", func(w http.ResponseWriter, _ *http.Request) {
180180
json.NewEncoder(w).Encode(schema.ServerGetResponse{
181181
Server: schema.Server{
182182
ID: 1,
@@ -185,7 +185,7 @@ func TestInstances_InstanceShutdown(t *testing.T) {
185185
},
186186
})
187187
})
188-
env.Mux.HandleFunc("/servers/2", func(w http.ResponseWriter, r *http.Request) {
188+
env.Mux.HandleFunc("/servers/2", func(w http.ResponseWriter, _ *http.Request) {
189189
json.NewEncoder(w).Encode(schema.ServerGetResponse{
190190
Server: schema.Server{
191191
ID: 2,
@@ -195,7 +195,7 @@ func TestInstances_InstanceShutdown(t *testing.T) {
195195
})
196196
})
197197

198-
env.Mux.HandleFunc("/robot/server/321", func(w http.ResponseWriter, r *http.Request) {
198+
env.Mux.HandleFunc("/robot/server/321", func(w http.ResponseWriter, _ *http.Request) {
199199
json.NewEncoder(w).Encode(models.ServerResponse{
200200
Server: models.Server{
201201
ServerIP: "123.123.123.123",
@@ -253,7 +253,7 @@ func TestInstances_InstanceShutdown(t *testing.T) {
253253
func TestInstances_InstanceMetadata(t *testing.T) {
254254
env := newTestEnv()
255255
defer env.Teardown()
256-
env.Mux.HandleFunc("/servers/1", func(w http.ResponseWriter, r *http.Request) {
256+
env.Mux.HandleFunc("/servers/1", func(w http.ResponseWriter, _ *http.Request) {
257257
json.NewEncoder(w).Encode(schema.ServerGetResponse{
258258
Server: schema.Server{
259259
ID: 1,
@@ -300,7 +300,7 @@ func TestInstances_InstanceMetadata(t *testing.T) {
300300
func TestInstances_InstanceMetadataRobotServer(t *testing.T) {
301301
env := newTestEnv()
302302
defer env.Teardown()
303-
env.Mux.HandleFunc("/robot/server/321", func(w http.ResponseWriter, r *http.Request) {
303+
env.Mux.HandleFunc("/robot/server/321", func(w http.ResponseWriter, _ *http.Request) {
304304
json.NewEncoder(w).Encode(models.ServerResponse{
305305
Server: models.Server{
306306
ServerIP: "123.123.123.123",

0 commit comments

Comments
 (0)