Skip to content

Commit 3623677

Browse files
authored
Merge pull request #20 from cloudscale-ch/denis/stricter-linting
Enable stricter linting
2 parents 24f29b8 + c4dd3b1 commit 3623677

32 files changed

+1555
-179
lines changed

.github/workflows/ccm-integration-tests.yml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ permissions:
1919
contents: read
2020

2121
env:
22-
GO_VERSION: 1.22
22+
GO_VERSION: 1.24
2323

2424
jobs:
2525
lint:
@@ -28,6 +28,9 @@ jobs:
2828

2929
steps:
3030
- uses: actions/checkout@v4
31+
with:
32+
persist-credentials: false
33+
3134
- uses: actions/setup-go@v5
3235
with:
3336
go-version: '${{ env.GO_VERSION }}'
@@ -40,11 +43,8 @@ jobs:
4043
~/.cache/go-build
4144
key: lint-${{ hashFiles('go.mod') }}
4245

43-
- name: Install golangci-lint
44-
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
45-
46-
- name: Install staticcheck
47-
run: go install honnef.co/go/tools/cmd/staticcheck@2023.1.6
46+
- name: Install go tools
47+
run: go mod tidy -modfile tool.mod
4848

4949
- name: Run Linter
5050
run: make lint
@@ -63,6 +63,9 @@ jobs:
6363

6464
steps:
6565
- uses: actions/checkout@v4
66+
with:
67+
persist-credentials: false
68+
6669
- uses: actions/setup-go@v5
6770
with:
6871
go-version: '${{ env.GO_VERSION }}'
@@ -76,6 +79,8 @@ jobs:
7679

7780
steps:
7881
- uses: actions/checkout@v4
82+
with:
83+
persist-credentials: false
7984

8085
- name: "Generate Test Matrix"
8186
id: list
@@ -90,6 +95,8 @@ jobs:
9095

9196
steps:
9297
- uses: actions/checkout@v4
98+
with:
99+
persist-credentials: false
93100

94101
- name: Evaluate image name
95102
run: 'helpers/image-from-ref >> $GITHUB_ENV'
@@ -147,6 +154,8 @@ jobs:
147154

148155
steps:
149156
- uses: actions/checkout@v4
157+
with:
158+
persist-credentials: false
150159

