@@ -22,6 +22,7 @@ import (
2222 "github.com/golang/glog"
2323 "github.com/jaypipes/ghw"
2424
25+ cdiPkg "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/cdi"
2526 "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/factory"
2627 "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types"
2728 "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils"
@@ -31,20 +32,25 @@ const (
3132 socketSuffix = "sock"
3233)
3334
35+ // cliParams presents CLI parameters for SR-IOV Network Device Plugin
3436type cliParams struct {
3537 configFile string
3638 resourcePrefix string
39+ useCdi bool
3740}
3841
42+ // resourceManager manages resources for SR-IOV Network Device Plugin binaries
3943type resourceManager struct {
4044 cliParams
4145 pluginWatchMode bool
4246 rFactory types.ResourceFactory
4347 configList []* types.ResourceConfig
4448 resourceServers []types.ResourceServer
4549 deviceProviders map [types.DeviceType ]types.DeviceProvider
50+ cdi cdiPkg.CDI
4651}
4752
53+ // newResourceManager initiates a new instance of resourceManager
4854func newResourceManager (cp * cliParams ) * resourceManager {
4955 pluginWatchMode := utils .DetectPluginWatchMode (types .SockDir )
5056 if pluginWatchMode {
@@ -53,7 +59,7 @@ func newResourceManager(cp *cliParams) *resourceManager {
5359 glog .Infof ("Using Deprecated Device Plugin Registry Path" )
5460 }
5561
56- rf := factory .NewResourceFactory (cp .resourcePrefix , socketSuffix , pluginWatchMode )
62+ rf := factory .NewResourceFactory (cp .resourcePrefix , socketSuffix , pluginWatchMode , cp . useCdi )
5763 dp := make (map [types.DeviceType ]types.DeviceProvider )
5864 for k := range types .SupportedDevices {
5965 dp [k ] = rf .GetDeviceProvider (k )
@@ -64,6 +70,7 @@ func newResourceManager(cp *cliParams) *resourceManager {
6470 pluginWatchMode : pluginWatchMode ,
6571 rFactory : rf ,
6672 deviceProviders : dp ,
73+ cdi : cdiPkg .New (),
6774 }
6875}
6976
@@ -101,12 +108,16 @@ func (rm *resourceManager) readConfig() error {
101108}
102109
103110func (rm * resourceManager ) initServers () error {
111+ err := rm .cleanupCDISpecs ()
112+ if err != nil {
113+ glog .Errorf ("Unable to delete CDI specs: %v" , err )
114+ return err
115+ }
104116 rf := rm .rFactory
105117 glog .Infof ("number of config: %d\n " , len (rm .configList ))
106118 deviceAllocated := make (map [string ]bool )
107119 for _ , rc := range rm .configList {
108120 // Create new ResourcePool
109- glog .Infof ("" )
110121 glog .Infof ("Creating new ResourcePool: %s" , rc .ResourceName )
111122 glog .Infof ("DeviceType: %+v" , rc .DeviceType )
112123 dp , ok := rm .deviceProviders [rc .DeviceType ]
@@ -249,3 +260,12 @@ func (rm *resourceManager) discoverHostDevices() error {
249260 }
250261 return nil
251262}
263+
264+ func (rm * resourceManager ) cleanupCDISpecs () error {
265+ if rm .cliParams .useCdi {
266+ if err := rm .cdi .CleanupSpecs (); err != nil {
267+ return fmt .Errorf ("unable to delete CDI specs: %v" , err )
268+ }
269+ }
270+ return nil
271+ }
0 commit comments