diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-04-26 09:31:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-26 09:31:06 -0400 |
commit | fef3ea80aa597fb8fb0cb133b4d7410d1e2a65d6 (patch) | |
tree | c11b5aff7eb871af2ed6375bd4adc600bf43ea88 /pkg/specgen/generate | |
parent | 333817a187f7811919b9f5fb75a829fe5abfbc44 (diff) | |
parent | db7cff8c86a35a4b1971c3fbb2365eff9cc205d4 (diff) | |
download | podman-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 'pkg/specgen/generate')
-rw-r--r-- | pkg/specgen/generate/container_create.go | 33 |
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 |