Skip to content

Commit 8137ae5

Browse files
authored
Migrate to slog and go-1.22 (#51)
1 parent f89d5cf commit 8137ae5

File tree

12 files changed

+299
-649
lines changed

12 files changed

+299
-649
lines changed

.github/workflows/docker.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ jobs:
3131
- name: Checkout
3232
uses: actions/checkout@v4
3333

34-
- name: Set up Go 1.21
35-
uses: actions/setup-go@v4
34+
- name: Set up Go 1.22
35+
uses: actions/setup-go@v5
3636
with:
37-
go-version: '1.21'
37+
go-version: '1.22'
3838
cache: false
3939

4040
- name: Lint
41-
uses: golangci/golangci-lint-action@v3
41+
uses: golangci/golangci-lint-action@v4
4242
with:
4343
args: --build-tags integration -p bugs -p unused --timeout=10m
4444

@@ -63,10 +63,10 @@ jobs:
6363
- name: Checkout
6464
uses: actions/checkout@v4
6565

66-
- name: Set up Go 1.21
67-
uses: actions/setup-go@v4
66+
- name: Set up Go 1.22
67+
uses: actions/setup-go@v5
6868
with:
69-
go-version: '1.21'
69+
go-version: '1.22'
7070

7171
- name: Checkout
7272
run: |

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Build the firewall-controller-manager binary
2-
FROM golang:1.21 as builder
2+
FROM golang:1.22 as builder
33

44
WORKDIR /work
55
COPY . .
66
RUN make
77

8-
FROM alpine:3.18
8+
FROM alpine:3.19
99
COPY --from=builder /work/bin/firewall-controller-manager .
1010
USER 65534
1111
ENTRYPOINT ["/firewall-controller-manager"]

Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.18
1+
FROM alpine:3.19
22
COPY bin/firewall-controller-manager /firewall-controller-manager
33
USER 65534
44
ENTRYPOINT ["/firewall-controller-manager"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GITVERSION := $(shell git describe --long --all)
88
BUILDDATE := $(shell date -Iseconds)
99
VERSION := $(or ${VERSION},$(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD))
1010

11-
CONTROLLER_TOOLS_VERSION ?= v0.11.3
11+
CONTROLLER_TOOLS_VERSION ?= v0.14.0
1212
LOCALBIN ?= $(shell pwd)/bin
1313
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
1414
ENVTEST ?= $(LOCALBIN)/setup-envtest

api/v2/zz_generated.deepcopy.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/logger.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,18 @@ package controllers
22

33
import (
44
"fmt"
5-
6-
"go.uber.org/zap"
7-
"go.uber.org/zap/zapcore"
5+
"log/slog"
6+
"os"
87
)
98

10-
func NewZapLogger(levelString string) (*zap.SugaredLogger, error) {
11-
level, err := zap.ParseAtomicLevel(levelString)
12-
if err != nil {
13-
return nil, fmt.Errorf("unable to parse log level: %w", err)
14-
}
15-
16-
cfg := zap.NewProductionConfig()
17-
cfg.Level = level
18-
cfg.EncoderConfig.TimeKey = "timestamp"
19-
cfg.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
20-
21-
l, err := cfg.Build()
9+
func NewLogger(levelString string) (slog.Handler, error) {
10+
var (
11+
lvlvar slog.LevelVar
12+
)
13+
err := lvlvar.UnmarshalText([]byte(levelString))
2214
if err != nil {
23-
return nil, fmt.Errorf("can't initialize zap logger: %w", err)
15+
return nil, fmt.Errorf("can't initialize logger: %w", err)
2416
}
25-
26-
return l.Sugar(), nil
17+
level := lvlvar.Level()
18+
return slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level}), nil
2719
}

controllers/set/suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/go-logr/zapr"
10+
"github.com/go-logr/logr"
1111
v2 "github.com/metal-stack/firewall-controller-manager/api/v2"
1212
controllerconfig "github.com/metal-stack/firewall-controller-manager/api/v2/config"
1313
"github.com/metal-stack/firewall-controller-manager/controllers"
@@ -46,10 +46,10 @@ func TestAPIs(t *testing.T) {
4646
}
4747

4848
var _ = BeforeSuite(func() {
49-
l, err := controllers.NewZapLogger("debug")
49+
l, err := controllers.NewLogger("debug")
5050
Expect(err).NotTo(HaveOccurred())
5151

52-
ctrl.SetLogger(zapr.NewLogger(l.Desugar()))
52+
ctrl.SetLogger(logr.FromSlogHandler(l))
5353

5454
ctx, cancel = context.WithCancel(context.Background())
5555

go.mod

Lines changed: 81 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,147 @@
11
module github.com/metal-stack/firewall-controller-manager
22

3-
go 1.21
3+
go 1.22
44

55
require (
66
github.com/Masterminds/semver/v3 v3.2.1
77
github.com/flatcar/container-linux-config-transpiler v0.9.4
8-
github.com/go-logr/logr v1.2.4
9-
github.com/go-logr/zapr v1.2.4
10-
github.com/go-openapi/strfmt v0.21.7
8+
github.com/go-logr/logr v1.4.1
9+
github.com/go-openapi/strfmt v0.23.0
1110
github.com/google/go-cmp v0.6.0
12-
github.com/google/uuid v1.3.1
13-
github.com/metal-stack/metal-go v0.24.3
14-
github.com/metal-stack/metal-lib v0.13.5
11+
github.com/google/uuid v1.6.0
12+
github.com/metal-stack/metal-go v0.28.1
13+
github.com/metal-stack/metal-lib v0.15.1
1514
github.com/metal-stack/v v1.0.3
16-
github.com/onsi/ginkgo/v2 v2.13.0
17-
github.com/onsi/gomega v1.28.1
18-
github.com/stretchr/testify v1.8.4
19-
go.uber.org/zap v1.26.0
20-
k8s.io/api v0.26.3
21-
k8s.io/apimachinery v0.27.4
22-
k8s.io/client-go v0.26.3
15+
github.com/onsi/ginkgo/v2 v2.16.0
16+
github.com/onsi/gomega v1.31.1
17+
github.com/stretchr/testify v1.9.0
18+
k8s.io/api v0.28.3
19+
k8s.io/apimachinery v0.28.3
20+
k8s.io/client-go v0.28.3
2321
sigs.k8s.io/controller-runtime v0.14.5
2422
)
2523

24+
replace (
25+
k8s.io/api => k8s.io/api v0.26.3
26+
k8s.io/client-go => k8s.io/client-go v0.26.3
27+
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
28+
)
29+
2630
require (
27-
github.com/Masterminds/goutils v1.1.1 // indirect
28-
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
2931
github.com/ajeddeloh/go-json v0.0.0-20200220154158-5ae607161559 // indirect
3032
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
3133
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
3234
github.com/beorn7/perks v1.0.1 // indirect
3335
github.com/cespare/xxhash/v2 v2.2.0 // indirect
34-
github.com/coreos/go-oidc/v3 v3.6.0 // indirect
36+
github.com/coreos/go-oidc/v3 v3.9.0 // indirect
3537
github.com/coreos/go-semver v0.3.1 // indirect
3638
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
37-
github.com/davecgh/go-spew v1.1.1 // indirect
39+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3840
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
39-
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
41+
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
4042
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
4143
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
42-
github.com/fatih/color v1.15.0 // indirect
44+
github.com/fatih/color v1.16.0 // indirect
4345
github.com/flatcar/ignition v0.36.2 // indirect
44-
github.com/fsnotify/fsnotify v1.6.0 // indirect
45-
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
46+
github.com/fsnotify/fsnotify v1.7.0 // indirect
47+
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
4648
github.com/go-logr/stdr v1.2.2 // indirect
47-
github.com/go-openapi/analysis v0.21.4 // indirect
48-
github.com/go-openapi/errors v0.20.4 // indirect
49-
github.com/go-openapi/jsonpointer v0.20.0 // indirect
50-
github.com/go-openapi/jsonreference v0.20.2 // indirect
51-
github.com/go-openapi/loads v0.21.2 // indirect
52-
github.com/go-openapi/runtime v0.26.0 // indirect
53-
github.com/go-openapi/spec v0.20.9 // indirect
54-
github.com/go-openapi/swag v0.22.4 // indirect
55-
github.com/go-openapi/validate v0.22.1 // indirect
49+
github.com/go-openapi/analysis v0.22.0 // indirect
50+
github.com/go-openapi/errors v0.22.0 // indirect
51+
github.com/go-openapi/jsonpointer v0.20.2 // indirect
52+
github.com/go-openapi/jsonreference v0.20.4 // indirect
53+
github.com/go-openapi/loads v0.21.5 // indirect
54+
github.com/go-openapi/runtime v0.27.1 // indirect
55+
github.com/go-openapi/spec v0.20.14 // indirect
56+
github.com/go-openapi/swag v0.22.9 // indirect
57+
github.com/go-openapi/validate v0.22.6 // indirect
5658
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
59+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
5760
github.com/goccy/go-json v0.10.2 // indirect
58-
github.com/goccy/go-yaml v1.11.0 // indirect
61+
github.com/goccy/go-yaml v1.11.3 // indirect
5962
github.com/gogo/protobuf v1.3.2 // indirect
6063
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
6164
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
6265
github.com/golang/protobuf v1.5.3 // indirect
63-
github.com/google/gnostic v0.6.9 // indirect
66+
github.com/google/gnostic v0.5.7-v3refs // indirect
6467
github.com/google/gofuzz v1.2.0 // indirect
6568
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd // indirect
66-
github.com/gorilla/mux v1.8.0 // indirect
69+
github.com/gorilla/mux v1.8.1 // indirect
6770
github.com/hashicorp/hcl v1.0.0 // indirect
68-
github.com/huandu/xstrings v1.4.0 // indirect
6971
github.com/imdario/mergo v0.3.16 // indirect
7072
github.com/inconshreveable/mousetrap v1.1.0 // indirect
7173
github.com/josharian/intern v1.0.0 // indirect
7274
github.com/json-iterator/go v1.1.12 // indirect
73-
github.com/jszwec/csvutil v1.8.0 // indirect
74-
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
75-
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
75+
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
7676
github.com/lestrrat-go/httpcc v1.0.1 // indirect
77+
github.com/lestrrat-go/httprc v1.0.4 // indirect
7778
github.com/lestrrat-go/iter v1.0.2 // indirect
78-
github.com/lestrrat-go/jwx v1.2.26 // indirect
79+
github.com/lestrrat-go/jwx/v2 v2.0.19 // indirect
7980
github.com/lestrrat-go/option v1.0.1 // indirect
8081
github.com/magiconair/properties v1.8.7 // indirect
8182
github.com/mailru/easyjson v0.7.7 // indirect
8283
github.com/mattn/go-colorable v0.1.13 // indirect
83-
github.com/mattn/go-isatty v0.0.19 // indirect
84+
github.com/mattn/go-isatty v0.0.20 // indirect
8485
github.com/mattn/go-runewidth v0.0.15 // indirect
8586
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
86-
github.com/metal-stack/security v0.6.7 // indirect
87-
github.com/mitchellh/copystructure v1.2.0 // indirect
87+
github.com/metal-stack/security v0.7.2 // indirect
8888
github.com/mitchellh/mapstructure v1.5.0 // indirect
89-
github.com/mitchellh/reflectwalk v1.0.2 // indirect
9089
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
9190
github.com/modern-go/reflect2 v1.0.2 // indirect
9291
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
9392
github.com/oklog/ulid v1.3.1 // indirect
9493
github.com/olekukonko/tablewriter v0.0.5 // indirect
9594
github.com/opentracing/opentracing-go v1.2.0 // indirect
96-
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
95+
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
9796
github.com/pkg/errors v0.9.1 // indirect
98-
github.com/pmezard/go-difflib v1.0.0 // indirect
99-
github.com/prometheus/client_golang v1.14.0 // indirect
100-
github.com/prometheus/client_model v0.3.0 // indirect
101-
github.com/prometheus/common v0.42.0 // indirect
102-
github.com/prometheus/procfs v0.9.0 // indirect
97+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
98+
github.com/prometheus/client_golang v1.16.0 // indirect
99+
github.com/prometheus/client_model v0.4.0 // indirect
100+
github.com/prometheus/common v0.44.0 // indirect
101+
github.com/prometheus/procfs v0.10.1 // indirect
103102
github.com/rivo/uniseg v0.4.4 // indirect
104-
github.com/shopspring/decimal v1.3.1 // indirect
105-
github.com/spf13/afero v1.9.5 // indirect
106-
github.com/spf13/cast v1.5.1 // indirect
107-
github.com/spf13/cobra v1.7.0 // indirect
108-
github.com/spf13/jwalterweatherman v1.1.0 // indirect
103+
github.com/sagikazarmark/locafero v0.4.0 // indirect
104+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
105+
github.com/segmentio/asm v1.2.0 // indirect
106+
github.com/sourcegraph/conc v0.3.0 // indirect
107+
github.com/spf13/afero v1.11.0 // indirect
108+
github.com/spf13/cast v1.6.0 // indirect
109+
github.com/spf13/cobra v1.8.0 // indirect
109110
github.com/spf13/pflag v1.0.5 // indirect
110-
github.com/spf13/viper v1.16.0 // indirect
111-
github.com/stretchr/objx v0.5.0 // indirect
112-
github.com/subosito/gotenv v1.4.2 // indirect
111+
github.com/spf13/viper v1.18.2 // indirect
112+
github.com/stretchr/objx v0.5.2 // indirect
113+
github.com/subosito/gotenv v1.6.0 // indirect
113114
github.com/vincent-petithory/dataurl v1.0.0 // indirect
114-
go.mongodb.org/mongo-driver v1.12.1 // indirect
115-
go.opentelemetry.io/otel v1.14.0 // indirect
116-
go.opentelemetry.io/otel/trace v1.14.0 // indirect
115+
go.mongodb.org/mongo-driver v1.14.0 // indirect
116+
go.opentelemetry.io/otel v1.19.0 // indirect
117+
go.opentelemetry.io/otel/metric v1.19.0 // indirect
118+
go.opentelemetry.io/otel/trace v1.19.0 // indirect
117119
go.uber.org/multierr v1.11.0 // indirect
120+
go.uber.org/zap v1.26.0 // indirect
118121
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
119-
golang.org/x/crypto v0.14.0 // indirect
120-
golang.org/x/net v0.17.0 // indirect
121-
golang.org/x/oauth2 v0.13.0 // indirect
122-
golang.org/x/sys v0.13.0 // indirect
123-
golang.org/x/term v0.13.0 // indirect
124-
golang.org/x/text v0.13.0 // indirect
125-
golang.org/x/time v0.3.0 // indirect
126-
golang.org/x/tools v0.14.0 // indirect
122+
golang.org/x/crypto v0.21.0 // indirect
123+
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
124+
golang.org/x/net v0.22.0 // indirect
125+
golang.org/x/oauth2 v0.18.0 // indirect
126+
golang.org/x/sync v0.6.0 // indirect
127+
golang.org/x/sys v0.18.0 // indirect
128+
golang.org/x/term v0.18.0 // indirect
129+
golang.org/x/text v0.14.0 // indirect
130+
golang.org/x/time v0.5.0 // indirect
131+
golang.org/x/tools v0.19.0 // indirect
127132
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
128-
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
129-
google.golang.org/appengine v1.6.7 // indirect
130-
google.golang.org/protobuf v1.31.0 // indirect
133+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
134+
google.golang.org/appengine v1.6.8 // indirect
135+
google.golang.org/protobuf v1.33.0 // indirect
131136
gopkg.in/inf.v0 v0.9.1 // indirect
132137
gopkg.in/ini.v1 v1.67.0 // indirect
133138
gopkg.in/yaml.v2 v2.4.0 // indirect
134139
gopkg.in/yaml.v3 v3.0.1 // indirect
135-
k8s.io/apiextensions-apiserver v0.26.3 // indirect
136-
k8s.io/component-base v0.26.3 // indirect
137-
k8s.io/klog/v2 v2.90.1 // indirect
138-
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
139-
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749 // indirect
140+
k8s.io/apiextensions-apiserver v0.28.3 // indirect
141+
k8s.io/component-base v0.28.3 // indirect
142+
k8s.io/klog/v2 v2.100.1 // indirect
143+
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
144+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
140145
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
141146
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
142147
sigs.k8s.io/yaml v1.3.0 // indirect

0 commit comments

Comments
 (0)