Skip to content

Commit

Permalink
log the unresolved CDI devices only
Browse files Browse the repository at this point in the history
Signed-off-by: Tariq Ibrahim <[email protected]>
  • Loading branch information
tariq1890 committed Aug 10, 2023
1 parent 9c63527 commit a446fd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
- name: Install golint
run: go get -u golang.org/x/lint/golint
run: go install golang.org/x/lint/golint@latest
- name: Lint
run: make lint
- name: Fmt
Expand Down
6 changes: 3 additions & 3 deletions pkg/cdi/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Cache struct {
}

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

if unresolved != nil {
return unresolved, fmt.Errorf("unresolvable CDI devices %s",
strings.Join(devices, ", "))
strings.Join(unresolved, ", "))
}

if err := edits.Apply(ociSpec); err != nil {
Expand Down
16 changes: 10 additions & 6 deletions pkg/cdi/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cdi

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -818,12 +819,13 @@ func TestInjectDevice(t *testing.T) {
run map[string]string
}
type testCase struct {
name string
cdiSpecs specDirs
ociSpec *oci.Spec
devices []string
result *oci.Spec
unresolved []string
name string
cdiSpecs specDirs
ociSpec *oci.Spec
devices []string
result *oci.Spec
unresolved []string
expectedErr error
}
for _, tc := range []*testCase{
{
Expand Down Expand Up @@ -1155,6 +1157,7 @@ devices:
unresolved: []string{
"vendor1.com/device=dev2",
},
expectedErr: errors.New("unresolvable CDI devices vendor1.com/device=dev2"),
},
} {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -1180,6 +1183,7 @@ devices:
unresolved, err := cache.InjectDevices(tc.ociSpec, tc.devices...)
if len(tc.unresolved) != 0 {
require.NotNil(t, err)
require.Equal(t, tc.expectedErr, err)
require.Equal(t, tc.unresolved, unresolved)
return
}
Expand Down

0 comments on commit a446fd5

Please sign in to comment.