8000 server,factory/container: delay CDI device injection later. by klihub · Pull Request #9292 · cri-o/cri-o · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

server,factory/container: delay CDI device injection later. #9292

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

Merged
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
3 changes: 3 additions & 0 deletions internal/factory/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type Container interface {
// SpecAddDevices adds devices from the server config, and container CRI config
SpecAddDevices([]device.Device, []device.Device, bool, bool) error

// SpecInjectCDIDevices injects any requested CDI devices to the container's Spec.
SpecInjectCDIDevices() error

// AddUnifiedResourcesFromAnnotations adds the cgroup-v2 resources specified in the io.kubernetes.cri-o.UnifiedCgroup annotation
AddUnifiedResourcesFromAnnotations(annotationsMap map[string]string) error

Expand Down
10 changes: 10 additions & 0 deletions internal/factory/container/device_freebsd.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package container

import (
"fmt"
"runtime"

devicecfg "github.com/cri-o/cri-o/internal/config/device"
)

func (c *container) SpecAddDevices(configuredDevices, annotationDevices []devicecfg.Device, privilegedWithoutHostDevices, enableDeviceOwnershipFromSecurityContext bool) error {
return nil
}

func (c *container) SpecInjectCDIDevices() error {
if len(c.Config().CDIDevices) > 0 {
return fmt.Errorf("(*container).SpecInjectCDIDevices not supported on %s", runtime.GOOS)
}
return nil
}
5 changes: 2 additions & 3 deletions internal/factory/container/device_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func (c *container) SpecAddDevices(configuredDevices, annotationDevices []device
return err
}

// Finally, inject CDI devices
return c.specInjectCDIDevices()
return nil
}

func (c *container) specAddHostDevicesIfPrivileged(privilegedWithoutHostDevices bool) error {
Expand Down Expand Up @@ -185,7 +184,7 @@ func (c *container) specAddContainerConfigDevices(enableDeviceOwnershipFromSecur
return nil
}

func (c *container) specInjectCDIDevices() error {
func (c *container) SpecInjectCDIDevices() error {
var (
cdiDevices = c.Config().CDIDevices
fromCRI = map[string]struct{}{}
Expand Down
4 changes: 2 additions & 2 deletions internal/factory/container/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ var _ = t.Describe("Container", func() {
}
})

t.Describe("SpecAdd(CDI)Devices", func() {
t.Describe("SpecInjectCDIDevices", func() {
writeCDISpecFiles := func(content []string) error {
if len(content) == 0 {
return nil
Expand Down Expand Up @@ -421,7 +421,7 @@ containerEdits:
Expect(writeCDISpecFiles(test.cdiSpecFiles)).To(Succeed())

// When
err := sut.SpecAddDevices(nil, nil, false, false)
err := sut.SpecInjectCDIDevices()

// Then
Expect(err != nil).To(Equal(test.expectError))
Expand Down
8000
7 changes: 7 additions & 0 deletions internal/factory/container/device_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ import (
func (c *container) SpecAddDevices(configuredDevices, annotationDevices []devicecfg.Device, privilegedWithoutHostDevices, enableDeviceOwnershipFromSecurityContext bool) error {
return fmt.Errorf("(*container).SpecAddDevices not supported on %s", runtime.GOOS)
}

func (c *container) SpecInjectCDIDevices() error {
if len(c.Config().CDIDevices) > 0 {
return fmt.Errorf("(*container).SpecInjectCDIDevices not supported on %s", runtime.GOOS)
}
return nil
}
4 changes: 4 additions & 0 deletions server/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,10 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr container.Conta
}
}

if err := ctr.SpecInjectCDIDevices(); err != nil {
return nil, err
}

// Set up pids limit if pids cgroup is mounted
if node.CgroupHasPid() {
specgen.SetLinuxResourcesPidsLimit(s.config.PidsLimit)
Expand Down
2 changes: 1 addition & 1 deletion test/cdi.bats
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function annotate_ctr_with_unknown_cdidev {
}

function prepare_ctr_with_cdidev {
jq ".CDI_Devices |= . + [ { \"Name\": \"vendor0.com/device=loop8\" }, { \"Name\": \"vendor0.com/device=loop9\" } ]" \
jq ".CDI_Devices |= . + [ { \"Name\": \"vendor0.com/device=loop8\" }, { \"Name\": \"vendor0.com/device=loop9\" } ] | .envs |= . + [ { \"key\": \"VENDOR0\", \"value\": \"unset\" }, { \"key\": \"LOOP8\", \"value\": \"unset\" } ]" \
"$TESTDATA/container_sleep.json" > "$ctr_config"
}

Expand Down
Loading
0