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

CDI implementation #489

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ mockery: | $(BASE) $(GOMOCKERY) ; $(info Running mockery...) @ ## Run golint on
# $Q cd $(BASE)/pkg/types && rm -rf mocks && $(GOMOCKERY) --all 2>/dev/null
$Q $(GOMOCKERY) --name=".*" --dir=pkg/types --output=pkg/types/mocks --recursive=false --log-level=debug
$Q $(GOMOCKERY) --name=".*" --dir=pkg/utils --output=pkg/utils/mocks --recursive=false --log-level=debug
$Q $(GOMOCKERY) --name=".*" --dir=pkg/cdi --output=pkg/cdi/mocks --recursive=false --log-level=debug

.PHONY: help
help: ; @ ## Display this help message
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [CNI plugins in virtual environments](#cni-plugins-in-virtual-environments)
- [Virtual environments with no iommu](#virtual-environments-with-no-iommu)
- [Multi Architecture Support](#multi-architecture-support)
- [Container Device Interface](#container-device-interface)
- [Issues and Contributing](#issues-and-contributing)

## SR-IOV Network Device Plugin
Expand Down Expand Up @@ -712,12 +713,15 @@ Buiding image for AMD64:
$ DOCKERFILE=Dockerfile make image
```

Buiding image for PPC64LE:
Building image for PPC64LE:

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

## Container Device Interface
To enable Container Device Interface (CDI) deployment please the see [CDI](deployments/cdi/README.md).

## Issues and Contributing

We welcome your feedback and contributions to this project. Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.
7 changes: 6 additions & 1 deletion cmd/sriovdp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ const (
defaultConfig = "/etc/pcidp/config.json"
)

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

func main() {
Expand Down Expand Up @@ -86,4 +88,7 @@ func main() {
if err := rm.stopAllServers(); err != nil {
glog.Errorf("stopping servers produced error: %s", err.Error())
}
if err := rm.cleanupCDISpecs(); err != nil {
glog.Errorf("cleaning up CDI Specs produced error: %s", err.Error())
}
}
24 changes: 22 additions & 2 deletions cmd/sriovdp/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/golang/glog"
"github.com/jaypipes/ghw"

cdiPkg "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/cdi"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/factory"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils"
Expand All @@ -31,20 +32,25 @@ const (
socketSuffix = "sock"
)

// cliParams presents CLI parameters for SR-IOV Network Device Plugin
type cliParams struct {
configFile string
resourcePrefix string
useCdi bool
}

// resourceManager manages resources for SR-IOV Network Device Plugin binaries
type resourceManager struct {
cliParams
pluginWatchMode bool
rFactory types.ResourceFactory
configList []*types.ResourceConfig
resourceServers []types.ResourceServer
deviceProviders map[types.DeviceType]types.DeviceProvider
cdi cdiPkg.CDI
}

// newResourceManager initiates a new instance of resourceManager
func newResourceManager(cp *cliParams) *resourceManager {
pluginWatchMode := utils.DetectPluginWatchMode(types.SockDir)
if pluginWatchMode {
Expand All @@ -53,7 +59,7 @@ func newResourceManager(cp *cliParams) *resourceManager {
glog.Infof("Using Deprecated Device Plugin Registry Path")
}

rf := factory.NewResourceFactory(cp.resourcePrefix, socketSuffix, pluginWatchMode)
rf := factory.NewResourceFactory(cp.resourcePrefix, socketSuffix, pluginWatchMode, cp.useCdi)
dp := make(map[types.DeviceType]types.DeviceProvider)
for k := range types.SupportedDevices {
dp[k] = rf.GetDeviceProvider(k)
Expand All @@ -64,6 +70,7 @@ func newResourceManager(cp *cliParams) *resourceManager {
pluginWatchMode: pluginWatchMode,
rFactory: rf,
deviceProviders: dp,
cdi: cdiPkg.New(),
}
}

Expand Down Expand Up @@ -101,12 +108,16 @@ func (rm *resourceManager) readConfig() error {
}

func (rm *resourceManager) initServers() error {
err := rm.cleanupCDISpecs()
if err != nil {
glog.Errorf("Unable to delete CDI specs: %v", err)
return err
}
rf := rm.rFactory
glog.Infof("number of config: %d\n", len(rm.configList))
deviceAllocated := make(map[string]bool)
for _, rc := range rm.configList {
// Create new ResourcePool
glog.Infof("")
glog.Infof("Creating new ResourcePool: %s", rc.ResourceName)
glog.Infof("DeviceType: %+v", rc.DeviceType)
dp, ok := rm.deviceProviders[rc.DeviceType]
Expand Down Expand Up @@ -249,3 +260,12 @@ func (rm *resourceManager) discoverHostDevices() error {
}
return nil
}

func (rm *resourceManager) cleanupCDISpecs() error {
if rm.cliParams.useCdi {
if err := rm.cdi.CleanupSpecs(); err != nil {
return fmt.Errorf("unable to delete CDI specs: %v", err)
}
}
return nil
}
23 changes: 22 additions & 1 deletion cmd/sriovdp/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"os"
"testing"

CDImocks "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/cdi/mocks"

"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/factory"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/netdevice"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types"
Expand Down Expand Up @@ -441,7 +443,7 @@ var _ = Describe("Resource manager", func() {
_ = os.Unsetenv("GHW_CHROOT")
}()

rf := factory.NewResourceFactory("fake", "fake", true)
rf := factory.NewResourceFactory("fake", "fake", true, false)

rm := &resourceManager{
rFactory: rf,
Expand Down Expand Up @@ -615,5 +617,24 @@ var _ = Describe("Resource manager", func() {
Expect(err).To(HaveOccurred())
})
})
Context("when resource servers cleans CDI specs ", func() {
rs := &mocks.ResourceServer{}
rs.On("Stop").Return(nil)

cp = &cliParams{
configFile: "/tmp/sriovdp/test_config",
resourcePrefix: "test_",
useCdi: true,
}
rm = newResourceManager(cp)
cdi := &CDImocks.CDI{}
cdi.On("CleanupSpecs").Return(nil)
rm.cdi = &CDImocks.CDI{}

err := rm.stopAllServers()
It("shouldn't fail", func() {
Expect(err).NotTo(HaveOccurred())
})
})
})
})
11 changes: 11 additions & 0 deletions deployments/cdi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SR-IOV Network Device Plugin in CDI mode deployment

SR-IOV Network Device Plugin supports [Container Device Interface (CDI)](https://github.com/container-orchestrated-devices/container-device-interface).

To enable CDI mode, SR-IOV Network Device Plugin should be started with `--use-cdi` CLI argument.
This mode has different deployment requirements: `sriovdp-daemonset.yaml`

```yaml
- mountPath: /var/run/cdi
Copy link
Contributor

Choose a reason for hiding this comment

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

we need just /var/run/cdi imo we dont deal with statically configured files right ?

Copy link
Contributor

Choose a reason for hiding this comment

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

we should align daemonsets as well

name: dynamic-cdi
```
Loading
Loading