Skip to content

Commit

Permalink
Update cdiapi.Registry to cdiapi.Cache
Browse files Browse the repository at this point in the history
The registry is now deprecated and throwing lint errors without this update.

Signed-off-by: Kevin Klues <[email protected]>
  • Loading branch information
klueska committed Apr 19, 2024
1 parent 174c5c7 commit 98ee011
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions cmd/nvidia-dra-plugin/cdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type CDIHandler struct {
nvml nvml.Interface
nvdevice nvdevice.Interface
nvcdi nvcdi.Interface
registry cdiapi.Registry
cache *cdiapi.Cache
driverRoot string
devRoot string
targetDriverRoot string
Expand Down Expand Up @@ -102,23 +102,21 @@ func NewCDIHandler(opts ...cdiOption) (*CDIHandler, error) {
h.cdiRoot = defaultCDIRoot
}

if h.registry == nil {
// TODO: We should rather construct a cdi.CacheHere directly.
registry := cdiapi.GetRegistry(
if h.cache == nil {
cache, err := cdiapi.NewCache(
cdiapi.WithSpecDirs(h.cdiRoot),
)
err := registry.Refresh()
if err != nil {
return nil, fmt.Errorf("unable to refresh the CDI registry: %w", err)
return nil, fmt.Errorf("unable to create a new CDI cache: %w", err)
}
h.registry = registry
h.cache = cache
}

return h, nil
}

func (cdi *CDIHandler) GetDevice(device string) *cdiapi.Device {
return cdi.registry.DeviceDB().GetDevice(device)
return cdi.cache.GetDevice(device)
}

func (cdi *CDIHandler) CreateClaimSpecFile(claimUID string, devices *PreparedDevices) error {
Expand Down Expand Up @@ -239,7 +237,7 @@ func (cdi *CDIHandler) DeleteClaimSpecFile(claimUID string) error {
return fmt.Errorf("failed to generate Spec name: %w", err)
}

return cdi.registry.SpecDB().RemoveSpec(specName + ".json")
return cdi.cache.RemoveSpec(specName + ".json")
}

func (cdi *CDIHandler) GetClaimDevices(claimUID string) []string {
Expand Down

0 comments on commit 98ee011

Please sign in to comment.