Skip to content

Commit 35babbe

Browse files
Merge pull request #1107 from ArangoGutierrez/i/1075
Load settings from config.toml file during CDI generation
2 parents d1d1676 + 0e75444 commit 35babbe

File tree

159 files changed

+8303
-19860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+8303
-19860
lines changed

cmd/nvidia-cdi-hook/chmod/chmod.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package chmod
1818

1919
import (
20+
"context"
2021
"errors"
2122
"fmt"
2223
"io/fs"
@@ -25,7 +26,7 @@ import (
2526
"strconv"
2627
"strings"
2728

28-
"github.com/urfave/cli/v2"
29+
"github.com/urfave/cli/v3"
2930

3031
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
3132
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
@@ -36,7 +37,7 @@ type command struct {
3637
}
3738

3839
type config struct {
39-
paths cli.StringSlice
40+
paths []string
4041
modeStr string
4142
mode fs.FileMode
4243
containerSpec string
@@ -58,36 +59,35 @@ func (m command) build() *cli.Command {
5859
c := cli.Command{
5960
Name: "chmod",
6061
Usage: "Set the permissions of folders in the container by running chmod. The container root is prefixed to the specified paths.",
61-
Before: func(c *cli.Context) error {
62-
return validateFlags(c, &cfg)
62+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
63+
return ctx, m.validateFlags(cmd, &cfg)
6364
},
64-
Action: func(c *cli.Context) error {
65-
return m.run(c, &cfg)
65+
Action: func(ctx context.Context, cmd *cli.Command) error {
66+
return m.run(cmd, &cfg)
6667
},
67-
}
68-
69-
c.Flags = []cli.Flag{
70-
&cli.StringSliceFlag{
71-
Name: "path",
72-
Usage: "Specify a path to apply the specified mode to",
73-
Destination: &cfg.paths,
74-
},
75-
&cli.StringFlag{
76-
Name: "mode",
77-
Usage: "Specify the file mode",
78-
Destination: &cfg.modeStr,
79-
},
80-
&cli.StringFlag{
81-
Name: "container-spec",
82-
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
83-
Destination: &cfg.containerSpec,
68+
Flags: []cli.Flag{
69+
&cli.StringSliceFlag{
70+
Name: "path",
71+
Usage: "Specify a path to apply the specified mode to",
72+
Destination: &cfg.paths,
73+
},
74+
&cli.StringFlag{
75+
Name: "mode",
76+
Usage: "Specify the file mode",
77+
Destination: &cfg.modeStr,
78+
},
79+
&cli.StringFlag{
80+
Name: "container-spec",
81+
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
82+
Destination: &cfg.containerSpec,
83+
},
8484
},
8585
}
8686

8787
return &c
8888
}
8989

90-
func validateFlags(c *cli.Context, cfg *config) error {
90+
func (m command) validateFlags(_ *cli.Command, cfg *config) error {
9191
if strings.TrimSpace(cfg.modeStr) == "" {
9292
return fmt.Errorf("a non-empty mode must be specified")
9393
}
@@ -98,7 +98,7 @@ func validateFlags(c *cli.Context, cfg *config) error {
9898
}
9999
cfg.mode = fs.FileMode(modeInt)
100100

101-
for _, p := range cfg.paths.Value() {
101+
for _, p := range cfg.paths {
102102
if strings.TrimSpace(p) == "" {
103103
return fmt.Errorf("paths must not be empty")
104104
}
@@ -107,7 +107,7 @@ func validateFlags(c *cli.Context, cfg *config) error {
107107
return nil
108108
}
109109

110-
func (m command) run(c *cli.Context, cfg *config) error {
110+
func (m command) run(_ *cli.Command, cfg *config) error {
111111
s, err := oci.LoadContainerState(cfg.containerSpec)
112112
if err != nil {
113113
return fmt.Errorf("failed to load container state: %v", err)
@@ -121,7 +121,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
121121
return fmt.Errorf("empty container root detected")
122122
}
123123

124-
paths := m.getPaths(containerRoot, cfg.paths.Value(), cfg.mode)
124+
paths := m.getPaths(containerRoot, cfg.paths, cfg.mode)
125125
if len(paths) == 0 {
126126
m.logger.Debugf("No paths specified; exiting")
127127
return nil

cmd/nvidia-cdi-hook/commands/commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package commands
1818

1919
import (
20-
"github.com/urfave/cli/v2"
20+
"github.com/urfave/cli/v3"
2121

2222
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/chmod"
2323
createsonamesymlinks "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/create-soname-symlinks"
@@ -45,7 +45,7 @@ func New(logger logger.Interface) []*cli.Command {
4545
// hook has been specified.
4646
// This happens if a subcommand is provided that does not match one of the
4747
// subcommands that has been explicitly specified.
48-
func IssueUnsupportedHookWarning(logger logger.Interface, c *cli.Context) {
48+
func IssueUnsupportedHookWarning(logger logger.Interface, c *cli.Command) {
4949
args := c.Args().Slice()
5050
if len(args) == 0 {
5151
logger.Warningf("No CDI hook specified")

cmd/nvidia-cdi-hook/create-soname-symlinks/soname-symlinks.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
package create_soname_symlinks
1919

2020
import (
21+
"context"
2122
"errors"
2223
"fmt"
2324
"log"
2425
"os"
2526

2627
"github.com/moby/sys/reexec"
27-
"github.com/urfave/cli/v2"
28+
"github.com/urfave/cli/v3"
2829

2930
"github.com/NVIDIA/nvidia-container-toolkit/internal/ldconfig"
3031
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
@@ -40,7 +41,7 @@ type command struct {
4041
}
4142

4243
type options struct {
43-
folders cli.StringSlice
44+
folders []string
4445
ldconfigPath string
4546
containerSpec string
4647
}
@@ -68,44 +69,43 @@ func (m command) build() *cli.Command {
6869
c := cli.Command{
6970
Name: "create-soname-symlinks",
7071
Usage: "Create soname symlinks libraries in specified directories",
71-
Before: func(c *cli.Context) error {
72-
return m.validateFlags(c, &cfg)
72+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
73+
return ctx, m.validateFlags(cmd, &cfg)
7374
},
74-
Action: func(c *cli.Context) error {
75-
return m.run(c, &cfg)
75+
Action: func(ctx context.Context, cmd *cli.Command) error {
76+
return m.run(cmd, &cfg)
7677
},
77-
}
78-
79-
c.Flags = []cli.Flag{
80-
&cli.StringSliceFlag{
81-
Name: "folder",
82-
Usage: "Specify a directory to generate soname symlinks in. Can be specified multiple times",
83-
Destination: &cfg.folders,
84-
},
85-
&cli.StringFlag{
86-
Name: "ldconfig-path",
87-
Usage: "Specify the path to ldconfig on the host",
88-
Destination: &cfg.ldconfigPath,
89-
Value: "/sbin/ldconfig",
90-
},
91-
&cli.StringFlag{
92-
Name: "container-spec",
93-
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
94-
Destination: &cfg.containerSpec,
78+
Flags: []cli.Flag{
79+
&cli.StringSliceFlag{
80+
Name: "folder",
81+
Usage: "Specify a directory to generate soname symlinks in. Can be specified multiple times",
82+
Destination: &cfg.folders,
83+
},
84+
&cli.StringFlag{
85+
Name: "ldconfig-path",
86+
Usage: "Specify the path to ldconfig on the host",
87+
Destination: &cfg.ldconfigPath,
88+
Value: "/sbin/ldconfig",
89+
},
90+
&cli.StringFlag{
91+
Name: "container-spec",
92+
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
93+
Destination: &cfg.containerSpec,
94+
},
9595
},
9696
}
9797

9898
return &c
9999
}
100100

101-
func (m command) validateFlags(c *cli.Context, cfg *options) error {
101+
func (m command) validateFlags(_ *cli.Command, cfg *options) error {
102102
if cfg.ldconfigPath == "" {
103103
return errors.New("ldconfig-path must be specified")
104104
}
105105
return nil
106106
}
107107

108-
func (m command) run(c *cli.Context, cfg *options) error {
108+
func (m command) run(_ *cli.Command, cfg *options) error {
109109
s, err := oci.LoadContainerState(cfg.containerSpec)
110110
if err != nil {
111111
return fmt.Errorf("failed to load container state: %v", err)
@@ -120,7 +120,7 @@ func (m command) run(c *cli.Context, cfg *options) error {
120120
reexecUpdateLdCacheCommandName,
121121
cfg.ldconfigPath,
122122
containerRootDir,
123-
cfg.folders.Value()...,
123+
cfg.folders...,
124124
)
125125
if err != nil {
126126
return err

cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package symlinks
1818

1919
import (
20+
"context"
2021
"errors"
2122
"fmt"
2223
"os"
2324
"path/filepath"
2425
"strings"
2526

2627
"github.com/moby/sys/symlink"
27-
"github.com/urfave/cli/v2"
28+
"github.com/urfave/cli/v3"
2829

2930
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
3031
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
@@ -36,7 +37,7 @@ type command struct {
3637
}
3738

3839
type config struct {
39-
links cli.StringSlice
40+
links []string
4041
containerSpec string
4142
}
4243

@@ -55,30 +56,29 @@ func (m command) build() *cli.Command {
5556
c := cli.Command{
5657
Name: "create-symlinks",
5758
Usage: "A hook to create symlinks in the container.",
58-
Action: func(c *cli.Context) error {
59-
return m.run(c, &cfg)
59+
Action: func(_ context.Context, cmd *cli.Command) error {
60+
return m.run(cmd, &cfg)
6061
},
61-
}
62-
63-
c.Flags = []cli.Flag{
64-
&cli.StringSliceFlag{
65-
Name: "link",
66-
Usage: "Specify a specific link to create. The link is specified as target::link. If the link exists in the container root, it is removed.",
67-
Destination: &cfg.links,
68-
},
69-
// The following flags are testing-only flags.
70-
&cli.StringFlag{
71-
Name: "container-spec",
72-
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN. This is only intended for testing.",
73-
Destination: &cfg.containerSpec,
74-
Hidden: true,
62+
Flags: []cli.Flag{
63+
&cli.StringSliceFlag{
64+
Name: "link",
65+
Usage: "Specify a specific link to create. The link is specified as target::link. If the link exists in the container root, it is removed.",
66+
Destination: &cfg.links,
67+
},
68+
// The following flags are testing-only flags.
69+
&cli.StringFlag{
70+
Name: "container-spec",
71+
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN. This is only intended for testing.",
72+
Destination: &cfg.containerSpec,
73+
Hidden: true,
74+
},
7575
},
7676
}
7777

7878
return &c
7979
}
8080

81-
func (m command) run(c *cli.Context, cfg *config) error {
81+
func (m command) run(_ *cli.Command, cfg *config) error {
8282
s, err := oci.LoadContainerState(cfg.containerSpec)
8383
if err != nil {
8484
return fmt.Errorf("failed to load container state: %v", err)
@@ -90,7 +90,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
9090
}
9191

9292
created := make(map[string]bool)
93-
for _, l := range cfg.links.Value() {
93+
for _, l := range cfg.links {
9494
if created[l] {
9595
m.logger.Debugf("Link %v already processed", l)
9696
continue

cmd/nvidia-cdi-hook/cudacompat/cudacompat.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
package cudacompat
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"os"
2223
"path/filepath"
2324
"strconv"
2425
"strings"
2526

26-
"github.com/urfave/cli/v2"
27+
"github.com/urfave/cli/v3"
2728

2829
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2930
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
@@ -63,37 +64,36 @@ func (m command) build() *cli.Command {
6364
c := cli.Command{
6465
Name: "enable-cuda-compat",
6566
Usage: "This hook ensures that the folder containing the CUDA compat libraries is added to the ldconfig search path if required.",
66-
Before: func(c *cli.Context) error {
67-
return m.validateFlags(c, &cfg)
67+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
68+
return ctx, m.validateFlags(cmd, &cfg)
6869
},
69-
Action: func(c *cli.Context) error {
70-
return m.run(c, &cfg)
70+
Action: func(ctx context.Context, cmd *cli.Command) error {
71+
return m.run(cmd, &cfg)
7172
},
72-
}
73-
74-
c.Flags = []cli.Flag{
75-
&cli.StringFlag{
76-
Name: "host-driver-version",
77-
Usage: "Specify the host driver version. If the CUDA compat libraries detected in the container do not have a higher MAJOR version, the hook is a no-op.",
78-
Destination: &cfg.hostDriverVersion,
79-
},
80-
&cli.StringFlag{
81-
Name: "container-spec",
82-
Hidden: true,
83-
Category: "testing-only",
84-
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
85-
Destination: &cfg.containerSpec,
73+
Flags: []cli.Flag{
74+
&cli.StringFlag{
75+
Name: "host-driver-version",
76+
Usage: "Specify the host driver version. If the CUDA compat libraries detected in the container do not have a higher MAJOR version, the hook is a no-op.",
77+
Destination: &cfg.hostDriverVersion,
78+
},
79+
&cli.StringFlag{
80+
Name: "container-spec",
81+
Hidden: true,
82+
Category: "testing-only",
83+
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
84+
Destination: &cfg.containerSpec,
85+
},
8686
},
8787
}
8888

8989
return &c
9090
}
9191

92-
func (m command) validateFlags(_ *cli.Context, cfg *options) error {
92+
func (m command) validateFlags(cmd *cli.Command, cfg *options) error {
9393
return nil
9494
}
9595

96-
func (m command) run(_ *cli.Context, cfg *options) error {
96+
func (m command) run(_ *cli.Command, cfg *options) error {
9797
if cfg.hostDriverVersion == "" {
9898
return nil
9999
}

0 commit comments

Comments
 (0)