Skip to content
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 @@ -112,6 +112,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
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 @@ -171,7 +170,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 @@ -185,7 +185,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 @@ -419,7 +419,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
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
}
3 changes: 2 additions & 1 deletion scripts/github-actions-setup
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ prepare_system() {
sudo swapon --show

# enable necessary kernel modules
sudo ip6tables --list >/dev/null
sudo modprobe br_netfilter
sudo sysctl -p /etc/sysctl.conf

# enable necessary sysctls
sudo sysctl -w net.ipv4.conf.all.route_localnet=1
Expand Down
4 changes: 4 additions & 0 deletions server/container_create_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@
}
}

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

Check warning on line 692 in server/container_create_linux.go

View check run for this annotation

Codecov / codecov/patch

server/container_create_linux.go#L691-L692

Added lines #L691 - L692 were not covered by tests

// 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