summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-04-26 09:31:06 -0400
committerGitHub <noreply@github.com>2021-04-26 09:31:06 -0400
commitfef3ea80aa597fb8fb0cb133b4d7410d1e2a65d6 (patch)
treec11b5aff7eb871af2ed6375bd4adc600bf43ea88 /libpod
parent333817a187f7811919b9f5fb75a829fe5abfbc44 (diff)
parentdb7cff8c86a35a4b1971c3fbb2365eff9cc205d4 (diff)
downloadpodman-fef3ea80aa597fb8fb0cb133b4d7410d1e2a65d6.tar.gz
podman-fef3ea80aa597fb8fb0cb133b4d7410d1e2a65d6.tar.bz2
podman-fef3ea80aa597fb8fb0cb133b4d7410d1e2a65d6.zip
Merge pull request #10081 from sjug/cdi_device_lib
Add support for CDI device configuration
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_config.go2
-rw-r--r--libpod/container_internal_linux.go8
-rw-r--r--libpod/options.go11
3 files changed, 21 insertions, 0 deletions
diff --git a/libpod/container_config.go b/libpod/container_config.go
index e6c3be1bd..d0572fbc2 100644
--- a/libpod/container_config.go
+++ b/libpod/container_config.go
@@ -366,4 +366,6 @@ type ContainerMiscConfig struct {
Umask string `json:"umask,omitempty"`
// PidFile is the file that saves the pid of the container process
PidFile string `json:"pid_file,omitempty"`
+ // CDIDevices contains devices that use the CDI
+ CDIDevices []string `json:"cdiDevices,omitempty"`
}
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 1986f7438..f4762b5ff 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -20,6 +20,7 @@ import (
"time"
metadata "github.com/checkpoint-restore/checkpointctl/lib"
+ cdi "github.com/container-orchestrated-devices/container-device-interface/pkg"
cnitypes "github.com/containernetworking/cni/pkg/types/current"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containers/buildah/pkg/chrootuser"
@@ -704,6 +705,13 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
}
g.SetLinuxCgroupsPath(cgroupPath)
+ // Warning: CDI may alter g.Config in place.
+ if len(c.config.CDIDevices) > 0 {
+ if err = cdi.UpdateOCISpecForDevices(g.Config, c.config.CDIDevices); err != nil {
+ return nil, errors.Wrapf(err, "error setting up CDI devices")
+ }
+ }
+
// Mounts need to be sorted so paths will not cover other paths
mounts := sortMounts(g.Mounts())
g.ClearMounts()
diff --git a/libpod/options.go b/libpod/options.go
index 5cd0f7b88..103a9a80a 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -293,6 +293,17 @@ func WithHooksDir(hooksDirs ...string) RuntimeOption {
}
}
+// WithCDI sets the devices to check for for CDI configuration.
+func WithCDI(devices []string) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return define.ErrCtrFinalized
+ }
+ ctr.config.CDIDevices = devices
+ return nil
+ }
+}
+
// WithDefaultMountsFile sets the file to look at for default mounts (mainly
// secrets).
// Note we are not saving this in the database as it is for testing purposes