Skip to content

Commit a291737

Browse files
authored
move to go 1.23 (#141)
* move to go 1.23 * Upgrade linter * fix scanner return in test * Update cmd/flow_capture.go
1 parent 245f6a0 commit a291737

File tree

15 files changed

+93
-76
lines changed

15 files changed

+93
-76
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
go: ['1.21', '1.22']
13+
go: ['1.23']
1414

1515
steps:
1616
- uses: actions/checkout@v3
@@ -27,7 +27,7 @@ jobs:
2727
- name: check clean vendors
2828
run: go mod vendor
2929
- name: Report coverage
30-
if: ${{ matrix.go == '1.22' }}
30+
if: ${{ matrix.go == '1.23' }}
3131
uses: codecov/codecov-action@v4
3232
env:
3333
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/pull_request_e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: set up go 1.x
2424
uses: actions/setup-go@v3
2525
with:
26-
go-version: '1.22'
26+
go-version: '1.23'
2727
- name: checkout
2828
uses: actions/checkout@v3
2929
- name: get kernel version

.github/workflows/push_image.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
go: ['1.22']
18+
go: ['1.23']
1919
steps:
2020
- name: install make
2121
run: sudo apt-get install make
@@ -46,7 +46,7 @@ jobs:
4646
runs-on: ubuntu-latest
4747
strategy:
4848
matrix:
49-
go: ['1.22']
49+
go: ['1.23']
5050
steps:
5151
- name: install make
5252
run: sudo apt-get install make

.github/workflows/push_image_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
go: ['1.22']
19+
go: ['1.23']
2020
steps:
2121
- name: install make
2222
run: sudo apt-get install make

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
go: ['1.22']
17+
go: ['1.23']
1818
steps:
1919
- name: checkout
2020
uses: actions/checkout@v3

.golangci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ linters:
55
- cyclop
66
- errname
77
- exhaustive
8-
- exportloopref
8+
- copyloopvar
99
- gocritic
1010
- gofmt
1111
- gosimple
@@ -16,15 +16,17 @@ linters:
1616
- stylecheck
1717
- typecheck
1818
- unused
19+
run:
20+
go: "1.22"
1921
linters-settings:
20-
stylecheck:
21-
go: "1.22"
2222
gocritic:
2323
enabled-checks:
2424
- hugeParam
2525
- rangeExprCopy
2626
- rangeValCopy
2727
- indexAlloc
28-
- deprecatedComment
28+
settings:
29+
ifElseChain:
30+
minThreshold: 3
2931
cyclop:
30-
max-complexity: 150 # TODO: reduce that to 20
32+
max-complexity: 150 # TODO: reduce that to 20

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ARG TARGETARCH=amd64
33

44
# Build the manager binary
5-
FROM docker.io/library/golang:1.22 as builder
5+
FROM docker.io/library/golang:1.23 as builder
66

77
ARG TARGETARCH
88
ARG LDFLAGS

Dockerfile.downstream

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG COMMIT
66
FROM registry.redhat.io/openshift4/ose-cli-rhel9:v4.17.0-202412032103.p0.g13001b0.assembly.stream.el9 as ose-cli
77

88
# Build the manager binary
9-
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:v1.22.5-202407301806.g4c8b32d.el9 as builder
9+
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:v1.23 as builder
1010

1111
ARG TARGETARCH
1212
ARG TARGETPLATFORM

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ifneq ($(CLEAN_BUILD),)
4747
LDFLAGS ?= -X 'main.buildVersion=${VERSION}-${BUILD_SHA}' -X 'main.buildDate=${BUILD_DATE}'
4848
endif
4949

50-
GOLANGCI_LINT_VERSION = v1.54.2
50+
GOLANGCI_LINT_VERSION = v1.61.0
5151
YQ_VERSION = v4.43.1
5252

5353
# build a single arch target provided as argument

cmd/flow_capture.go

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,38 @@ var (
5858
)
5959

6060
func runFlowCapture(_ *cobra.Command, _ []string) {
61-
go scanner()
61+
go func() {
62+
if !scanner() {
63+
return
64+
}
65+
// scanner returns on exit request
66+
os.Exit(0)
67+
}()
6268

6369
captureType = "Flow"
6470
wg := sync.WaitGroup{}
6571
wg.Add(len(ports))
6672
for i := range ports {
6773
go func(idx int) {
6874
defer wg.Done()
69-
runFlowCaptureOnAddr(ports[idx], nodes[idx])
75+
err := runFlowCaptureOnAddr(ports[idx], nodes[idx])
76+
if err != nil {
77+
// Only fatal errors are returned here
78+
log.Fatal(err)
79+
}
7080
}(i)
7181
}
7282
wg.Wait()
7383
}
7484

75-
func runFlowCaptureOnAddr(port int, filename string) {
85+
func runFlowCaptureOnAddr(port int, filename string) error {
7686
if len(filename) > 0 {
7787
log.Infof("Starting Flow Capture for %s...", filename)
7888
} else {
7989
log.Infof("Starting Flow Capture...")
80-
filename = strings.Replace(
90+
filename = strings.ReplaceAll(
8191
currentTime().UTC().Format(time.RFC3339),
82-
":", "", -1) // get rid of offensive colons
92+
":", "") // get rid of offensive colons
8393
}
8494

8595
var f *os.File
@@ -105,8 +115,7 @@ func runFlowCaptureOnAddr(port int, filename string) {
105115
flowPackets := make(chan *genericmap.Flow, 100)
106116
collector, err := grpc.StartCollector(port, flowPackets)
107117
if err != nil {
108-
log.Error("StartCollector failed:", err.Error())
109-
log.Fatal(err)
118+
return fmt.Errorf("StartCollector failed: %w", err)
110119
}
111120
log.Trace("Started collector")
112121
collectorStarted = true
@@ -128,7 +137,7 @@ func runFlowCaptureOnAddr(port int, filename string) {
128137

129138
if stopReceived {
130139
log.Trace("Stop received")
131-
return
140+
return nil
132141
}
133142
// parse and display flow async
134143
go parseGenericMapAndDisplay(fp.GenericMap.Value)
@@ -145,18 +154,18 @@ func runFlowCaptureOnAddr(port int, filename string) {
145154
// append new line between each record to read file easilly
146155
bytes, err := f.Write(append(fp.GenericMap.Value, []byte(",\n")...))
147156
if err != nil {
148-
log.Fatal(err)
157+
return err
149158
}
150159
if !captureStarted {
151160
log.Trace("Wrote flows to json")
152161
}
153162

154163
// terminate capture if max bytes reached
155-
totalBytes = totalBytes + int64(bytes)
164+
totalBytes += int64(bytes)
156165
if totalBytes > maxBytes {
157166
if exit := onLimitReached(); exit {
158167
log.Infof("Capture reached %s, exiting now...", sizestr.ToString(maxBytes))
159-
return
168+
return nil
160169
}
161170
}
162171

@@ -166,12 +175,13 @@ func runFlowCaptureOnAddr(port int, filename string) {
166175
if int(duration) > int(maxTime) {
167176
if exit := onLimitReached(); exit {
168177
log.Infof("Capture reached %s, exiting now...", maxTime)
169-
return
178+
return nil
170179
}
171180
}
172181

173182
captureStarted = true
174183
}
184+
return nil
175185
}
176186

177187
func parseGenericMapAndDisplay(bytes []byte) {
@@ -202,7 +212,7 @@ func manageFlowsDisplay(genericMap config.GenericMap) {
202212
if len(regexes) > 0 {
203213
// regexes may change during the render so we make a copy first
204214
rCopy := make([]string, len(regexes))
205-
copy(rCopy[:], regexes)
215+
copy(rCopy, regexes)
206216
filtered := []config.GenericMap{}
207217
for _, flow := range lastFlows {
208218
match := true
@@ -380,10 +390,11 @@ func cycleOption(selection []string, exclusiveOptions []string, options []string
380390
return selection
381391
}
382392

383-
func scanner() {
393+
// scanner returns true in case of normal exit (end of program execution) or false in case of error
394+
func scanner() bool {
384395
if err := keyboard.Open(); err != nil {
385396
keyboardError = fmt.Sprintf("Keyboard not supported %v", err)
386-
return
397+
return false
387398
}
388399
defer func() {
389400
_ = keyboard.Close()
@@ -394,26 +405,26 @@ func scanner() {
394405
if err != nil {
395406
panic(err)
396407
}
397-
if key == keyboard.KeyCtrlC || stopReceived {
408+
switch {
409+
case key == keyboard.KeyCtrlC, stopReceived:
398410
log.Info("Ctrl-C pressed, exiting program.")
399-
400411
// exit program
401-
os.Exit(0)
402-
} else if key == keyboard.KeyArrowUp {
403-
flowsToShow = flowsToShow + 1
404-
} else if key == keyboard.KeyArrowDown {
412+
return true
413+
case key == keyboard.KeyArrowUp:
414+
flowsToShow++
415+
case key == keyboard.KeyArrowDown:
405416
if flowsToShow > 10 {
406-
flowsToShow = flowsToShow - 1
417+
flowsToShow--
407418
}
408-
} else if key == keyboard.KeyArrowRight {
419+
case key == keyboard.KeyArrowRight:
409420
display = cycleOption(display, exclusiveDisplays, displays, 1)
410-
} else if key == keyboard.KeyArrowLeft {
421+
case key == keyboard.KeyArrowLeft:
411422
display = cycleOption(display, exclusiveDisplays, displays, -1)
412-
} else if key == keyboard.KeyPgup {
423+
case key == keyboard.KeyPgup:
413424
enrichment = cycleOption(enrichment, exclusiveEnrichments, enrichments, 1)
414-
} else if key == keyboard.KeyPgdn {
425+
case key == keyboard.KeyPgdn:
415426
enrichment = cycleOption(enrichment, exclusiveEnrichments, enrichments, -1)
416-
} else if key == keyboard.KeyBackspace || key == keyboard.KeyBackspace2 {
427+
case key == keyboard.KeyBackspace || key == keyboard.KeyBackspace2:
417428
if len(regexes) > 0 {
418429
lastIndex := len(regexes) - 1
419430
if len(regexes[lastIndex]) > 0 {
@@ -422,14 +433,14 @@ func scanner() {
422433
regexes = regexes[:lastIndex]
423434
}
424435
}
425-
} else if key == keyboard.KeyEnter {
436+
case key == keyboard.KeyEnter:
426437
regexes = append(regexes, "")
427-
} else {
438+
default:
428439
if len(regexes) == 0 {
429440
regexes = []string{string(char)}
430441
} else {
431442
lastIndex := len(regexes) - 1
432-
regexes[lastIndex] = regexes[lastIndex] + string(char)
443+
regexes[lastIndex] += string(char)
433444
}
434445
}
435446
lastRefresh = startupTime

0 commit comments

Comments
 (0)