Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log the unresolved CDI devices only #153

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tariq1890 marked this conversation as resolved.
Show resolved Hide resolved
- 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