mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
[no-relnote] Remove feature flag for per-container features
This change REMOVES the ability to set opt-in features (e.g. GDS, MOFED, GDRCOPY) in the config file. The existing per-container envvars are unaffected. Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
f794d09df1
commit
1d9d0acf7d
@ -16,70 +16,19 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
type featureName string
|
|
||||||
|
|
||||||
const (
|
|
||||||
FeatureGDS = featureName("gds")
|
|
||||||
FeatureMOFED = featureName("mofed")
|
|
||||||
FeatureNVSWITCH = featureName("nvswitch")
|
|
||||||
FeatureGDRCopy = featureName("gdrcopy")
|
|
||||||
)
|
|
||||||
|
|
||||||
// features specifies a set of named features.
|
// features specifies a set of named features.
|
||||||
type features struct {
|
type features struct {
|
||||||
GDS *feature `toml:"gds,omitempty"`
|
|
||||||
MOFED *feature `toml:"mofed,omitempty"`
|
|
||||||
NVSWITCH *feature `toml:"nvswitch,omitempty"`
|
|
||||||
GDRCopy *feature `toml:"gdrcopy,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:unused
|
||||||
type feature bool
|
type feature bool
|
||||||
|
|
||||||
// IsEnabled checks whether a specified named feature is enabled.
|
// IsEnabled checks whether a feature is explicitly enabled.
|
||||||
// An optional list of environments to check for feature-specific environment
|
//
|
||||||
// variables can also be supplied.
|
//nolint:unused
|
||||||
func (fs features) IsEnabled(n featureName, in ...getenver) bool {
|
func (f *feature) IsEnabled() bool {
|
||||||
featureEnvvars := map[featureName]string{
|
|
||||||
FeatureGDS: "NVIDIA_GDS",
|
|
||||||
FeatureMOFED: "NVIDIA_MOFED",
|
|
||||||
FeatureNVSWITCH: "NVIDIA_NVSWITCH",
|
|
||||||
FeatureGDRCopy: "NVIDIA_GDRCOPY",
|
|
||||||
}
|
|
||||||
|
|
||||||
envvar := featureEnvvars[n]
|
|
||||||
switch n {
|
|
||||||
case FeatureGDS:
|
|
||||||
return fs.GDS.isEnabled(envvar, in...)
|
|
||||||
case FeatureMOFED:
|
|
||||||
return fs.MOFED.isEnabled(envvar, in...)
|
|
||||||
case FeatureNVSWITCH:
|
|
||||||
return fs.NVSWITCH.isEnabled(envvar, in...)
|
|
||||||
case FeatureGDRCopy:
|
|
||||||
return fs.GDRCopy.isEnabled(envvar, in...)
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// isEnabled checks whether a feature is enabled.
|
|
||||||
// If the enabled value is explicitly set, this is returned, otherwise the
|
|
||||||
// associated envvar is checked in the specified getenver for the string "enabled"
|
|
||||||
// A CUDA container / image can be passed here.
|
|
||||||
func (f *feature) isEnabled(envvar string, ins ...getenver) bool {
|
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return bool(*f)
|
return bool(*f)
|
||||||
}
|
}
|
||||||
if envvar == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, in := range ins {
|
|
||||||
if in.Getenv(envvar) == "enabled" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type getenver interface {
|
|
||||||
Getenv(string) string
|
|
||||||
}
|
|
||||||
|
@ -274,3 +274,7 @@ func (i CUDA) CDIDevicesFromMounts() []string {
|
|||||||
}
|
}
|
||||||
return devices
|
return devices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i CUDA) IsEnabled(envvar string) bool {
|
||||||
|
return i.Getenv(envvar) == "enabled"
|
||||||
|
}
|
||||||
|
@ -46,7 +46,7 @@ func NewFeatureGatedModifier(logger logger.Interface, cfg *config.Config, image
|
|||||||
driverRoot := cfg.NVIDIAContainerCLIConfig.Root
|
driverRoot := cfg.NVIDIAContainerCLIConfig.Root
|
||||||
devRoot := cfg.NVIDIAContainerCLIConfig.Root
|
devRoot := cfg.NVIDIAContainerCLIConfig.Root
|
||||||
|
|
||||||
if cfg.Features.IsEnabled(config.FeatureGDS, image) {
|
if image.Getenv("NVIDIA_GDS") == "enabled" {
|
||||||
d, err := discover.NewGDSDiscoverer(logger, driverRoot, devRoot)
|
d, err := discover.NewGDSDiscoverer(logger, driverRoot, devRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to construct discoverer for GDS devices: %w", err)
|
return nil, fmt.Errorf("failed to construct discoverer for GDS devices: %w", err)
|
||||||
@ -54,7 +54,7 @@ func NewFeatureGatedModifier(logger logger.Interface, cfg *config.Config, image
|
|||||||
discoverers = append(discoverers, d)
|
discoverers = append(discoverers, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Features.IsEnabled(config.FeatureMOFED, image) {
|
if image.Getenv("NVIDIA_MOFED") == "enabled" {
|
||||||
d, err := discover.NewMOFEDDiscoverer(logger, devRoot)
|
d, err := discover.NewMOFEDDiscoverer(logger, devRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to construct discoverer for MOFED devices: %w", err)
|
return nil, fmt.Errorf("failed to construct discoverer for MOFED devices: %w", err)
|
||||||
@ -62,7 +62,7 @@ func NewFeatureGatedModifier(logger logger.Interface, cfg *config.Config, image
|
|||||||
discoverers = append(discoverers, d)
|
discoverers = append(discoverers, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Features.IsEnabled(config.FeatureNVSWITCH, image) {
|
if image.Getenv("NVIDIA_NVSWITCH") == "enabled" {
|
||||||
d, err := discover.NewNvSwitchDiscoverer(logger, devRoot)
|
d, err := discover.NewNvSwitchDiscoverer(logger, devRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to construct discoverer for NVSWITCH devices: %w", err)
|
return nil, fmt.Errorf("failed to construct discoverer for NVSWITCH devices: %w", err)
|
||||||
@ -70,7 +70,7 @@ func NewFeatureGatedModifier(logger logger.Interface, cfg *config.Config, image
|
|||||||
discoverers = append(discoverers, d)
|
discoverers = append(discoverers, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Features.IsEnabled(config.FeatureGDRCopy, image) {
|
if image.Getenv("NVIDIA_GDRCOPY") == "enabled" {
|
||||||
d, err := discover.NewGDRCopyDiscoverer(logger, devRoot)
|
d, err := discover.NewGDRCopyDiscoverer(logger, devRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to construct discoverer for GDRCopy devices: %w", err)
|
return nil, fmt.Errorf("failed to construct discoverer for GDRCopy devices: %w", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user