Skip to content

Commit 2cc723d

Browse files
authored
Merge pull request #489 from e0ne/cdi
CDI implementation
2 parents aff8970 + 7564f3b commit 2cc723d

File tree

106 files changed

+10910
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+10910
-206
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ mockery: | $(BASE) $(GOMOCKERY) ; $(info Running mockery...) @ ## Run golint on
160160
# $Q cd $(BASE)/pkg/types && rm -rf mocks && $(GOMOCKERY) --all 2>/dev/null
161161
$Q $(GOMOCKERY) --name=".*" --dir=pkg/types --output=pkg/types/mocks --recursive=false --log-level=debug
162162
$Q $(GOMOCKERY) --name=".*" --dir=pkg/utils --output=pkg/utils/mocks --recursive=false --log-level=debug
163+
$Q $(GOMOCKERY) --name=".*" --dir=pkg/cdi --output=pkg/cdi/mocks --recursive=false --log-level=debug
163164

164165
.PHONY: help
165166
help: ; @ ## Display this help message

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- [CNI plugins in virtual environments](#cni-plugins-in-virtual-environments)
3333
- [Virtual environments with no iommu](#virtual-environments-with-no-iommu)
3434
- [Multi Architecture Support](#multi-architecture-support)
35+
- [Container Device Interface](#container-device-interface)
3536
- [Issues and Contributing](#issues-and-contributing)
3637

3738
## SR-IOV Network Device Plugin
@@ -712,12 +713,15 @@ Buiding image for AMD64:
712713
$ DOCKERFILE=Dockerfile make image
713714
```
714715

715-
Buiding image for PPC64LE:
716+
Building image for PPC64LE:
716717

717718
```sh
718719
$ DOCKERFILE=images/Dockerfile.ppc64le TAG=ghcr.io/k8snetworkplumbingwg/sriov-device-plugin:latest-ppc64le make image
719720
```
720721

722+
## Container Device Interface
723+
To enable Container Device Interface (CDI) deployment please the see [CDI](deployments/cdi/README.md).
724+
721725
## Issues and Contributing
722726

723727
We welcome your feedback and contributions to this project. Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.

cmd/sriovdp/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ const (
2727
defaultConfig = "/etc/pcidp/config.json"
2828
)
2929

30-
// Parse Command line flags
30+
// flagInit parse command line flags
3131
func flagInit(cp *cliParams) {
3232
flag.StringVar(&cp.configFile, "config-file", defaultConfig,
3333
"JSON device pool config file location")
3434
flag.StringVar(&cp.resourcePrefix, "resource-prefix", "intel.com",
3535
"resource name prefix used for K8s extended resource")
36+
flag.BoolVar(&cp.useCdi, "use-cdi", false,
37+
"Use Container Device Interface to expose devices in containers")
3638
}
3739

3840
func main() {
@@ -86,4 +88,7 @@ func main() {
8688
if err := rm.stopAllServers(); err != nil {
8789
glog.Errorf("stopping servers produced error: %s", err.Error())
8890
}
91+
if err := rm.cleanupCDISpecs(); err != nil {
92+
glog.Errorf("cleaning up CDI Specs produced error: %s", err.Error())
93+
}
8994
}

cmd/sriovdp/manager.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3436
type cliParams struct {
3537
configFile string
3638
resourcePrefix string
39+
useCdi bool
3740
}
3841

42+
// resourceManager manages resources for SR-IOV Network Device Plugin binaries
3943
type 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
4854
func 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

103110
func (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+
}

cmd/sriovdp/manager_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"os"
2020
"testing"
2121

22+
CDImocks "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/cdi/mocks"
23+
2224
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/factory"
2325
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/netdevice"
2426
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types"
@@ -441,7 +443,7 @@ var _ = Describe("Resource manager", func() {
441443
_ = os.Unsetenv("GHW_CHROOT")
442444
}()
443445

444-
rf := factory.NewResourceFactory("fake", "fake", true)
446+
rf := factory.NewResourceFactory("fake", "fake", true, false)
445447

446448
rm := &resourceManager{
447449
rFactory: rf,
@@ -615,5 +617,24 @@ var _ = Describe("Resource manager", func() {
615617
Expect(err).To(HaveOccurred())
616618
})
617619
})
620+
Context("when resource servers cleans CDI specs ", func() {
621+
rs := &mocks.ResourceServer{}
622+
rs.On("Stop").Return(nil)
623+
624+
cp = &cliParams{
625+
configFile: "/tmp/sriovdp/test_config",
626+
resourcePrefix: "test_",
627+
useCdi: true,
628+
}
629+
rm = newResourceManager(cp)
630+
cdi := &CDImocks.CDI{}
631+
cdi.On("CleanupSpecs").Return(nil)
632+
rm.cdi = &CDImocks.CDI{}
633+
634+
err := rm.stopAllServers()
635+
It("shouldn't fail", func() {
636+
Expect(err).NotTo(HaveOccurred())
637+
})
638+
})
618639
})
619640
})

deployments/cdi/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SR-IOV Network Device Plugin in CDI mode deployment
2+
3+
SR-IOV Network Device Plugin supports [Container Device Interface (CDI)](https://github.com/container-orchestrated-devices/container-device-interface).
4+
5+
To enable CDI mode, SR-IOV Network Device Plugin should be started with `--use-cdi` CLI argument.
6+
This mode has different deployment requirements: `sriovdp-daemonset.yaml`
7+
8+
```yaml
9+
- mountPath: /var/run/cdi
10+
name: dynamic-cdi
11+
```

0 commit comments

Comments
 (0)