Skip to content

Commit

Permalink
Update to go-1.23, satisfy linter (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Sep 9, 2024
1 parent 516176c commit 4d0fcf2
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 118 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go 1.22
uses: actions/setup-go@v4
- name: Set up Go 1.23
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"
cache: false

- name: make ipxe
run: |
make ipxe
- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
args: -p bugs -p unused --timeout=3m

Expand All @@ -49,7 +53,7 @@ jobs:
[ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true
- name: Build and push image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
push: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# be aware that bookworm has a newer gcc which can not compile the older ipxe
FROM golang:1.22-bullseye as builder
FROM golang:1.23-bullseye as builder
WORKDIR /work
COPY . .
RUN apt update \
&& apt install --yes --no-install-recommends \
liblzma-dev \
&& make ipxe pixie

FROM alpine:3.19
FROM alpine:3.20
RUN apk -U add ca-certificates
COPY --from=builder /work/build/pixie /pixie
ENTRYPOINT ["/pixie"]
8 changes: 4 additions & 4 deletions dhcp4/conn_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newLinuxConn(port int) (conn, error) {
// Get UDP dport
bpf.LoadIndirect{Off: 2, Size: 2},
// Correct dport?
bpf.JumpIf{Cond: bpf.JumpEqual, Val: uint32(port), SkipFalse: 1},
bpf.JumpIf{Cond: bpf.JumpEqual, Val: uint32(port), SkipFalse: 1}, // nolint:gosec
// Accept
bpf.RetConstant{Val: 1500},
// Ignore
Expand Down Expand Up @@ -81,7 +81,7 @@ func newLinuxConn(port int) (conn, error) {
}

ret := &linuxConn{
port: uint16(port),
port: uint16(port), // nolint:gosec
conn: r,
}
return ret, nil
Expand All @@ -108,9 +108,9 @@ func (c *linuxConn) Send(b []byte, addr *net.UDPAddr, ifidx int) error {
// src port
binary.BigEndian.PutUint16(raw[:2], c.port)
// dst port
binary.BigEndian.PutUint16(raw[2:4], uint16(addr.Port))
binary.BigEndian.PutUint16(raw[2:4], uint16(addr.Port)) // nolint:gosec
// length
binary.BigEndian.PutUint16(raw[4:6], uint16(8+len(b)))
binary.BigEndian.PutUint16(raw[4:6], uint16(8+len(b))) // nolint:gosec
copy(raw[8:], b)

hdr := ipv4.Header{
Expand Down
4 changes: 2 additions & 2 deletions dhcp4/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (o Options) Copy() Options {
func (o Options) marshalLimited(w io.Writer, nBytes int, skip52 bool) (Options, error) {
ks := make([]int, 0, len(o))
for n := range o {
if n <= 0 || n >= 255 {
if n <= 0 || n >= 255 { // nolint:staticcheck
return nil, fmt.Errorf("invalid DHCP option number %d", n)
}
ks = append(ks, int(n))
Expand Down Expand Up @@ -250,7 +250,7 @@ func (o Options) Int32(n Option) (int32, error) {
if len(bs) != 4 {
return 0, errOptionWrongSize
}
return int32(binary.BigEndian.Uint32(bs)), nil
return int32(binary.BigEndian.Uint32(bs)), nil // nolint:gosec
}

// IPs returns the value of option n as a list of IPv4 addresses.
Expand Down
2 changes: 1 addition & 1 deletion dhcp6/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Option struct {

// MakeOption creates an Option with given ID and value
func MakeOption(id uint16, value []byte) *Option {
return &Option{ID: id, Length: uint16(len(value)), Value: value}
return &Option{ID: id, Length: uint16(len(value)), Value: value} // nolint:gosec
}

// Options contains all options of a DHCPv6 packet
Expand Down
4 changes: 2 additions & 2 deletions dhcp6/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestMarshalOption(t *testing.T) {
expectedURL := []byte("http://blah")
expectedLength := uint16(len(expectedURL))
expectedLength := uint16(len(expectedURL)) // nolint:gosec
opt := &Option{ID: OptBootfileURL, Length: expectedLength, Value: expectedURL}

marshalled, err := opt.Marshal()
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestMakeStatusOption(t *testing.T) {
if noAddrOption.ID != OptStatusCode {
t.Fatalf("Expected option id %d, got %d", OptStatusCode, noAddrOption.ID)
}
if noAddrOption.Length != uint16(2+len(expectedMessage)) {
if noAddrOption.Length != uint16(2+len(expectedMessage)) { // nolint:gosec
t.Fatalf("Expected option length of %d, got %d", 2+len(expectedMessage), noAddrOption.Length)
}
if binary.BigEndian.Uint16(noAddrOption.Value[0:2]) != expectedStatusCode {
Expand Down
6 changes: 3 additions & 3 deletions dhcp6/packet_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dhcp6

import (
"encoding/binary"
"fmt"
"errors"
"net"
"testing"
)
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestMakeNoAddrsAvailable(t *testing.T) {

builder := MakePacketBuilder(90, 100)

msg := builder.makeMsgAdvertiseWithNoAddrsAvailable(transactionID, expectedServerID, expectedClientID, fmt.Errorf(expectedMessage))
msg := builder.makeMsgAdvertiseWithNoAddrsAvailable(transactionID, expectedServerID, expectedClientID, errors.New(expectedMessage))

if msg.Type != MsgAdvertise {
t.Fatalf("Expected message type %d, got %d", MsgAdvertise, msg.Type)
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestMakeMsgReplyWithNoAddrsAvailable(t *testing.T) {

msg := builder.makeMsgReply(transactionID, expectedServerID, expectedClientID, 0x10,
[]*IdentityAssociation{identityAssociation}, [][]byte{[]byte("id-2")}, expectedBootFileURL, []net.IP{},
fmt.Errorf(expectedErrorMessage))
errors.New(expectedErrorMessage))

iaNaOption := msg.Options[OptIaNa]
if iaNaOption == nil {
Expand Down
20 changes: 10 additions & 10 deletions dhcp6/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func TestShouldDiscardSolicitWithoutBootfileUrlOption(t *testing.T) {
clientID := []byte("clientid")
options := make(Options)
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID})
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID}) // nolint:gosec
solicit := &Packet{Type: MsgSolicit, TransactionID: [3]byte{'1', '2', '3'}, Options: options}

if err := shouldDiscardSolicit(solicit); err == nil {
Expand All @@ -31,8 +31,8 @@ func TestShouldDiscardSolicitWithServerIdOption(t *testing.T) {
clientID := []byte("clientid")
options := make(Options)
options.Add(MakeOptionRequestOptions([]uint16{OptBootfileURL}))
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID})
options.Add(&Option{ID: OptServerID, Length: uint16(len(serverID)), Value: serverID})
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID}) // nolint:gosec
options.Add(&Option{ID: OptServerID, Length: uint16(len(serverID)), Value: serverID}) // nolint:gosec
solicit := &Packet{Type: MsgSolicit, TransactionID: [3]byte{'1', '2', '3'}, Options: options}

if err := shouldDiscardSolicit(solicit); err == nil {
Expand All @@ -44,8 +44,8 @@ func TestShouldDiscardRequestWithoutBootfileUrlOption(t *testing.T) {
serverID := []byte("serverid")
clientID := []byte("clientid")
options := make(Options)
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID})
options.Add(&Option{ID: OptServerID, Length: uint16(len(serverID)), Value: serverID})
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID}) // nolint:gosec
options.Add(&Option{ID: OptServerID, Length: uint16(len(serverID)), Value: serverID}) // nolint:gosec
request := &Packet{Type: MsgRequest, TransactionID: [3]byte{'1', '2', '3'}, Options: options}

if err := shouldDiscardRequest(request, serverID); err == nil {
Expand All @@ -57,7 +57,7 @@ func TestShouldDiscardRequestWithoutClientIdOption(t *testing.T) {
serverID := []byte("serverid")
options := make(Options)
options.Add(MakeOptionRequestOptions([]uint16{OptBootfileURL}))
options.Add(&Option{ID: OptServerID, Length: uint16(len(serverID)), Value: serverID})
options.Add(&Option{ID: OptServerID, Length: uint16(len(serverID)), Value: serverID}) // nolint:gosec
request := &Packet{Type: MsgRequest, TransactionID: [3]byte{'1', '2', '3'}, Options: options}

if err := shouldDiscardRequest(request, serverID); err == nil {
Expand All @@ -69,7 +69,7 @@ func TestShouldDiscardRequestWithoutServerIdOption(t *testing.T) {
clientID := []byte("clientid")
options := make(Options)
options.Add(MakeOptionRequestOptions([]uint16{OptBootfileURL}))
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID})
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID}) // nolint:gosec
request := &Packet{Type: MsgRequest, TransactionID: [3]byte{'1', '2', '3'}, Options: options}

if err := shouldDiscardRequest(request, []byte("serverid")); err == nil {
Expand All @@ -82,8 +82,8 @@ func TestShouldDiscardRequestWithWrongServerId(t *testing.T) {
serverID := []byte("serverid")
options := make(Options)
options.Add(MakeOptionRequestOptions([]uint16{OptBootfileURL}))
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID})
options.Add(&Option{ID: OptServerID, Length: uint16(len(serverID)), Value: serverID})
options.Add(&Option{ID: OptClientID, Length: uint16(len(clientID)), Value: clientID}) // nolint:gosec
options.Add(&Option{ID: OptServerID, Length: uint16(len(serverID)), Value: serverID}) // nolint:gosec
request := &Packet{Type: MsgRequest, TransactionID: [3]byte{'1', '2', '3'}, Options: options}

if err := shouldDiscardRequest(request, []byte("wrongid")); err == nil {
Expand All @@ -97,5 +97,5 @@ func MakeOptionRequestOptions(options []uint16) *Option {
binary.BigEndian.PutUint16(value[i*2:], option)
}

return &Option{ID: OptOro, Length: uint16(len(options) * 2), Value: value}
return &Option{ID: OptOro, Length: uint16(len(options) * 2), Value: value} // nolint:gosec
}
45 changes: 23 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
module github.com/metal-stack/pixie

go 1.22
go 1.23

require (
github.com/metal-stack/metal-api v0.26.3
github.com/metal-stack/metal-api v0.34.0
github.com/metal-stack/v v1.0.3
github.com/pin/tftp/v3 v3.1.0
github.com/prometheus/client_golang v1.18.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.19.0
golang.org/x/net v0.21.0
google.golang.org/grpc v1.61.0
github.com/prometheus/client_golang v1.20.3
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.27.0
golang.org/x/net v0.29.0
google.golang.org/grpc v1.66.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/protobuf v1.32.0 // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 4d0fcf2

Please sign in to comment.