MCPcopy
hub / github.com/containers/toolbox / applyCDISpecForNvidia

Function applyCDISpecForNvidia

src/cmd/initContainer.go:408–480  ·  view source on GitHub ↗
(spec *specs.Spec)

Source from the content-addressed store, hash-verified

406}
407
408func applyCDISpecForNvidia(spec *specs.Spec) error {
409 if spec == nil {
410 panic("spec not specified")
411 }
412
413 logrus.Debug("Applying Container Device Interface for NVIDIA")
414
415 for _, mount := range spec.ContainerEdits.Mounts {
416 if err := (&cdi.Mount{Mount: mount}).Validate(); err != nil {
417 logrus.Debugf("Applying Container Device Interface for NVIDIA: invalid mount: %s", err)
418 return errors.New("invalid mount in Container Device Interface for NVIDIA")
419 }
420
421 if mount.Type == "" {
422 mount.Type = "bind"
423 }
424
425 if mount.Type != "bind" {
426 logrus.Debugf("Applying Container Device Interface for NVIDIA: unknown mount type %s",
427 mount.Type)
428 continue
429 }
430
431 flags := strings.Join(mount.Options, ",")
432 hostPath := filepath.Join(string(filepath.Separator), "run", "host", mount.HostPath)
433 if err := mountBind(mount.ContainerPath, hostPath, flags); err != nil {
434 logrus.Debugf("Applying Container Device Interface for NVIDIA: %s", err)
435 return errors.New("failed to apply mount from Container Device Interface for NVIDIA")
436 }
437 }
438
439 for _, hook := range spec.ContainerEdits.Hooks {
440 if err := (&cdi.Hook{Hook: hook}).Validate(); err != nil {
441 logrus.Debugf("Applying Container Device Interface for NVIDIA: invalid hook: %s", err)
442 return errors.New("invalid hook in Container Device Interface for NVIDIA")
443 }
444
445 if hook.HookName != cdi.CreateContainerHook {
446 logrus.Debugf("Applying Container Device Interface for NVIDIA: unknown hook name %s",
447 hook.HookName)
448 continue
449 }
450
451 if len(hook.Args) >= 2 &&
452 hook.Args[0] == "nvidia-cdi-hook" &&
453 hook.Args[1] == "create-symlinks" {
454 hookArgs := hook.Args[2:]
455 if err := applyCDISpecForNvidiaHookCreateSymlinks(hookArgs); err != nil {
456 logrus.Debugf("Applying Container Device Interface for NVIDIA: %s", err)
457 return errors.New("failed to create symlinks for Container Device Interface for NVIDIA")
458 }
459
460 continue
461 } else if len(hook.Args) >= 2 &&
462 hook.Args[0] == "nvidia-cdi-hook" &&
463 hook.Args[1] == "update-ldcache" {
464 hookArgs := hook.Args[2:]
465 if err := applyCDISpecForNvidiaHookUpdateLDCache(hookArgs); err != nil {

Callers 1

initContainerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…