Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Go to v1.22/v1.23, update golangci-lint and fix lint errors #163

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
main:
strategy:
matrix:
go-version: ["1.20", "1.21"]
go-version: ["1.22", "1.23"]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -28,20 +28,20 @@ jobs:
- name: Run static checks
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
with:
version: v1.55.2
version: v1.61.0
args: --config=.golangci.yml --verbose --out-${NO_FUTURE}format colored-line-number
skip-cache: true
- name: Check module tidiness
run: |
go mod tidy -compat=1.20
go mod tidy -compat=1.22
go mod verify
test -z "$(git status --porcelain)" || (echo "please run 'go mod tidy -compat=1.20', and commit your changes"; exit 1)
- name: Run unit tests
run: make test
cmd:
strategy:
matrix:
go-version: ["1.20", "1.21"]
go-version: ["1.22", "1.23"]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -57,13 +57,13 @@ jobs:
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
with:
working-directory: ./cmd
version: v1.55.2
version: v1.61.0
args: --config=../.golangci.yml --verbose --out-${NO_FUTURE}format colored-line-number
skip-cache: true
- name: Check module tidiness
working-directory: ./cmd
run: |
go mod tidy -compat=1.20
go mod tidy -compat=1.22
go mod verify
test -z "$(git status --porcelain)" || (echo "please run 'go mod tidy -compat=1.20', and commit your changes"; exit 1)
- name: Run unit tests
Expand All @@ -72,7 +72,7 @@ jobs:
flow:
strategy:
matrix:
go-version: ["1.20", "1.21"]
go-version: ["1.22", "1.23"]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -88,13 +88,13 @@ jobs:
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
with:
working-directory: ./flow
version: v1.55.2
version: v1.61.0
args: --config=../.golangci.yml --verbose --out-${NO_FUTURE}format colored-line-number
skip-cache: true
- name: Check module tidiness
working-directory: ./flow
run: |
go mod tidy -compat=1.20
go mod tidy -compat=1.22
go mod verify
test -z "$(git status --porcelain)" || (echo "please run 'go mod tidy -compat=1.20', and commit your changes"; exit 1)
- name: Run unit tests
Expand Down
9 changes: 4 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# See https://golangci-lint.run/usage/configuration/ for available options.
# Also https://github.com/cilium/cilium/blob/main/.golangci.yaml as a
# reference.
run:
go: '1.21'
linters:
disable-all: true
enable:
Expand All @@ -12,23 +10,23 @@ linters:
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- err113
- errcheck
- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gocheckcompilerdirectives
- gocognit
- goconst
- gocritic
- godot
- goerr113
- gofmt
- goheader
- goimports
Expand All @@ -39,6 +37,7 @@ linters:
- grouper
- ineffassign
- interfacebloat
- intrange
- makezero
- mirror
- misspell
Expand Down Expand Up @@ -97,7 +96,7 @@ issues:
exclude-rules:
- linters: [errcheck]
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
- linters: [goerr113]
- linters: [err113]
text: "do not define dynamic errors, use wrapped static errors instead"
- linters: [gosec]
text: "G404" # Use of weak random number generator (math/rand instead of crypto/rand)
Expand Down
2 changes: 1 addition & 1 deletion cmd/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cilium/fake/cmd

go 1.20
go 1.22

require (
github.com/cilium/cilium v1.14.5
Expand Down
34 changes: 34 additions & 0 deletions cmd/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/internal/cmd/flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func runFlows(p *printer.Printer) error {
}
}

for i := 0; i < opts.count; i++ {
for i := range opts.count {
// used to get a random node name
idx := rand.Intn(len(nodesIPs))
// add a small amount of jitter to the timestamps so they don't have perfect time gaps
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/cmd/ip/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func runIPs(cmd *cobra.Command) error {
ipOptions = append(ipOptions, fake.WithIPCIDR(opts.cidr))
}

for i := 0; i < opts.count; i++ {
for range opts.count {
fmt.Fprintln(cmd.OutOrStdout(), fake.IP(ipOptions...))
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/cmd/mac/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func New() *cobra.Command {
}

func runMACs(cmd *cobra.Command) error {
for i := 0; i < opts.count; i++ {
for range opts.count {
fmt.Fprintln(cmd.OutOrStdout(), fake.MAC())
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion flow/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import (

// AuthType generates a random AuthType.
func AuthType() flowpb.AuthType {
return flowpb.AuthType(rand.Intn(len(flowpb.AuthType_name)))
return flowpb.AuthType(rand.Intn(len(flowpb.AuthType_name))) //nolint:gosec
}
2 changes: 1 addition & 1 deletion flow/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func Test_DropReason(t *testing.T) {
}

nonDrop, count := 0, 10000
for i := 0; i < count; i++ {
for range count {
if d := DropReason(tt.opts...); d == flowpb.DropReason_DROP_REASON_UNKNOWN {
nonDrop++
}
Expand Down
2 changes: 1 addition & 1 deletion flow/event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ func EventType() *flowpb.CiliumEventType {
return &flowpb.CiliumEventType{
Type: typ,
// NOTE: AgentNotify* are the most numerous.
SubType: int32(rand.Intn(13)),
SubType: int32(rand.Intn(13)), //nolint:gosec
}
}
4 changes: 2 additions & 2 deletions flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ func New(options ...Option) *flowpb.Flow {
SourceService: Service(),
DestinationService: Service(),
TrafficDirection: TrafficDirection(),
PolicyMatchType: uint32(rand.Intn(5)),
PolicyMatchType: uint32(rand.Intn(5)), //nolint:gosec
TraceObservationPoint: TraceObservationPoint(),
DropReasonDesc: opts.dropReason,
IsReply: IsReply(),
TraceContext: tc,
SockXlatePoint: flowpb.SocketTranslationPoint(rand.Intn(len(flowpb.SocketTranslationPoint_name))),
SockXlatePoint: flowpb.SocketTranslationPoint(rand.Intn(len(flowpb.SocketTranslationPoint_name))), //nolint:gosec
SocketCookie: rand.Uint64(),
CgroupId: rand.Uint64(),
// NOTE: don't populate Summary as it is deprecated.
Expand Down
2 changes: 1 addition & 1 deletion flow/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cilium/fake/flow

go 1.20
go 1.22

require (
github.com/cilium/cilium v1.14.5
Expand Down
Loading
Loading