151160
- name: Load image
152161
uses: actions/download-artifact@v4
@@ -182,3 +191,28 @@ jobs:
182191
- name: Destroy Test Cluster
183192
if: always()
184193
run: helpers/cleanup
194+
195+
validate-workflows:
196+
name: Validate GitHub Workflows
197+
runs-on: ubuntu-latest
198+
199+
permissions:
200+
contents: read
201+
202+
steps:
203+
- uses: actions/checkout@v4
204+
with:
205+
fetch-depth: 0
206+
persist-credentials: false
207+
208+
- name: Set up Python
209+
uses: actions/setup-python@v5
210+
with:
211+
python-version: '3.13'
212+
213+
- name: Check Workflows
214+
run: |
215+
python -m pip install zizmor --root-user-action=ignore
216+
zizmor .github/workflows/*
217+
env:
218+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.golangci.yml

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,60 @@
1+
version: "2"
2+
13
linters:
2-
disable-all: true
4+
default: all
5+
disable:
6+
- cyclop
7+
- depguard
8+
- err113
9+
- exhaustruct
10+
- forbidigo
11+
- forcetypeassert
12+
- funlen
13+
- gochecknoinits
14+
- gocognit
15+
- goconst
16+
- gocyclo
17+
- gomoddirectives
18+
- ireturn
19+
- maintidx
20+
- mnd
21+
- nestif
22+
- nilnil
23+
- noctx
24+
- nonamedreturns
25+
- revive
26+
- testifylint
27+
- testpackage
28+
- varnamelen
29+
- usestdlibvars
30+
- whitespace
31+
- wsl
32+
settings:
33+
lll:
34+
line-length: 80
35+
tab-width: 4
36+
exclusions:
37+
generated: lax
38+
presets:
39+
- comments
40+
- common-false-positives
41+
- legacy
42+
- std-error-handling
43+
rules:
44+
- linters:
45+
- lll
46+
source: .+LoadBalancer|// http(s)://
47+
paths:
48+
- third_party$
49+
- builtin$
50+
- examples$
51+
52+
formatters:
353
enable:
4-
- errcheck
5-
- exportloopref
6-
- gocritic
754
- gofmt
8-
- gosimple
9-
- govet
10-
- ineffassign
11-
- lll
12-
- makezero
13-
- staticcheck
14-
- unparam
15-
- unused
16-
- wrapcheck
17-
18-
linters-settings:
19-
lll:
20-
line-length: 80
21-
tab-width: 4
22-
23-
issues:
24-
exclude-rules:
25-
- linters:
26-
- lll
27-
source: ".+LoadBalancer|// http(s)://"
55+
exclusions:
56+
generated: lax
57+
paths:
58+
- third_party$
59+
- builtin$
60+
- examples$

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.22-alpine AS build
1+
FROM golang:1.24-alpine AS build
22
ARG VERSION
33

44
RUN apk add --no-cache git

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ build:
55
cmd/cloudscale-cloud-controller-manager/main.go
66

77
lint:
8-
golangci-lint run --timeout=10m
9-
staticcheck ./...
8+
go tool -modfile tool.mod golangci-lint run --timeout=10m --show-stats=false
9+
go tool -modfile tool.mod staticcheck ./...
1010

1111
test:
1212
go test -race -v \

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/cloudscale-ch/cloudscale-cloud-controller-manager
22

3-
go 1.22
3+
go 1.24
44

55
// https://github.com/kubernetes/apiserver/issues/97
66
replace github.com/google/cel-go => github.com/google/cel-go v0.17.7
@@ -18,8 +18,8 @@ require (
1818
github.com/cloudscale-ch/cloudscale-go-sdk/v4 v4.0.0
1919
github.com/google/uuid v1.5.0
2020
github.com/stretchr/testify v1.8.4
21-
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
2221
k8s.io/client-go v0.29.0
22+
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
2323
)
2424

2525
require (
@@ -86,6 +86,7 @@ require (
8686
go.uber.org/multierr v1.11.0 // indirect
8787
go.uber.org/zap v1.26.0 // indirect
8888
golang.org/x/crypto v0.17.0 // indirect
89+
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
8990
golang.org/x/net v0.19.0 // indirect
9091
golang.org/x/sync v0.6.0 // indirect
9192
golang.org/x/sys v0.16.0 // indirect
@@ -107,7 +108,6 @@ require (
107108
k8s.io/controller-manager v0.29.0 // indirect
108109
k8s.io/kms v0.29.0 // indirect
109110
k8s.io/kube-openapi v0.0.0-20240105020646-a37d4de58910 // indirect
110-
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
111111
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 // indirect
112112
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
113113
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect

pkg/cloudscale_ccm/cloud.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,45 @@ import (
1919

2020
const (
2121
// Under no circumstances can this string change. It is for eternity.
22-
ProviderName = "cloudscale"
22+
ProviderName = "cloudscale"
23+
24+
// #nosec G101
2325
AccessToken = "CLOUDSCALE_ACCESS_TOKEN"
2426
ApiUrl = "CLOUDSCALE_API_URL"
2527
ApiTimeout = "CLOUDSCALE_API_TIMEOUT"
2628
DefaultTimeout = time.Duration(20) * time.Second
2729
)
2830

29-
// cloud implements cloudprovider.Interface
31+
// cloud implements cloudprovider.Interface.
3032
type cloud struct {
3133
instances *instances
3234
loadbalancer *loadbalancer
3335
}
3436

35-
// Register this provider with Kubernetes
37+
// Register this provider with Kubernetes.
3638
func init() {
3739
cloudprovider.RegisterCloudProvider(ProviderName, newCloudscaleProvider)
3840
}
3941

40-
// maskAccessToken returns the given token with most of the information hidden
42+
// maskAccessToken returns the given token with most of the information hidden.
4143
func maskAccessToken(token string) string {
4244
if len(token) < 4 {
4345
return ""
4446
}
47+
4548
return fmt.Sprintf("%.4s%s", token, strings.Repeat("*", len(token)-4))
4649
}
4750

48-
// apiTimeout returns the configured timeout or the default one
51+
// apiTimeout returns the configured timeout or the default one.
4952
func apiTimeout() time.Duration {
5053
if seconds, _ := strconv.Atoi(os.Getenv(ApiTimeout)); seconds > 0 {
5154
return time.Duration(seconds) * time.Second
5255
}
56+
5357
return DefaultTimeout
5458
}
5559

56-
// newCloudscaleProvider creates the provider, ready to be registered
60+
// newCloudscaleProvider creates the provider, ready to be registered.
5761
func newCloudscaleProvider(config io.Reader) (cloudprovider.Interface, error) {
5862
if config != nil {
5963
klog.Warning("--cloud-config received but ignored")
@@ -77,7 +81,7 @@ func newCloudscaleProvider(config io.Reader) (cloudprovider.Interface, error) {
7781
}, nil
7882
}
7983

80-
// newCloudscaleClient spawns a new cloudscale API client
84+
// newCloudscaleClient spawns a new cloudscale API client.
8185
func newCloudscaleClient(
8286
token string, timeout time.Duration) *cloudscale.Client {
8387

@@ -159,7 +163,7 @@ func (c *cloud) ProviderName() string {
159163
return ProviderName
160164
}
161165

162-
// HasClusterID returns true if a ClusterID is required and set
166+
// HasClusterID returns true if a ClusterID is required and set.
163167
func (c *cloud) HasClusterID() bool {
164168
return false
165169
}

pkg/cloudscale_ccm/cloud_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cloudscale_ccm
22

33
import (
44
"errors"
5-
"os"
65
"testing"
76
"testing/iotest"
87
"time"
@@ -11,6 +10,7 @@ import (
1110
)
1211

1312
func TestMaskAccessToken(t *testing.T) {
13+
t.Parallel()
1414

1515
assertMasked := func(input string, expected string) {
1616
assert.Equal(t, expected, maskAccessToken(input))
@@ -24,32 +24,38 @@ func TestMaskAccessToken(t *testing.T) {
2424
}
2525

2626
func TestNewCloudscaleProviderWithoutToken(t *testing.T) {
27+
t.Parallel()
28+
2729
if _, err := newCloudscaleProvider(nil); err == nil {
2830
t.Error("no token in env: newCloudscaleProvider should have failed")
2931
}
3032
}
3133

3234
func TestNewCloudscaleProviderWithToken(t *testing.T) {
33-
os.Setenv(AccessToken, "1234")
35+
t.Setenv(AccessToken, "1234")
3436
if _, err := newCloudscaleProvider(nil); err != nil {
3537
t.Error("newCloudscaleProvider should initialize with just a token")
3638
}
3739
}
3840

3941
func TestNewCloudscaleProviderWithBadConfig(t *testing.T) {
42+
t.Setenv(AccessToken, "1234")
43+
4044
cfg := iotest.ErrReader(errors.New("bad config"))
4145
if _, err := newCloudscaleProvider(cfg); err != nil {
4246
t.Error("newCloudscaleProvider should ignore the config file")
4347
}
4448
}
4549

4650
func TestDefaultTimeout(t *testing.T) {
51+
t.Parallel()
52+
4753
timeout := apiTimeout()
4854
assert.Equal(t, timeout, 20*time.Second)
4955
}
5056

5157
func TestCustomTimeout(t *testing.T) {
52-
os.Setenv(ApiTimeout, "5")
58+
t.Setenv(ApiTimeout, "5")
5359
timeout := apiTimeout()
5460
assert.Equal(t, timeout, 5*time.Second)
5561
}

pkg/cloudscale_ccm/instances.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (i *instances) InstanceExists(ctx context.Context, node *v1.Node) (
4444
"Node", node.Name,
4545
"ProviderID", node.Spec.ProviderID,
4646
)
47+
4748
return false, nil
4849
}
4950

@@ -52,6 +53,7 @@ func (i *instances) InstanceExists(ctx context.Context, node *v1.Node) (
5253
"Node", node.Name,
5354
"ProviderID", node.Spec.ProviderID,
5455
)
56+
5557
return true, nil
5658
}
5759

@@ -77,6 +79,7 @@ func (i *instances) InstanceShutdown(ctx context.Context, node *v1.Node) (
7779
"ProviderID", node.Spec.ProviderID,
7880
"Server.Status", server.Status,
7981
)
82+
8083
return server.Status == "stopped", nil
8184
}
8285

0 commit comments

Comments
 (0)