Skip to content

Commit

Permalink
Merge pull request #988 from ArangoGutierrez/devel/EnvVar
Browse files Browse the repository at this point in the history
[no-relnote] Rename all variables from Envvar to EnvVar
  • Loading branch information
ArangoGutierrez authored Oct 10, 2024
2 parents 7a7d659 + 11a9c38 commit 8fd4b8f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/mps-control-daemon
/releases
deployments/helm/gpu-feature-discovery
cmd/gpu-feature-discovery/gfd-test-loop
e2e_logs

*.out
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ deploying the plugin via `helm`.

### As command line flags or envvars

| Flag | Envvar | Default Value |
| Flag | Environment Variable | Default Value |
|--------------------------|-------------------------|-----------------|
| `--mig-strategy` | `$MIG_STRATEGY` | `"none"` |
| `--fail-on-init-error` | `$FAIL_ON_INIT_ERROR` | `true` |
Expand Down
2 changes: 1 addition & 1 deletion api/config/v1/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (

// Constants to represent the various device list strategies
const (
DeviceListStrategyEnvvar = "envvar"
DeviceListStrategyEnvVar = "envvar"
DeviceListStrategyVolumeMounts = "volume-mounts"
DeviceListStrategyCDIAnnotations = "cdi-annotations"
DeviceListStrategyCDICRI = "cdi-cri"
Expand Down
2 changes: 1 addition & 1 deletion api/config/v1/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type DeviceListStrategies map[string]bool
// NewDeviceListStrategies constructs a new DeviceListStrategy
func NewDeviceListStrategies(strategies []string) (DeviceListStrategies, error) {
ret := map[string]bool{
DeviceListStrategyEnvvar: false,
DeviceListStrategyEnvVar: false,
DeviceListStrategyVolumeMounts: false,
DeviceListStrategyCDIAnnotations: false,
DeviceListStrategyCDICRI: false,
Expand Down
8 changes: 4 additions & 4 deletions cmd/mps-control-daemon/mps/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (e envvars) toSlice() []string {
return envs
}

// Envvars returns the environment variables required for the daemon.
// EnvVars returns the environment variables required for the daemon.
// These should be passed to clients consuming the device shared using MPS.
// TODO: Set CUDA_VISIBLE_DEVICES to include only the devices for this resource type.
func (d *Daemon) Envvars() envvars {
func (d *Daemon) EnvVars() envvars {
return map[string]string{
"CUDA_MPS_PIPE_DIRECTORY": d.PipeDir(),
"CUDA_MPS_LOG_DIRECTORY": d.LogDir(),
Expand Down Expand Up @@ -111,7 +111,7 @@ func (d *Daemon) Start() error {
}

mpsDaemon := exec.Command(mpsControlBin, "-d")
mpsDaemon.Env = append(mpsDaemon.Env, d.Envvars().toSlice()...)
mpsDaemon.Env = append(mpsDaemon.Env, d.EnvVars().toSlice()...)
if err := mpsDaemon.Run(); err != nil {
return err
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func (d *Daemon) EchoPipeToControl(command string) (string, error) {
defer reader.Close()

mpsDaemon := exec.Command(mpsControlBin)
mpsDaemon.Env = append(mpsDaemon.Env, d.Envvars().toSlice()...)
mpsDaemon.Env = append(mpsDaemon.Env, d.EnvVars().toSlice()...)

mpsDaemon.Stdin = reader
mpsDaemon.Stdout = &out
Expand Down
2 changes: 1 addition & 1 deletion cmd/nvidia-device-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func main() {
},
&cli.StringSliceFlag{
Name: "device-list-strategy",
Value: cli.NewStringSlice(string(spec.DeviceListStrategyEnvvar)),
Value: cli.NewStringSlice(string(spec.DeviceListStrategyEnvVar)),
Usage: "the desired strategy for passing the device list to the underlying runtime:\n\t\t[envvar | volume-mounts | cdi-annotations]",
EnvVars: []string{"DEVICE_LIST_STRATEGY"},
},
Expand Down
16 changes: 8 additions & 8 deletions internal/plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
type NvidiaDevicePlugin struct {
rm rm.ResourceManager
config *spec.Config
deviceListEnvvar string
deviceListEnvVar string
deviceListStrategies spec.DeviceListStrategies
socket string
kubeletSocket string
Expand Down Expand Up @@ -94,7 +94,7 @@ func NewNvidiaDevicePlugin(config *spec.Config, kubeletSocket string, resourceMa
plugin := NvidiaDevicePlugin{
rm: resourceManager,
config: config,
deviceListEnvvar: "NVIDIA_VISIBLE_DEVICES",
deviceListEnvVar: "NVIDIA_VISIBLE_DEVICES",
deviceListStrategies: deviceListStrategies,
socket: pluginPath + ".sock",
cdiHandler: cdiHandler,
Expand Down Expand Up @@ -362,8 +362,8 @@ func (plugin *NvidiaDevicePlugin) getAllocateResponse(requestIds []string) (*plu
return response, nil
}

if plugin.deviceListStrategies.Includes(spec.DeviceListStrategyEnvvar) {
plugin.updateResponseForDeviceListEnvvar(response, deviceIDs...)
if plugin.deviceListStrategies.Includes(spec.DeviceListStrategyEnvVar) {
plugin.updateResponseForDeviceListEnvVar(response, deviceIDs...)
}
if plugin.deviceListStrategies.Includes(spec.DeviceListStrategyVolumeMounts) {
plugin.updateResponseForDeviceMounts(response, deviceIDs...)
Expand Down Expand Up @@ -497,14 +497,14 @@ func (plugin *NvidiaDevicePlugin) apiDevices() []*pluginapi.Device {
return plugin.rm.Devices().GetPluginDevices()
}

// updateResponseForDeviceListEnvvar sets the environment variable for the requested devices.
func (plugin *NvidiaDevicePlugin) updateResponseForDeviceListEnvvar(response *pluginapi.ContainerAllocateResponse, deviceIDs ...string) {
response.Envs[plugin.deviceListEnvvar] = strings.Join(deviceIDs, ",")
// updateResponseForDeviceListEnvVar sets the environment variable for the requested devices.
func (plugin *NvidiaDevicePlugin) updateResponseForDeviceListEnvVar(response *pluginapi.ContainerAllocateResponse, deviceIDs ...string) {
response.Envs[plugin.deviceListEnvVar] = strings.Join(deviceIDs, ",")
}

// updateResponseForDeviceMounts sets the mounts required to request devices if volume mounts are used.
func (plugin *NvidiaDevicePlugin) updateResponseForDeviceMounts(response *pluginapi.ContainerAllocateResponse, deviceIDs ...string) {
plugin.updateResponseForDeviceListEnvvar(response, deviceListAsVolumeMountsContainerPathRoot)
plugin.updateResponseForDeviceListEnvVar(response, deviceListAsVolumeMountsContainerPathRoot)
for _, id := range deviceIDs {
mount := &pluginapi.Mount{
HostPath: deviceListAsVolumeMountsHostPath,
Expand Down

0 comments on commit 8fd4b8f

Please sign in to comment.