mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Move destinationArg to options struct
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
8d623967ed
commit
0a2d8f4d22
@ -30,13 +30,13 @@ var availableRuntimes = map[string]struct{}{"docker": {}, "crio": {}, "container
|
|||||||
var waitingForSignal = make(chan bool, 1)
|
var waitingForSignal = make(chan bool, 1)
|
||||||
var signalReceived = make(chan bool, 1)
|
var signalReceived = make(chan bool, 1)
|
||||||
|
|
||||||
var destinationArg string
|
|
||||||
|
|
||||||
// options stores the command line arguments
|
// options stores the command line arguments
|
||||||
type options struct {
|
type options struct {
|
||||||
noDaemon bool
|
noDaemon bool
|
||||||
runtime string
|
runtime string
|
||||||
runtimeArgs string
|
runtimeArgs string
|
||||||
|
|
||||||
|
root string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version defines the CLI version. This is set at build time using LD FLAGS
|
// Version defines the CLI version. This is set at build time using LD FLAGS
|
||||||
@ -87,7 +87,7 @@ func main() {
|
|||||||
// Run the CLI
|
// Run the CLI
|
||||||
log.Infof("Starting %v", c.Name)
|
log.Infof("Starting %v", c.Name)
|
||||||
|
|
||||||
remainingArgs, err := ParseArgs(os.Args)
|
remainingArgs, err := ParseArgs(os.Args, &options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error: unable to parse arguments: %v", err)
|
log.Errorf("Error: unable to parse arguments: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -114,7 +114,7 @@ func Run(c *cli.Context, o *options) error {
|
|||||||
}
|
}
|
||||||
defer shutdown()
|
defer shutdown()
|
||||||
|
|
||||||
err = installToolkit()
|
err = installToolkit(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to install toolkit: %v", err)
|
return fmt.Errorf("unable to install toolkit: %v", err)
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ func Run(c *cli.Context, o *options) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseArgs parses the command line arguments and returns the remaining arguments
|
// ParseArgs parses the command line arguments and returns the remaining arguments
|
||||||
func ParseArgs(args []string) ([]string, error) {
|
func ParseArgs(args []string, o *options) ([]string, error) {
|
||||||
log.Infof("Parsing arguments")
|
log.Infof("Parsing arguments")
|
||||||
|
|
||||||
numPositionalArgs := 2 // Includes command itself
|
numPositionalArgs := 2 // Includes command itself
|
||||||
@ -170,7 +170,7 @@ func ParseArgs(args []string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destinationArg = args[1]
|
o.root = args[1]
|
||||||
|
|
||||||
return append([]string{args[0]}, args[numPositionalArgs:]...), nil
|
return append([]string{args[0]}, args[numPositionalArgs:]...), nil
|
||||||
}
|
}
|
||||||
@ -220,14 +220,14 @@ func initialize() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func installToolkit() error {
|
func installToolkit(o *options) error {
|
||||||
log.Infof("Installing toolkit")
|
log.Infof("Installing toolkit")
|
||||||
|
|
||||||
cmdline := []string{
|
cmdline := []string{
|
||||||
toolkitCommand,
|
toolkitCommand,
|
||||||
"install",
|
"install",
|
||||||
"--toolkit-root",
|
"--toolkit-root",
|
||||||
filepath.Join(destinationArg, toolkitSubDir),
|
filepath.Join(o.root, toolkitSubDir),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("sh", "-c", strings.Join(cmdline, " "))
|
cmd := exec.Command("sh", "-c", strings.Join(cmdline, " "))
|
||||||
@ -242,7 +242,7 @@ func installToolkit() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupRuntime(o *options) error {
|
func setupRuntime(o *options) error {
|
||||||
toolkitDir := filepath.Join(destinationArg, toolkitSubDir)
|
toolkitDir := filepath.Join(o.root, toolkitSubDir)
|
||||||
|
|
||||||
log.Infof("Setting up runtime")
|
log.Infof("Setting up runtime")
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ func waitForSignal() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cleanupRuntime(o *options) error {
|
func cleanupRuntime(o *options) error {
|
||||||
toolkitDir := filepath.Join(destinationArg, toolkitSubDir)
|
toolkitDir := filepath.Join(o.root, toolkitSubDir)
|
||||||
|
|
||||||
log.Infof("Cleaning up Runtime")
|
log.Infof("Cleaning up Runtime")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user