Skip to content

Commit a446fd5

Browse files
committed
log the unresolved CDI devices only
Signed-off-by: Tariq Ibrahim <[email protected]>
1 parent 9c63527 commit a446fd5

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

.github/workflows/sanity.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
go-version: ${{ env.GO_VERSION }}
2424
- name: Install golint
25-
run: go get -u golang.org/x/lint/golint
25+
run: go install golang.org/x/lint/golint@latest
2626
- name: Lint
2727
run: make lint
2828
- name: Fmt

pkg/cdi/cache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Cache struct {
4949
}
5050

5151
// WithAutoRefresh returns an option to control automatic Cache refresh.
52-
// By default auto-refresh is enabled, the list of Spec directories are
52+
// By default, auto-refresh is enabled, the list of Spec directories are
5353
// monitored and the Cache is automatically refreshed whenever a change
5454
// is detected. This option can be used to disable this behavior when a
5555
// manually refreshed mode is preferable.
@@ -203,7 +203,7 @@ func (c *Cache) refresh() error {
203203
// RefreshIfRequired triggers a refresh if necessary.
204204
func (c *Cache) refreshIfRequired(force bool) (bool, error) {
205205
// We need to refresh if
206-
// - it's forced by an explicitly call to Refresh() in manual mode
206+
// - it's forced by an explicit call to Refresh() in manual mode
207207
// - a missing Spec dir appears (added to watch) in auto-refresh mode
208208
if force || (c.autoRefresh && c.watch.update(c.dirErrors)) {
209209
return true, c.refresh()
@@ -244,7 +244,7 @@ func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, e
244244

245245
if unresolved != nil {
246246
return unresolved, fmt.Errorf("unresolvable CDI devices %s",
247-
strings.Join(devices, ", "))
247+
strings.Join(unresolved, ", "))
248248
}
249249

250250
if err := edits.Apply(ociSpec); err != nil {

pkg/cdi/cache_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cdi
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"os"
2223
"path/filepath"
@@ -818,12 +819,13 @@ func TestInjectDevice(t *testing.T) {
818819
run map[string]string
819820
}
820821
type testCase struct {
821-
name string
822-
cdiSpecs specDirs
823-
ociSpec *oci.Spec
824-
devices []string
825-
result *oci.Spec
826-
unresolved []string
822+
name string
823+
cdiSpecs specDirs
824+
ociSpec *oci.Spec
825+
devices []string
826+
result *oci.Spec
827+
unresolved []string
828+
expectedErr error
827829
}
828830
for _, tc := range []*testCase{
829831
{
@@ -1155,6 +1157,7 @@ devices:
11551157
unresolved: []string{
11561158
"vendor1.com/device=dev2",
11571159
},
1160+
expectedErr: errors.New("unresolvable CDI devices vendor1.com/device=dev2"),
11581161
},
11591162
} {
11601163
t.Run(tc.name, func(t *testing.T) {
@@ -1180,6 +1183,7 @@ devices:
11801183
unresolved, err := cache.InjectDevices(tc.ociSpec, tc.devices...)
11811184
if len(tc.unresolved) != 0 {
11821185
require.NotNil(t, err)
1186+
require.Equal(t, tc.expectedErr, err)
11831187
require.Equal(t, tc.unresolved, unresolved)
11841188
return
11851189
}

0 commit comments

Comments
 (0)