mirror of
				https://github.com/NVIDIA/nvidia-container-toolkit
				synced 2025-06-26 18:18:24 +00:00 
			
		
		
		
	Add --relative-to option to nvidia-ctk transform root
This change adds a --relative-to option to the nvidia-ctk transform root command. This defaults to "host" maintaining the existing behaviour. If --relative-to=container is specified, the root transform is applied to container paths in the CDI specification instead of host paths. Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
		
							parent
							
								
									879cc99aac
								
							
						
					
					
						commit
						bc4e19aa48
					
				| @ -9,6 +9,7 @@ | ||||
| * Add support for injecting /dev/nvidia-nvswitch* devices if the NVIDIA_NVSWITCH=enabled envvar is specified. | ||||
| * Added support for `nvidia-ctk runtime configure --enable-cdi` for the `docker` runtime. Note that this requires Docker >= 25. | ||||
| * Fixed bug in `nvidia-ctk config` command when using `--set`. The types of applied config options are now applied correctly. | ||||
| * Add `--relative-to` option to `nvidia-ctk transform root` command. This controls whether the root transformation is applied to host or container paths. | ||||
| 
 | ||||
| * [libnvidia-container] Fix device permission check when using cgroupv2 (fixes #227) | ||||
| 
 | ||||
|  | ||||
| @ -23,7 +23,7 @@ import ( | ||||
| 
 | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/logger" | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec" | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" | ||||
| 	transformroot "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform/root" | ||||
| 	"github.com/urfave/cli/v2" | ||||
| 	"tags.cncf.io/container-device-interface/pkg/cdi" | ||||
| ) | ||||
| @ -41,6 +41,7 @@ type options struct { | ||||
| 	transformOptions | ||||
| 	from       string | ||||
| 	to         string | ||||
| 	relativeTo string | ||||
| } | ||||
| 
 | ||||
| // NewCommand constructs a generate-cdi command with the specified logger
 | ||||
| @ -67,6 +68,11 @@ func (m command) build() *cli.Command { | ||||
| 	} | ||||
| 
 | ||||
| 	c.Flags = []cli.Flag{ | ||||
| 		&cli.StringFlag{ | ||||
| 			Name:        "from", | ||||
| 			Usage:       "specify the root to be transformed", | ||||
| 			Destination: &opts.from, | ||||
| 		}, | ||||
| 		&cli.StringFlag{ | ||||
| 			Name:        "input", | ||||
| 			Usage:       "Specify the file to read the CDI specification from. If this is '-' the specification is read from STDIN", | ||||
| @ -79,9 +85,10 @@ func (m command) build() *cli.Command { | ||||
| 			Destination: &opts.output, | ||||
| 		}, | ||||
| 		&cli.StringFlag{ | ||||
| 			Name:        "from", | ||||
| 			Usage:       "specify the root to be transformed", | ||||
| 			Destination: &opts.from, | ||||
| 			Name:        "relative-to", | ||||
| 			Usage:       "specify whether the transform is relative to the host or to the container. One of [ host | container ]", | ||||
| 			Value:       "host", | ||||
| 			Destination: &opts.relativeTo, | ||||
| 		}, | ||||
| 		&cli.StringFlag{ | ||||
| 			Name:        "to", | ||||
| @ -95,6 +102,12 @@ func (m command) build() *cli.Command { | ||||
| } | ||||
| 
 | ||||
| func (m command) validateFlags(c *cli.Context, opts *options) error { | ||||
| 	switch opts.relativeTo { | ||||
| 	case "host": | ||||
| 	case "container": | ||||
| 	default: | ||||
| 		return fmt.Errorf("invalid --relative-to value: %v", opts.relativeTo) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| @ -104,9 +117,10 @@ func (m command) run(c *cli.Context, opts *options) error { | ||||
| 		return fmt.Errorf("failed to load CDI specification: %w", err) | ||||
| 	} | ||||
| 
 | ||||
| 	err = transform.NewHostRootTransformer( | ||||
| 		opts.from, | ||||
| 		opts.to, | ||||
| 	err = transformroot.New( | ||||
| 		transformroot.WithRoot(opts.from), | ||||
| 		transformroot.WithTargetRoot(opts.to), | ||||
| 		transformroot.WithRelativeTo(opts.relativeTo), | ||||
| 	).Transform(spec.Raw()) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("failed to transform CDI specification: %w", err) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user