Skip to content

Commit

Permalink
pkg/cdi: document possible implicit cache refresh.
Browse files Browse the repository at this point in the history
Update public API documentation to point out a possible implicit
cache refresh and how to query any errors encountered during it.

Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Oct 16, 2024
1 parent 9927475 commit 84ea77f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/cdi/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ func (c *Cache) refreshIfRequired(force bool) (bool, error) {

// InjectDevices injects the given qualified devices to an OCI Spec. It
// returns any unresolvable devices and an error if injection fails for
// any of the devices.
// any of the devices. Might trigger a cache refresh, in which case any
// errors encountered can be obtained using GetErrors().
func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, error) {
var unresolved []string

Expand Down Expand Up @@ -335,7 +336,9 @@ func (c *Cache) RemoveSpec(name string) error {
return err
}

// GetDevice returns the cached device for the given qualified name.
// GetDevice returns the cached device for the given qualified name. Might trigger
// a cache refresh, in which case any errors encountered can be obtained using
// GetErrors().
func (c *Cache) GetDevice(device string) *Device {
c.Lock()
defer c.Unlock()
Expand All @@ -345,7 +348,8 @@ func (c *Cache) GetDevice(device string) *Device {
return c.devices[device]
}

// ListDevices lists all cached devices by qualified name.
// ListDevices lists all cached devices by qualified name. Might trigger a cache
// refresh, in which case any errors encountered can be obtained using GetErrors().
func (c *Cache) ListDevices() []string {
var devices []string

Expand All @@ -362,7 +366,8 @@ func (c *Cache) ListDevices() []string {
return devices
}

// ListVendors lists all vendors known to the cache.
// ListVendors lists all vendors known to the cache. Might trigger a cache refresh,
// in which case any errors encountered can be obtained using GetErrors().
func (c *Cache) ListVendors() []string {
var vendors []string

Expand All @@ -379,7 +384,8 @@ func (c *Cache) ListVendors() []string {
return vendors
}

// ListClasses lists all device classes known to the cache.
// ListClasses lists all device classes known to the cache. Might trigger a cache
// refresh, in which case any errors encountered can be obtained using GetErrors().
func (c *Cache) ListClasses() []string {
var (
cmap = map[string]struct{}{}
Expand All @@ -404,7 +410,8 @@ func (c *Cache) ListClasses() []string {
return classes
}

// GetVendorSpecs returns all specs for the given vendor.
// GetVendorSpecs returns all specs for the given vendor. Might trigger a cache
// refresh, in which case any errors encountered can be obtained using GetErrors().
func (c *Cache) GetVendorSpecs(vendor string) []*Spec {
c.Lock()
defer c.Unlock()
Expand Down

0 comments on commit 84ea77f

Please sign in to comment.