Skip to content

Commit 0ab3ffa

Browse files
committed
ci: update GitHub Actions workflow
1 parent a0f433b commit 0ab3ffa

6 files changed

Lines changed: 77 additions & 80 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,38 @@ jobs:
2929
matrix:
3030
go-version: [1.21.x]
3131
os: [ubuntu-latest]
32-
architecture: [x32, x64]
33-
name: Generate/Build/Test (${{ matrix.os }}, ${{ matrix.architecture }}, Go ${{ matrix.go-version }})
32+
architecture: [x64]
33+
name: Build/Test (${{ matrix.os }}, ${{ matrix.architecture }}, Go ${{ matrix.go-version }})
3434
runs-on: ${{ matrix.os }}
3535
steps:
36-
- uses: actions/checkout@v3
37-
- uses: actions/setup-go@v4
36+
- uses: actions/checkout@v4
37+
- uses: actions/setup-go@v5
3838
with:
3939
go-version: ${{ matrix.go-version }}
4040
architecture: ${{ matrix.architecture }}
41+
cache: true
4142
- name: Build all modules
42-
run: CGO_ENABLED=0 go build -v
43+
run: CGO_ENABLED=0 go build -v ./...
4344
- name: Test all modules
44-
run: CGO_ENABLED=0 go test ./deviceplugin/... -v
45+
run: CGO_ENABLED=0 go test ./... -v
4546

4647
lint:
47-
strategy:
48-
matrix:
49-
go-version: [1.21.x]
50-
os: [ubuntu-latest]
51-
dir: ["./"]
52-
name: Lint ${{ matrix.dir }} (${{ matrix.os }}, Go ${{ matrix.go-version }})
53-
runs-on: ${{ matrix.os }}
48+
runs-on: ubuntu-latest
5449
steps:
55-
- uses: actions/checkout@v3
56-
- uses: actions/setup-go@v2
50+
- uses: actions/checkout@v4
51+
- uses: actions/setup-go@v5
5752
with:
58-
go-version: ${{ matrix.go-version }}
53+
go-version: 1.21.x
54+
cache: true
5955
- name: Run golangci-lint
60-
uses: golangci/golangci-lint-action@v3.2.0
56+
uses: golangci/golangci-lint-action@v4
6157
with:
6258
version: latest
63-
working-directory: ${{ matrix.dir }}
6459
args: >
65-
-D errcheck
60+
-E errcheck
6661
-E stylecheck
6762
-E goimports
6863
-E misspell
6964
-E revive
7065
-E gofmt
71-
-E goimports
72-
--exclude-use-default=false
73-
--max-same-issues=0
74-
--max-issues-per-linter=0
75-
--timeout 2m
66+
--timeout 5m

deviceplugin/ccdevice.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
)
3434

