CDI: configure registry on start
Currently CDI registry is reconfigured on every WithCDI call, which is a relatively heavy operation. This happens because cdi.GetRegistry(cdi.WithSpecDirs(cdiSpecDirs...)) unconditionally reconfigures the registry (clears fs notify watch, sets up new watch, rescans directories). Moving configuration to the criService.initPlatform should result in performing registry configuration only once on the service start. Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
This commit is contained in:
parent
eec7a76ecd
commit
8ed910c46a
@ -732,7 +732,7 @@ func GetPIDNamespace(pid uint32) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithCDI updates OCI spec with CDI content
|
// WithCDI updates OCI spec with CDI content
|
||||||
func WithCDI(annotations map[string]string, cdiSpecDirs []string) oci.SpecOpts {
|
func WithCDI(annotations map[string]string) oci.SpecOpts {
|
||||||
return func(ctx context.Context, _ oci.Client, c *containers.Container, s *oci.Spec) error {
|
return func(ctx context.Context, _ oci.Client, c *containers.Container, s *oci.Spec) error {
|
||||||
// TODO: Once CRI is extended with native CDI support this will need to be updated...
|
// TODO: Once CRI is extended with native CDI support this will need to be updated...
|
||||||
_, cdiDevices, err := cdi.ParseAnnotations(annotations)
|
_, cdiDevices, err := cdi.ParseAnnotations(annotations)
|
||||||
@ -743,7 +743,7 @@ func WithCDI(annotations map[string]string, cdiSpecDirs []string) oci.SpecOpts {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
registry := cdi.GetRegistry(cdi.WithSpecDirs(cdiSpecDirs...))
|
registry := cdi.GetRegistry()
|
||||||
if err = registry.Refresh(); err != nil {
|
if err = registry.Refresh(); err != nil {
|
||||||
// We don't consider registry refresh failure a fatal error.
|
// We don't consider registry refresh failure a fatal error.
|
||||||
// For instance, a dynamically generated invalid CDI Spec file for
|
// For instance, a dynamically generated invalid CDI Spec file for
|
||||||
|
@ -404,7 +404,7 @@ func (c *criService) containerSpecOpts(config *runtime.ContainerConfig, imageCon
|
|||||||
specOpts = append(specOpts, seccompSpecOpts)
|
specOpts = append(specOpts, seccompSpecOpts)
|
||||||
}
|
}
|
||||||
if c.config.EnableCDI {
|
if c.config.EnableCDI {
|
||||||
specOpts = append(specOpts, customopts.WithCDI(config.Annotations, c.config.CDISpecDirs))
|
specOpts = append(specOpts, customopts.WithCDI(config.Annotations))
|
||||||
}
|
}
|
||||||
return specOpts, nil
|
return specOpts, nil
|
||||||
}
|
}
|
||||||
|
@ -1648,7 +1648,11 @@ containerEdits:
|
|||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
injectFun := customopts.WithCDI(test.annotations, []string{cdiDir})
|
reg := cdi.GetRegistry()
|
||||||
|
err = reg.Configure(cdi.WithSpecDirs(cdiDir))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
injectFun := customopts.WithCDI(test.annotations)
|
||||||
err = injectFun(nil, nil, nil, spec)
|
err = injectFun(nil, nil, nil, spec)
|
||||||
assert.Equal(t, test.expectError, err != nil)
|
assert.Equal(t, test.expectError, err != nil)
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ package sbserver
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/containerd/containerd/pkg/cap"
|
"github.com/containerd/containerd/pkg/cap"
|
||||||
"github.com/containerd/containerd/pkg/userns"
|
"github.com/containerd/containerd/pkg/userns"
|
||||||
"github.com/containerd/go-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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,7 +404,7 @@ func (c *criService) containerSpecOpts(config *runtime.ContainerConfig, imageCon
|
|||||||
specOpts = append(specOpts, seccompSpecOpts)
|
specOpts = append(specOpts, seccompSpecOpts)
|
||||||
}
|
}
|
||||||
if c.config.EnableCDI {
|
if c.config.EnableCDI {
|
||||||
specOpts = append(specOpts, customopts.WithCDI(config.Annotations, c.config.CDISpecDirs))
|
specOpts = append(specOpts, customopts.WithCDI(config.Annotations))
|
||||||
}
|
}
|
||||||
return specOpts, nil
|
return specOpts, nil
|
||||||
}
|
}
|
||||||
|
@ -1648,7 +1648,11 @@ containerEdits:
|
|||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
injectFun := customopts.WithCDI(test.annotations, []string{cdiDir})
|
reg := cdi.GetRegistry()
|
||||||
|
err = reg.Configure(cdi.WithSpecDirs(cdiDir))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
injectFun := customopts.WithCDI(test.annotations)
|
||||||
err = injectFun(nil, nil, nil, spec)
|
err = injectFun(nil, nil, nil, spec)
|
||||||
assert.Equal(t, test.expectError, err != nil)
|
assert.Equal(t, test.expectError, err != nil)
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/containerd/containerd/pkg/cap"
|
"github.com/containerd/containerd/pkg/cap"
|
||||||
"github.com/containerd/containerd/pkg/userns"
|
"github.com/containerd/containerd/pkg/userns"
|
||||||
cni "github.com/containerd/go-cni"
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user