Skip to content

Commit

Permalink
Merge pull request #583 from souleb/fix-576
Browse files Browse the repository at this point in the history
fix: generate a file per resourcePool
  • Loading branch information
adrianchiris authored Aug 26, 2024
2 parents 7dedc64 + a69512f commit ab6e489
Showing 1 changed file with 9 additions and 6 deletions.
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()
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

0 comments on commit ab6e489

Please sign in to comment.