3535
const (
36-
deviceCheckInterval = 5 * time.Second
36+
deviceCheckInterval = 5 * time.Second
3737
copiedEventLogDirectory = "/run/cc-device-plugin"
3838
copiedEventLogLocation = "/run/cc-device-plugin/binary_bios_measurements"
3939
containerEventLogDirectory = "/run/cc-device-plugin"
@@ -57,7 +57,7 @@ type CcDeviceSpec struct {
5757
Resource string
5858
DevicePaths []string
5959
MeasurementPaths []string
60-
DeviceLimit int // Number of allocatable instances of this resource
60+
DeviceLimit int // Number of allocatable instances of this resource
6161
Type AttestationType // New flag to explicitly define the device type
6262
}
6363

@@ -70,12 +70,12 @@ type CcDevice struct {
7070

7171
// CcDevicePlugin is a device plugin for cc devices
7272
type CcDevicePlugin struct {
73-
cds *CcDeviceSpec
74-
ccDevices map[string]CcDevice
75-
logger log.Logger
76-
copiedEventLogDirectory string
77-
copiedEventLogLocation string
78-
containerEventLogDirectory string
73+
cds *CcDeviceSpec
74+
ccDevices map[string]CcDevice
75+
logger log.Logger
76+
copiedEventLogDirectory string
77+
copiedEventLogLocation string
78+
containerEventLogDirectory string
7979
// this lock prevents data race when kubelet sends multiple requests at the same time
8080
mu sync.Mutex
8181

@@ -94,9 +94,9 @@ func NewCcDevicePlugin(cds *CcDeviceSpec, devicePluginPath string, socket string
9494
}
9595

9696
cdp := &CcDevicePlugin{
97-
cds: cds,
98-
ccDevices: make(map[string]CcDevice),
99-
logger: logger,
97+
cds: cds,
98+
ccDevices: make(map[string]CcDevice),
99+
logger: logger,
100100
copiedEventLogDirectory: copiedEventLogDirectory,
101101
copiedEventLogLocation: copiedEventLogLocation, // Note: This path is static, used only by vTPM plugin instance.
102102
containerEventLogDirectory: containerEventLogDirectory,
@@ -119,9 +119,9 @@ func NewCcDevicePlugin(cds *CcDeviceSpec, devicePluginPath string, socket string
119119
if err != nil {
120120
return nil, err
121121
}
122-
level.Info(cdp.logger).Log("msg", "Directory created:" + cdp.copiedEventLogDirectory)
122+
_ = level.Info(cdp.logger).Log("msg", "Directory created:"+cdp.copiedEventLogDirectory)
123123
} else {
124-
level.Info(cdp.logger).Log("msg", "Directory already exists:" + cdp.copiedEventLogDirectory)
124+
_ = level.Info(cdp.logger).Log("msg", "Directory already exists:"+cdp.copiedEventLogDirectory)
125125
}
126126
}
127127

@@ -144,7 +144,7 @@ func (cdp *CcDevicePlugin) discoverCcDevices() ([]CcDevice, error) {
144144
return nil, err
145145
}
146146
if len(matches) > 0 {
147-
level.Info(cdp.logger).Log("msg", "found matching device path(s)", "pattern", path, "matches", strings.Join(matches, ","))
147+
_ = level.Info(cdp.logger).Log("msg", "found matching device path(s)", "pattern", path, "matches", strings.Join(matches, ","))
148148
foundDevicePaths = append(foundDevicePaths, matches...)
149149
}
150150
}
@@ -180,7 +180,7 @@ func (cdp *CcDevicePlugin) discoverCcDevices() ([]CcDevice, error) {
180180
if len(matches) > 0 {
181181
// We only expect one measurement file
182182
foundMeasurementPath = matches[0]
183-
level.Info(cdp.logger).Log("msg", "measurement path found", "path", foundMeasurementPath)
183+
_ = level.Info(cdp.logger).Log("msg", "measurement path found", "path", foundMeasurementPath)
184184
break
185185
}
186186
}
@@ -194,21 +194,21 @@ func (cdp *CcDevicePlugin) discoverCcDevices() ([]CcDevice, error) {
194194
fileInfo, err := os.Stat(cdp.copiedEventLogLocation)
195195
if errors.Is(err, os.ErrNotExist) {
196196
if err := copyMeasurementFile(foundMeasurementPath, cdp.copiedEventLogLocation); err != nil {
197-
level.Error(cdp.logger).Log("msg", "failed to copy measurement file", "error", err)
197+
_ = level.Error(cdp.logger).Log("msg", "failed to copy measurement file", "error", err)
198198
return nil, err
199199
}
200200
} else if err == nil && fileInfo.ModTime().After(measurementFileLastUpdate) {
201201
// Refresh the copy if the source file has been updated by the kernel since the last copy.
202202
if err := copyMeasurementFile(foundMeasurementPath, cdp.copiedEventLogLocation); err != nil {
203-
level.Error(cdp.logger).Log("msg", "failed to re-copy measurement file", "error", err)
203+
_ = level.Error(cdp.logger).Log("msg", "failed to re-copy measurement file", "error", err)
204204
return nil, err
205205
}
206206
} else if err != nil {
207-
level.Error(cdp.logger).Log("msg", "failed to stat copied measurement file", "error", err)
207+
_ = level.Error(cdp.logger).Log("msg", "failed to stat copied measurement file", "error", err)
208208
return nil, err
209209
}
210210
} else {
211-
level.Warn(cdp.logger).Log("msg", "MeasurementPaths specified but no measurement file found", "paths", strings.Join(cdp.cds.MeasurementPaths, ","))
211+
_ = level.Warn(cdp.logger).Log("msg", "MeasurementPaths specified but no measurement file found", "paths", strings.Join(cdp.cds.MeasurementPaths, ","))
212212
}
213213
}
214214

@@ -292,13 +292,13 @@ func (cdp *CcDevicePlugin) refreshDevices() (bool, error) {
292292
// Log if devices were removed
293293
for k := range old {
294294
if _, ok := cdp.ccDevices[k]; !ok {
295-
level.Info(cdp.logger).Log("msg", "device removed", "id", k)
295+
_ = level.Info(cdp.logger).Log("msg", "device removed", "id", k)
296296
}
297297
}
298298
// Log if devices were added
299299
for k := range cdp.ccDevices {
300300
if _, ok := old[k]; !ok {
301-
level.Info(cdp.logger).Log("msg", "device added", "id", k)
301+
_ = level.Info(cdp.logger).Log("msg", "device added", "id", k)
302302
}
303303
}
304304

@@ -323,14 +323,14 @@ func (cdp *CcDevicePlugin) Allocate(_ context.Context, req *v1beta1.AllocateRequ
323323
if ccDevice.Health != v1beta1.Healthy {
324324
return nil, fmt.Errorf("requested cc device is not healthy %q", id)
325325
}
326-
level.Info(cdp.logger).Log("msg", "adding device and measurement to Pod", "device id", id)
326+
_ = level.Info(cdp.logger).Log("msg", "adding device and measurement to Pod", "device id", id)
327327

328328
for _, ds := range ccDevice.DeviceSpecs {
329-
level.Debug(cdp.logger).Log("msg", "added ccDevice.deviceSpecs", "spec", ds.String())
329+
_ = level.Debug(cdp.logger).Log("msg", "added ccDevice.deviceSpecs", "spec", ds.String())
330330
}
331331

332332
for _, dm := range ccDevice.Mounts {
333-
level.Debug(cdp.logger).Log("msg", "added ccDevice.mounts", "mount", dm.String())
333+
_ = level.Debug(cdp.logger).Log("msg", "added ccDevice.mounts", "mount", dm.String())
334334
}
335335

336336
resp.Devices = append(resp.Devices, ccDevice.DeviceSpecs...)
@@ -349,7 +349,7 @@ func (cdp *CcDevicePlugin) GetDevicePluginOptions(_ context.Context, _ *v1beta1.
349349

350350
// ListAndWatch lists all devices and then refreshes every deviceCheckInterval.
351351
func (cdp *CcDevicePlugin) ListAndWatch(_ *v1beta1.Empty, stream v1beta1.DevicePlugin_ListAndWatchServer) error {
352-
level.Info(cdp.logger).Log("msg", "starting list and watch")
352+
_ = level.Info(cdp.logger).Log("msg", "starting list and watch")
353353
if _, err := cdp.refreshDevices(); err != nil {
354354
return err
355355
}
@@ -363,14 +363,14 @@ func (cdp *CcDevicePlugin) ListAndWatch(_ *v1beta1.Empty, stream v1beta1.DeviceP
363363
cdp.mu.Unlock()
364364

365365
if err := stream.Send(res); err != nil {
366-
level.Error(cdp.logger).Log("msg", "failed to send ListAndWatchResponse", "error", err)
366+
_ = level.Error(cdp.logger).Log("msg", "failed to send ListAndWatchResponse", "error", err)
367367
return err
368368
}
369369

370370
<-time.After(deviceCheckInterval)
371371

372372
if _, err := cdp.refreshDevices(); err != nil {
373-
level.Error(cdp.logger).Log("msg", "error during device refresh", "error", err)
373+
_ = level.Error(cdp.logger).Log("msg", "error during device refresh", "error", err)
374374
// Don't return error immediately, try to continue
375375
}
376376
}

deviceplugin/ccdevice_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ func constructTestPlugin(t *testing.T, spec *CcDeviceSpec) *CcDevicePlugin {
9393

9494
// For SoftwareAttestation, we expect the directory to be created
9595
if spec.Type == SoftwareAttestation {
96-
os.MkdirAll(cdp.copiedEventLogDirectory, 0755)
96+
if err := os.MkdirAll(cdp.copiedEventLogDirectory, 0755); err != nil {
97+
t.Fatalf("failed to create directory: %v", err)
98+
}
9799
}
98100

99101
return cdp
@@ -223,7 +225,9 @@ func TestAllocate(t *testing.T) {
223225
DeviceLimit: 2,
224226
}
225227
cdp := constructTestPlugin(t, spec)
226-
cdp.refreshDevices()
228+
if _, err := cdp.refreshDevices(); err != nil {
229+
t.Fatalf("refreshDevices failed: %v", err)
230+
}
227231

228232
ctx := context.Background()
229233
expectedID := getExpectedID(spec.Resource, spec.DeviceLimit, 0)
@@ -259,10 +263,8 @@ func TestAllocateNotExistDevice(t *testing.T) {
259263
}},
260264
}
261265
_, err := cdp.Allocate(context.Background(), req)
262-
if err == nil || !errors.Is(err, err) { // Simplified check for existence of error
263-
if !errors.Is(err, fmt.Errorf("requested cc device does not exist \"NonExistentID\"")) {
264-
// Logic check passed if error contains the string
265-
}
266+
if err == nil {
267+
t.Fatal("expected error for non-existent device, got nil")
266268
}
267269
}
268270

@@ -277,13 +279,13 @@ func (d *listAndWatchServerStub) Send(*v1beta1.ListAndWatchResponse) error {
277279
return nil
278280
}
279281

280-
func (d *listAndWatchServerStub) SetTestComplete() { d.testComplete = true }
281-
func (d *listAndWatchServerStub) SetHeader(metadata.MD) error { return nil }
282+
func (d *listAndWatchServerStub) SetTestComplete() { d.testComplete = true }
283+
func (d *listAndWatchServerStub) SetHeader(metadata.MD) error { return nil }
282284
func (d *listAndWatchServerStub) SendHeader(metadata.MD) error { return nil }
283-
func (d *listAndWatchServerStub) SetTrailer(metadata.MD) {}
284-
func (d *listAndWatchServerStub) Context() context.Context { return context.Background() }
285-
func (d *listAndWatchServerStub) SendMsg(any) error { return nil }
286-
func (d *listAndWatchServerStub) RecvMsg(any) error { return nil }
285+
func (d *listAndWatchServerStub) SetTrailer(metadata.MD) { /* no-op for testing */ }
286+
func (d *listAndWatchServerStub) Context() context.Context { return context.Background() }
287+
func (d *listAndWatchServerStub) SendMsg(any) error { return nil }
288+
func (d *listAndWatchServerStub) RecvMsg(any) error { return nil }
287289

288290
func TestListAndWatch(t *testing.T) {
289291
spec := &CcDeviceSpec{
@@ -321,5 +323,7 @@ func TestListAndWatch(t *testing.T) {
321323
}, func(error) {})
322324
}
323325

324-
g.Run()
326+
if err := g.Run(); err != nil && err.Error() != "test complete" {
327+
t.Errorf("run group failed: %v", err)
328+
}
325329
}

deviceplugin/plugin.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Outer:
102102
err := p.runOnce(ctx)
103103
if err != nil {
104104
lastErrorTime = time.Now()
105-
level.Warn(p.logger).Log("msg", "encountered error while running plugin", "err", err)
105+
_ = level.Warn(p.logger).Log("msg", "encountered error while running plugin", "err", err)
106106
select {
107107
case <-ctx.Done():
108108
break Outer
@@ -129,15 +129,15 @@ Outer:
129129
// This makes it convenient to run in a run.Group.
130130
func (p *plugin) serve(ctx context.Context) (func() error, func(error), error) {
131131
// Run the gRPC server.
132-
level.Info(p.logger).Log("msg", "listening on Unix socket", "socket", p.socket)
132+
_ = level.Info(p.logger).Log("msg", "listening on Unix socket", "socket", p.socket)
133133
l, err := net.Listen("unix", p.socket)
134134
if err != nil {
135135
return nil, nil, fmt.Errorf("failed to listen on Unix socket %q: %v", p.socket, err)
136136
}
137137

138138
ch := make(chan error)
139139
go func() {
140-
level.Info(p.logger).Log("msg", "starting gRPC server")
140+
_ = level.Info(p.logger).Log("msg", "starting gRPC server")
141141
ch <- p.grpcServer.Serve(l)
142142
close(ch)
143143
}()
@@ -148,7 +148,7 @@ Outer:
148148
for range p.grpcServer.GetServiceInfo() {
149149
break Outer
150150
}
151-
level.Info(p.logger).Log("msg", "waiting for gRPC server to be ready")
151+
_ = level.Info(p.logger).Log("msg", "waiting for gRPC server to be ready")
152152
select {
153153
case <-ctx.Done():
154154
return nil, nil, ctx.Err()
@@ -164,7 +164,7 @@ Outer:
164164
// Drain the channel to clean up.
165165
<-ch
166166
if err := l.Close(); err != nil {
167-
level.Warn(p.logger).Log("msg", "encountered error while closing the listener", "err", err)
167+
_ = level.Warn(p.logger).Log("msg", "encountered error while closing the listener", "err", err)
168168
}
169169
}, nil
170170
}
@@ -190,7 +190,7 @@ func (p *plugin) runOnce(ctx context.Context) error {
190190
ctx, cancel := context.WithCancel(ctx)
191191
g.Add(func() error {
192192
defer cancel()
193-
level.Info(p.logger).Log("msg", "waiting for the gRPC server to be ready")
193+
_ = level.Info(p.logger).Log("msg", "waiting for the gRPC server to be ready")
194194
c, err := grpc.DialContext(ctx, p.socket, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(),
195195
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
196196
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
@@ -202,11 +202,11 @@ func (p *plugin) runOnce(ctx context.Context) error {
202202
if err := c.Close(); err != nil {
203203
return fmt.Errorf("failed to close connection to local gRPC server: %v", err)
204204
}
205-
level.Info(p.logger).Log("msg", "the gRPC server is ready")
205+
_ = level.Info(p.logger).Log("msg", "the gRPC server is ready")
206206
if err := p.registerWithKubelet(); err != nil {
207207
return fmt.Errorf("failed to register with kubelet: %v", err)
208208
}
209-
level.Info(p.logger).Log("msg", "the registration is complete")
209+
_ = level.Info(p.logger).Log("msg", "the registration is complete")
210210
<-ctx.Done()
211211
return nil
212212
}, func(error) {
@@ -239,7 +239,7 @@ func (p *plugin) runOnce(ctx context.Context) error {
239239
}
240240

241241
func (p *plugin) registerWithKubelet() error {
242-
level.Info(p.logger).Log("msg", "registering plugin with kubelet")
242+
_ = level.Info(p.logger).Log("msg", "registering plugin with kubelet")
243243
conn, err := grpc.Dial(filepath.Join(p.pluginDir, p.kubeSocketBase), grpc.WithTransportCredentials(insecure.NewCredentials()),
244244
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
245245
d := &net.Dialer{}

deviceplugin/plugin_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ func TestRegisterWithKublet(t *testing.T) {
165165
}, func(error) {})
166166
}
167167

168-
g.Run()
168+
if err := g.Run(); err != nil && err.Error() != "test complete" {
169+
t.Errorf("run group failed: %v", err)
170+
}
169171
}
170172

171173
func maybeLogError(f func() error, message string) {

0 commit comments

Comments
 (0)