Skip to content

Commit 490eb47

Browse files
Merge pull request #25717 from jankaluza/cdi-spec-dir
Add cdi-spec-dir option to top level options
2 parents 4f7b95d + dce3613 commit 490eb47

File tree

11 files changed

+69
-9
lines changed

11 files changed

+69
-9
lines changed

cmd/podman/root.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
247247
if cmd.Flag("hooks-dir").Changed {
248248
podmanConfig.ContainersConf.Engine.HooksDir.Set(podmanConfig.HooksDir)
249249
}
250+
if cmd.Flag("cdi-spec-dir").Changed {
251+
podmanConfig.ContainersConf.Engine.CdiSpecDirs.Set(podmanConfig.CdiSpecDirs)
252+
}
250253

251254
// Currently it is only possible to restore a container with the same runtime
252255
// as used for checkpointing. It should be possible to make crun and runc
@@ -566,6 +569,10 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) {
566569
pFlags.StringArrayVar(&podmanConfig.HooksDir, hooksDirFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.HooksDir.Get(), "Set the OCI hooks directory path (may be set multiple times)")
567570
_ = cmd.RegisterFlagCompletionFunc(hooksDirFlagName, completion.AutocompleteDefault)
568571

572+
cdiSpecDirFlagName := "cdi-spec-dir"
573+
pFlags.StringArrayVar(&podmanConfig.CdiSpecDirs, cdiSpecDirFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.CdiSpecDirs.Get(), "Set the CDI spec directory path (may be set multiple times)")
574+
_ = cmd.RegisterFlagCompletionFunc(cdiSpecDirFlagName, completion.AutocompleteDefault)
575+
569576
pFlags.IntVar(&podmanConfig.MaxWorks, "max-workers", (runtime.NumCPU()*3)+1, "The maximum number of workers for parallel operations")
570577

571578
namespaceFlagName := "namespace"

docs/source/markdown/podman.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ man pages.
2525

2626
## GLOBAL OPTIONS
2727

28+
#### **--cdi-spec-dir**=*path*
29+
30+
The CDI spec directory path (may be set multiple times). Default path is `/etc/cdi`.
31+
2832
#### **--cgroup-manager**=*manager*
2933

3034
The CGroup manager to use for container cgroups. Supported values are __cgroupfs__ or __systemd__. Default is _systemd_ unless overridden in the containers.conf file.

libpod/container_internal_common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
639639
// Warning: CDI may alter g.Config in place.
640640
if len(c.config.CDIDevices) > 0 {
641641
registry, err := cdi.NewCache(
642+
cdi.WithSpecDirs(c.runtime.config.Engine.CdiSpecDirs.Get()...),
642643
cdi.WithAutoRefresh(false),
643644
)
644645
if err != nil {

libpod/options.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ func WithCDI(devices []string) CtrCreateOption {
328328
}
329329
}
330330

331+
func WithCDISpecDirs(cdiSpecDirs []string) RuntimeOption {
332+
return func(rt *Runtime) error {
333+
if rt.valid {
334+
return define.ErrRuntimeFinalized
335+
}
336+
337+
rt.config.Engine.CdiSpecDirs.Set(cdiSpecDirs)
338+
return nil
339+
}
340+
}
341+
331342
// WithStorageOpts sets the devices to check for CDI configuration.
332343
func WithStorageOpts(storageOpts map[string]string) CtrCreateOption {
333344
return func(ctr *Container) error {

pkg/domain/entities/engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type PodmanConfig struct {
3535
CPUProfile string // Hidden: Should CPU profile be taken
3636
EngineMode EngineMode // ABI or Tunneling mode
3737
HooksDir []string
38+
CdiSpecDirs []string
3839
Identity string // ssh identity for connecting to server
3940
IsRenumber bool // Is this a system renumber command? If so, a number of checks will be relaxed
4041
IsReset bool // Is this a system reset command? If so, a number of checks will be skipped/omitted

pkg/domain/infra/runtime_libpod.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo
212212
options = append(options, libpod.WithDatabaseBackend(cfg.ContainersConf.Engine.DBBackend))
213213
}
214214

215+
if cfg.CdiSpecDirs != nil {
216+
options = append(options, libpod.WithCDISpecDirs(cfg.CdiSpecDirs))
217+
}
218+
215219
if cfg.Syslog {
216220
options = append(options, libpod.WithSyslog())
217221
}

pkg/specgen/generate/config_freebsd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ import (
99
"path/filepath"
1010
"strings"
1111

12+
"github.com/containers/common/pkg/config"
1213
"github.com/opencontainers/runtime-tools/generate"
1314
"github.com/sirupsen/logrus"
1415
"golang.org/x/sys/unix"
1516
"tags.cncf.io/container-device-interface/pkg/cdi"
1617
)
1718

1819
// DevicesFromPath computes a list of devices
19-
func DevicesFromPath(g *generate.Generator, devicePath string) error {
20+
func DevicesFromPath(g *generate.Generator, devicePath string, config *config.Config) error {
2021
if isCDIDevice(devicePath) {
2122
registry, err := cdi.NewCache(
23+
cdi.WithSpecDirs(config.Engine.CdiSpecDirs.Get()...),
2224
cdi.WithAutoRefresh(false),
2325
)
2426
if err != nil {

pkg/specgen/generate/config_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
)
2525

2626
// DevicesFromPath computes a list of devices
27-
func DevicesFromPath(g *generate.Generator, devicePath string) error {
27+
func DevicesFromPath(g *generate.Generator, devicePath string, config *config.Config) error {
2828
if isCDIDevice(devicePath) {
2929
registry, err := cdi.NewCache(
30+
cdi.WithSpecDirs(config.Engine.CdiSpecDirs.Get()...),
3031
cdi.WithAutoRefresh(false),
3132
)
3233
if err != nil {

pkg/specgen/generate/oci_freebsd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
5656
if !s.IsPrivileged() {
5757
// add default devices from containers.conf
5858
for _, device := range rtc.Containers.Devices.Get() {
59-
if err = DevicesFromPath(&g, device); err != nil {
59+
if err = DevicesFromPath(&g, device, rtc); err != nil {
6060
return nil, err
6161
}
6262
}
@@ -67,7 +67,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
6767
}
6868
// add default devices specified by caller
6969
for _, device := range userDevices {
70-
if err = DevicesFromPath(&g, device.Path); err != nil {
70+
if err = DevicesFromPath(&g, device.Path, rtc); err != nil {
7171
return nil, err
7272
}
7373
}

pkg/specgen/generate/oci_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
256256
var userDevices []spec.LinuxDevice
257257
// add default devices from containers.conf
258258
for _, device := range rtc.Containers.Devices.Get() {
259-
if err = DevicesFromPath(&g, device); err != nil {
259+
if err = DevicesFromPath(&g, device, rtc); err != nil {
260260
return nil, err
261261
}
262262
}
@@ -267,7 +267,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
267267
}
268268
// add default devices specified by caller
269269
for _, device := range userDevices {
270-
if err = DevicesFromPath(&g, device.Path); err != nil {
270+
if err = DevicesFromPath(&g, device.Path, rtc); err != nil {
271271
return nil, err
272272
}
273273
}

0 commit comments

Comments
 (0)