Skip to content

Commit

Permalink
cmd/initContainer: Shuffle some code around
Browse files Browse the repository at this point in the history
The following commit will handle create-symlinks hooks in the Container
Device Interface specification for the proprietary NVIDIA driver,
because NVIDIA Container Toolkit 0.16.0 started using those [1].  So,
make some space for the new code.

This will make the following commit easier to read.

Fallout from 649d02f

[1] NVIDIA Container Toolkit commit aae3da88c33d9cf2
    NVIDIA/nvidia-container-toolkit@aae3da88c33d9cf2
    NVIDIA/nvidia-container-toolkit#548

#1545
  • Loading branch information
debarshiray committed Sep 17, 2024
1 parent 9a87d15 commit a79e427
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions src/cmd/initContainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,38 +474,46 @@ func applyCDISpecForNvidia(spec *specs.Spec) error {
continue
}

if len(hook.Args) < 2 ||
hook.Args[0] != "nvidia-cdi-hook" ||
hook.Args[1] != "update-ldcache" {
logrus.Debug("Applying Container Device Interface for NVIDIA: unknown hook arguments:")
for _, arg := range hook.Args {
logrus.Debugf("%s", arg)
if len(hook.Args) >= 2 &&
hook.Args[0] == "nvidia-cdi-hook" &&
hook.Args[1] == "update-ldcache" {
hookArgs := hook.Args[2:]
if err := applyCDISpecForNvidiaHookUpdateLDCache(hookArgs); err != nil {
logrus.Debugf("Applying Container Device Interface for NVIDIA: %s", err)
return errors.New("failed to update ldcache for Container Device Interface for NVIDIA")
}

continue
}

var folderFlag bool
var folders []string
hookArgs := hook.Args[2:]
logrus.Debug("Applying Container Device Interface for NVIDIA: unknown hook arguments:")
for _, arg := range hook.Args {
logrus.Debugf("%s", arg)
}
}

for _, hookArg := range hookArgs {
if hookArg == "--folder" {
folderFlag = true
continue
}
return nil
}

if folderFlag {
folders = append(folders, hookArg)
}
func applyCDISpecForNvidiaHookUpdateLDCache(hookArgs []string) error {
var folderFlag bool
var folders []string

folderFlag = false
for _, hookArg := range hookArgs {
if hookArg == "--folder" {
folderFlag = true
continue
}

if err := ldConfig("toolbx-nvidia.conf", folders); err != nil {
logrus.Debugf("Applying Container Device Interface for NVIDIA: %s", err)
return errors.New("failed to update ldcache for Container Device Interface for NVIDIA")
if folderFlag {
folders = append(folders, hookArg)
}

folderFlag = false
}

if err := ldConfig("toolbx-nvidia.conf", folders); err != nil {
return err
}

return nil
Expand Down

0 comments on commit a79e427

Please sign in to comment.