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

fix: generate a file per resourcePool #583

Merged
merged 3 commits into from
Aug 26, 2024
Merged
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
15 changes: 9 additions & 6 deletions pkg/cdi/cdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package cdi

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -48,11 +49,6 @@ func New() CDI {

// CreateCDISpecForPool creates CDI spec file with specified devices
func (c *impl) CreateCDISpecForPool(resourcePrefix string, rPool types.ResourcePool) error {
err := c.CleanupSpecs()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question here: are we still going to cover a case where we remove a specific resource and create a new one using the same devices?

I don't see a cleanup removing resources that we don't expose anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all CDI files prefixed with "sriov-dp" are deleted on device plugin start. (existing logic)

if err != nil {
glog.Errorf("CreateCDISpecForPool(): can not cleanup old spec files: %v", err)
return err
}
cdiDevices := make([]cdiSpecs.Device, 0)
cdiSpec := cdiSpecs.Spec{
Version: cdiSpecs.CurrentVersion,
Expand Down Expand Up @@ -80,7 +76,14 @@ func (c *impl) CreateCDISpecForPool(resourcePrefix string, rPool types.ResourceP
cdiSpec.Devices = append(cdiSpec.Devices, device)
}

err = cdi.GetRegistry().SpecDB().WriteSpec(&cdiSpec, cdiSpecPrefix+resourcePrefix)
name, err := cdi.GenerateNameForSpec(&cdiSpec)
if err != nil {
glog.Errorf("GenerateNameForSpec(): can not generate name: %v", err)
return err
}

// this will overwrite any existing file for this spec with the same name
err = cdi.GetRegistry().SpecDB().WriteSpec(&cdiSpec, fmt.Sprintf("%s%s-%s", cdiSpecPrefix, name, rPool.GetResourceName()))
if err != nil {
glog.Errorf("CreateCDISpecForPool(): can not create CDI json: %v", err)
return err
Expand Down
Loading