mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-04-24 16:15:09 +00:00
Add support for NVIDIA_REQUIRE_JETPACK envvar
This change ensures that by default, the CSV discovery only considers the base CSV files (l4t.csv, drivers.csv, devices.csv) and skips the rest unless the NVIDIA_REQUIRE_JETPACK is set to "csv-mounts=all", in which case, all CSV files in the specified folder are considered. Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
1c05a463bd
commit
6682bc90b4
@ -68,7 +68,17 @@ func NewExperimentalModifier(logger *logrus.Logger, cfg *config.Config, ociSpec
|
||||
}
|
||||
d = legacyDiscoverer
|
||||
case "csv":
|
||||
csvDiscoverer, err := discover.NewFromCSV(logger, csv.DefaultRoot, "")
|
||||
csvFiles, err := csv.GetFileList(csv.DefaultRoot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get list of CSV files: %v", err)
|
||||
}
|
||||
|
||||
nvidiaRequireJetpack, _ := ociSpec.LookupEnv(nvidiaRequireJetpackEnvvar)
|
||||
if nvidiaRequireJetpack != "csv-mounts=all" {
|
||||
csvFiles = csv.BaseFilesOnly(csvFiles)
|
||||
}
|
||||
|
||||
csvDiscoverer, err := discover.NewFromCSVFiles(logger, csvFiles, root)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create CSV discoverer: %v", err)
|
||||
}
|
||||
|
@ -40,8 +40,15 @@ func NewFromCSV(logger *logrus.Logger, csvRoot string, root string) (Discover, e
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get CSV file from %v: %v", csvRoot, err)
|
||||
}
|
||||
return NewFromCSVFiles(logger, files, root)
|
||||
}
|
||||
|
||||
// NewFromCSVFiles creates a discoverer for the specified CSV files. A logger is also supplied.
|
||||
// The constructed discoverer is comprised of a list, with each element in the list being associated with a
|
||||
// single CSV files.
|
||||
func NewFromCSVFiles(logger *logrus.Logger, files []string, root string) (Discover, error) {
|
||||
if len(files) == 0 {
|
||||
logger.Warnf("No CSV files found in %v", csvRoot)
|
||||
logger.Warnf("No CSV files specified")
|
||||
return None{}, nil
|
||||
}
|
||||
|
||||
@ -66,7 +73,9 @@ func NewFromCSV(logger *logrus.Logger, csvRoot string, root string) (Discover, e
|
||||
return &list{discoverers: discoverers}, nil
|
||||
}
|
||||
|
||||
// NewFromCSVFile creates a discoverer for the CSV file. A logger is also supplied.
|
||||
// NewFromCSVFile creates a discoverer for the specified CSV file. A logger is also supplied.
|
||||
// The constructed discoverer is comprised of a list, with each element in the list being associated with a particular
|
||||
// MountSpecType.
|
||||
func NewFromCSVFile(logger *logrus.Logger, locators map[csv.MountSpecType]lookup.Locator, filename string) (Discover, error) {
|
||||
// Create a discoverer for each file-kind combination
|
||||
targets, err := csv.ParseFile(logger, filename)
|
||||
@ -91,6 +100,7 @@ func NewFromCSVFile(logger *logrus.Logger, locators map[csv.MountSpecType]lookup
|
||||
}
|
||||
|
||||
// newFromMountSpecs creates a discoverer for the CSV file. A logger is also supplied.
|
||||
// A list of csvDiscoverers is returned, with each being associated with a single MountSpecType.
|
||||
func newFromMountSpecs(logger *logrus.Logger, locators map[csv.MountSpecType]lookup.Locator, targets []*csv.MountSpec) ([]*csvDiscoverer, error) {
|
||||
var discoverers []*csvDiscoverer
|
||||
candidatesByType := make(map[csv.MountSpecType][]string)
|
||||
@ -117,6 +127,8 @@ func newFromMountSpecs(logger *logrus.Logger, locators map[csv.MountSpecType]loo
|
||||
return discoverers, nil
|
||||
}
|
||||
|
||||
// Mounts returns the discovered mounts for the csvDiscoverer.
|
||||
// Note that if the discoverer is for the device MountSpecType, the list of mounts is empty.
|
||||
func (d csvDiscoverer) Mounts() ([]Mount, error) {
|
||||
if d.mountType == csv.MountSpecDev {
|
||||
return d.None.Mounts()
|
||||
@ -125,6 +137,8 @@ func (d csvDiscoverer) Mounts() ([]Mount, error) {
|
||||
return d.mounts.Mounts()
|
||||
}
|
||||
|
||||
// Devices returns the discovered devices for the csvDiscoverer.
|
||||
// Note that if the discoverer is not for the device MountSpecType, the list of devices is empty.
|
||||
func (d csvDiscoverer) Devices() ([]Device, error) {
|
||||
if d.mountType != csv.MountSpecDev {
|
||||
return d.None.Devices()
|
||||
|
@ -62,6 +62,25 @@ func GetFileList(root string) ([]string, error) {
|
||||
return csvFilePaths, nil
|
||||
}
|
||||
|
||||
// BaseFilesOnly filters out non-base CSV files from the list of CSV files.
|
||||
func BaseFilesOnly(filenames []string) []string {
|
||||
filter := map[string]bool{
|
||||
"l4t.csv": true,
|
||||
"drivers.csv": true,
|
||||
"devices.csv": true,
|
||||
}
|
||||
|
||||
var selected []string
|
||||
for _, file := range filenames {
|
||||
base := filepath.Base(file)
|
||||
if filter[base] {
|
||||
selected = append(selected, file)
|
||||
}
|
||||
}
|
||||
|
||||
return selected
|
||||
}
|
||||
|
||||
// ParseFile parses the specified file and returns a list of required jetson mounts
|
||||
func ParseFile(logger *logrus.Logger, filename string) ([]*MountSpec, error) {
|
||||
csvFile, err := os.Open(filename)
|
||||
|
Loading…
Reference in New Issue
Block a user