summaryrefslogtreecommitdiff
path: root/pkg/specgen/generate/container_create.go
diff options
context:
space:
mode:
authorSebastian Jug <seb@stianj.ug>2021-03-29 20:21:00 -0400
committerSebastian Jug <seb@stianj.ug>2021-04-20 09:18:52 -0400
commitdb7cff8c86a35a4b1971c3fbb2365eff9cc205d4 (patch)
tree3dc20b52f6a8b2de4acf8cb99ebff81776680959 /pkg/specgen/generate/container_create.go
parentcf2c3a1f13710014892804aacf855cd6b001a5ea (diff)
downloadpodman-db7cff8c86a35a4b1971c3fbb2365eff9cc205d4.tar.gz
podman-db7cff8c86a35a4b1971c3fbb2365eff9cc205d4.tar.bz2
podman-db7cff8c86a35a4b1971c3fbb2365eff9cc205d4.zip
Add support for CDI device configuration
- Persist CDIDevices in container config - Add e2e test - Log HasDevice error and add additional condition for safety Signed-off-by: Sebastian Jug <seb@stianj.ug>
Diffstat (limited to 'pkg/specgen/generate/container_create.go')
-rw-r--r--pkg/specgen/generate/container_create.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go
index 13d4b4926..2f623bf10 100644
--- a/pkg/specgen/generate/container_create.go
+++ b/pkg/specgen/generate/container_create.go
@@ -6,12 +6,14 @@ import (
"path/filepath"
"strings"
+ cdi "github.com/container-orchestrated-devices/container-device-interface/pkg"
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/image"
"github.com/containers/podman/v3/pkg/specgen"
"github.com/containers/podman/v3/pkg/util"
"github.com/containers/storage/types"
+ spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -136,6 +138,11 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
options = append(options, libpod.WithNetworkAliases(s.Aliases))
}
+ if len(s.Devices) > 0 {
+ opts = extractCDIDevices(s)
+ options = append(options, opts...)
+ }
+
runtimeSpec, err := SpecGenToOCI(ctx, s, rt, rtc, newImage, finalMounts, pod, command)
if err != nil {
return nil, err
@@ -143,6 +150,32 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
return rt.NewContainer(ctx, runtimeSpec, options...)
}
+func extractCDIDevices(s *specgen.SpecGenerator) []libpod.CtrCreateOption {
+ devs := make([]spec.LinuxDevice, 0, len(s.Devices))
+ var cdiDevs []string
+ var options []libpod.CtrCreateOption
+
+ for _, device := range s.Devices {
+ isCDIDevice, err := cdi.HasDevice(device.Path)
+ if err != nil {
+ logrus.Debugf("CDI HasDevice Error: %v", err)
+ }
+ if err == nil && isCDIDevice {
+ cdiDevs = append(cdiDevs, device.Path)
+ continue
+ }
+
+ devs = append(devs, device)
+ }
+
+ s.Devices = devs
+ if len(cdiDevs) > 0 {
+ options = append(options, libpod.WithCDI(cdiDevs))
+ }
+
+ return options
+}
+
func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGenerator, pod *libpod.Pod, volumes []*specgen.NamedVolume, overlays []*specgen.OverlayVolume, img *image.Image, command []string) ([]libpod.CtrCreateOption, error) {
var options []libpod.CtrCreateOption
var err error