Skip to content

Commit 47d880f

Browse files
committed
Introduce log/slog for logging
Signed-off-by: Fredrik Lönnegren <[email protected]>
1 parent 6a50a39 commit 47d880f

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

cmd/device-plugin/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package main
22

33
import (
44
"flag"
5+
"log/slog"
56
"time"
67

7-
"github.com/golang/glog"
88
"github.com/kubevirt/device-plugin-manager/pkg/dpm"
99

1010
rtlsdr "github.com/frelon/k8s-radio/device-plugin/rtl-sdr"
@@ -38,14 +38,14 @@ func (l *RadioDeviceLister) NewPlugin(resourceLastName string) dpm.PluginInterfa
3838
}
3939
}
4040

41-
glog.Errorf("Unknown resource name: '%s'", resourceLastName)
41+
slog.Error("Unknown resource", "name", resourceLastName)
4242
return nil
4343
}
4444

4545
func main() {
4646
flag.Parse()
4747

48-
glog.Info("Starting radio device plugin")
48+
slog.Info("Starting radio device plugin")
4949

5050
l := RadioDeviceLister{
5151
ResUpdateChan: make(chan dpm.PluginNameList),
@@ -54,7 +54,7 @@ func main() {
5454

5555
pulse := 2
5656
go func() {
57-
glog.Infof("Heart beating every %d seconds", pulse)
57+
slog.Info("Heartbeat", "pulse", pulse)
5858

5959
for {
6060
time.Sleep(time.Second * time.Duration(pulse))

device-plugin/rtl-sdr/rtl-sdr.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package rtlsdr
33
import (
44
"context"
55
"fmt"
6+
"log/slog"
67

7-
"github.com/golang/glog"
88
"github.com/google/gousb"
99
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
1010
)
@@ -29,11 +29,11 @@ func (p *Plugin) PreStartContainer(ctx context.Context, r *pluginapi.PreStartCon
2929
func (p *Plugin) UpdateDevices() error {
3030
rtls, err := ListDevices()
3131
if err != nil {
32-
glog.Infof("Error listing devices: %s", err.Error())
32+
slog.Info("Error listing devices", slog.Any("error", err))
3333
return err
3434
}
3535

36-
glog.Infof("Found %d devices", len(rtls))
36+
slog.Info("Found devices", "len", len(rtls))
3737

3838
for _, rtl := range p.RtlSdrs {
3939
rtl.Connected = false
@@ -68,31 +68,31 @@ func (p *Plugin) GetDevices() []*pluginapi.Device {
6868
func (p *Plugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error {
6969
err := p.UpdateDevices()
7070
if err != nil {
71-
glog.Errorf("Error listing devices: %s", err.Error())
71+
slog.Error("Error listing devices", slog.Any("error", err))
7272
}
7373

7474
devs := p.GetDevices()
7575

7676
err = s.Send(&pluginapi.ListAndWatchResponse{Devices: devs})
7777
if err != nil {
78-
glog.Errorf("Error sending initial response: %s", err.Error())
78+
slog.Error("Error sending initial response", slog.Any("error", err))
7979
}
8080

81-
glog.Info("Waiting for updates...")
81+
slog.Info("Waiting for updates...")
8282

8383
for range p.Heartbeat {
8484
err = p.UpdateDevices()
8585
if err != nil {
86-
glog.Errorf("Error reading devices: %s", err.Error())
86+
slog.Error("Error reading devices", slog.Any("error", err))
8787
continue
8888
}
8989

9090
devs := p.GetDevices()
91-
glog.Infof("Devices updated (len %d)", len(devs))
91+
slog.Info("Devices updated", "len", len(devs))
9292

9393
err = s.Send(&pluginapi.ListAndWatchResponse{Devices: devs})
9494
if err != nil {
95-
glog.Errorf("Error sending response: %s", err.Error())
95+
slog.Error("Error sending response", slog.Any("error", err))
9696
continue
9797
}
9898
}
@@ -117,7 +117,7 @@ func (p *Plugin) Allocate(ctx context.Context, r *pluginapi.AllocateRequest) (*p
117117
car.Devices = append(car.Devices, dev)
118118

119119
for _, id := range req.DevicesIDs {
120-
glog.Infof("Allocating device ID: %s", id)
120+
slog.Info("Allocating device", slog.String("ID", id))
121121

122122
dev.HostPath = p.RtlSdrs[id].DevicePath()
123123
dev.ContainerPath = p.RtlSdrs[id].DevicePath()
@@ -166,7 +166,7 @@ func ListDevices() ([]*RtlSdrDev, error) {
166166
}
167167

168168
if err != nil {
169-
glog.Infof("Err open device (%d): %s", len(devs), err.Error())
169+
slog.Info("Error open device", slog.Int("len", len(devs)), slog.Any("error", err))
170170
return nil, err
171171
}
172172

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/frelon/k8s-radio
33
go 1.25
44

55
require (
6-
github.com/golang/glog v1.2.5
76
github.com/google/gousb v1.1.2
87
github.com/kubevirt/device-plugin-manager v1.19.5
98
github.com/onsi/ginkgo/v2 v2.11.0
@@ -29,6 +28,7 @@ require (
2928
github.com/go-openapi/swag v0.22.3 // indirect
3029
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
3130
github.com/gogo/protobuf v1.3.2 // indirect
31+
github.com/golang/glog v1.2.5 // indirect
3232
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3333
github.com/golang/protobuf v1.5.3 // indirect
3434
github.com/google/gnostic-models v0.6.8 // indirect

0 commit comments

Comments
 (0)