Merge pull request #7419 from bart0sh/PR005-configure-CDI-registry-on-start
This commit is contained in:
@@ -404,7 +404,7 @@ func (c *criService) containerSpecOpts(config *runtime.ContainerConfig, imageCon
|
||||
specOpts = append(specOpts, seccompSpecOpts)
|
||||
}
|
||||
if c.config.EnableCDI {
|
||||
specOpts = append(specOpts, oci.WithCDI(config.Annotations, c.config.CDISpecDirs))
|
||||
specOpts = append(specOpts, customopts.WithCDI(config.Annotations))
|
||||
}
|
||||
return specOpts, nil
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import (
|
||||
"github.com/containerd/containerd/pkg/cri/annotations"
|
||||
"github.com/containerd/containerd/pkg/cri/config"
|
||||
"github.com/containerd/containerd/pkg/cri/opts"
|
||||
customopts "github.com/containerd/containerd/pkg/cri/opts"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
ostesting "github.com/containerd/containerd/pkg/os/testing"
|
||||
@@ -1547,6 +1548,8 @@ func TestCDIInjections(t *testing.T) {
|
||||
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||
ociRuntime := config.Runtime{}
|
||||
c := newTestCRIService()
|
||||
testContainer := &containers.Container{ID: "64ddfe361f0099f8d59075398feeb3dcb3863b6851df7b946744755066c03e9d"}
|
||||
ctx := context.Background()
|
||||
|
||||
for _, test := range []struct {
|
||||
description string
|
||||
@@ -1647,8 +1650,12 @@ containerEdits:
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
injectFun := oci.WithCDI(test.annotations, []string{cdiDir})
|
||||
err = injectFun(nil, nil, nil, spec)
|
||||
reg := cdi.GetRegistry()
|
||||
err = reg.Configure(cdi.WithSpecDirs(cdiDir))
|
||||
require.NoError(t, err)
|
||||
|
||||
injectFun := customopts.WithCDI(test.annotations)
|
||||
err = injectFun(ctx, nil, testContainer, spec)
|
||||
assert.Equal(t, test.expectError, err != nil)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -19,6 +19,7 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||
"github.com/containerd/containerd/pkg/cap"
|
||||
"github.com/containerd/containerd/pkg/userns"
|
||||
cni "github.com/containerd/go-cni"
|
||||
@@ -87,6 +88,14 @@ func (c *criService) initPlatform() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if c.config.EnableCDI {
|
||||
reg := cdi.GetRegistry()
|
||||
err = reg.Configure(cdi.WithSpecDirs(c.config.CDISpecDirs...))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to configure CDI registry")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user