Skip to content

Commit 3a7cdab

Browse files
Merge pull request #9353 from openshift-cherrypick-robot/cherry-pick-9296-to-release-1.31
[release-1.31] server,factory/container: delay CDI device injection later.
2 parents 0002055 + d6a24de commit 3a7cdab

File tree

7 files changed

+21
-7
lines changed

7 files changed

+21
-7
lines changed

internal/factory/container/container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ type Container interface {
110110
// SpecAddDevices adds devices from the server config, and container CRI config
111111
SpecAddDevices([]device.Device, []device.Device, bool, bool) error
112112

113+
// SpecInjectCDIDevices injects any requested CDI devices to the container's Spec.
114+
SpecInjectCDIDevices() error
115+
113116
// AddUnifiedResourcesFromAnnotations adds the cgroup-v2 resources specified in the io.kubernetes.cri-o.UnifiedCgroup annotation
114117
AddUnifiedResourcesFromAnnotations(annotationsMap map[string]string) error
115118

internal/factory/container/device_linux.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ func (c *container) SpecAddDevices(configuredDevices, annotationDevices []device
4949
return err
5050
}
5151

52-
// Finally, inject CDI devices
53-
return c.specInjectCDIDevices()
52+
return nil
5453
}
5554

5655
func (c *container) specAddHostDevicesIfPrivileged(privilegedWithoutHostDevices bool) error {
@@ -171,7 +170,7 @@ func (c *container) specAddContainerConfigDevices(enableDeviceOwnershipFromSecur
171170
return nil
172171
}
173172

174-
func (c *container) specInjectCDIDevices() error {
173+
func (c *container) SpecInjectCDIDevices() error {
175174
var (
176175
cdiDevices = c.Config().CDIDevices
177176
fromCRI = map[string]struct{}{}

internal/factory/container/device_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ var _ = t.Describe("Container", func() {
185185
}
186186
})
187187

188-
t.Describe("SpecAdd(CDI)Devices", func() {
188+
t.Describe("SpecInjectCDIDevices", func() {
189189
writeCDISpecFiles := func(content []string) error {
190190
if len(content) == 0 {
191191
return nil
@@ -419,7 +419,7 @@ containerEdits:
419419
Expect(writeCDISpecFiles(test.cdiSpecFiles)).To(Succeed())
420420

421421
// When
422-
err := sut.SpecAddDevices(nil, nil, false, false)
422+
err := sut.SpecInjectCDIDevices()
423423

424424
// Then
425425
Expect(err != nil).To(Equal(test.expectError))

internal/factory/container/device_unsupported.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ import (
1313
func (c *container) SpecAddDevices(configuredDevices, annotationDevices []devicecfg.Device, privilegedWithoutHostDevices, enableDeviceOwnershipFromSecurityContext bool) error {
1414
return fmt.Errorf("(*container).SpecAddDevices not supported on %s", runtime.GOOS)
1515
}
16+
17+
func (c *container) SpecInjectCDIDevices() error {
18+
if len(c.Config().CDIDevices) > 0 {
19+
return fmt.Errorf("(*container).SpecInjectCDIDevices not supported on %s", runtime.GOOS)
20+
}
21+
return nil
22+
}

scripts/github-actions-setup

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ prepare_system() {
3939
sudo swapon --show
4040

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

4445
# enable necessary sysctls
4546
sudo sysctl -w net.ipv4.conf.all.route_localnet=1

server/container_create_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,10 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrfactory.Cont
828828
}
829829
}
830830

831+
if err := ctr.SpecInjectCDIDevices(); err != nil {
832+
return nil, err
833+
}
834+
831835
// Set up pids limit if pids cgroup is mounted
832836
if node.CgroupHasPid() {
833837
specgen.SetLinuxResourcesPidsLimit(s.config.PidsLimit)

test/cdi.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function annotate_ctr_with_unknown_cdidev {
111111
}
112112

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

0 commit comments

Comments
 (0)