Skip to content

Commit 2713efd

Browse files
authored
Merge pull request #65 from bart0sh/PR003-add-num-devices-parameter
add num-devices parameter
2 parents 303c1d2 + 009b41f commit 2713efd

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

cmd/dra-example-kubeletplugin/discovery.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import (
2828
"github.com/google/uuid"
2929
)
3030

31-
func enumerateAllPossibleDevices() (AllocatableDevices, error) {
32-
numGPUs := 8
31+
func enumerateAllPossibleDevices(numGPUs int) (AllocatableDevices, error) {
3332
seed := os.Getenv("NODE_NAME")
3433
uuids := generateUUIDs(seed, numGPUs)
3534

cmd/dra-example-kubeletplugin/main.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ type Flags struct {
4444
kubeClientConfig flags.KubeClientConfig
4545
loggingConfig *flags.LoggingConfig
4646

47-
nodeName string
48-
cdiRoot string
47+
nodeName string
48+
cdiRoot string
49+
numDevices int
4950
}
5051

5152
type Config struct {
@@ -79,6 +80,13 @@ func newApp() *cli.App {
7980
Destination: &flags.cdiRoot,
8081
EnvVars: []string{"CDI_ROOT"},
8182
},
83+
&cli.IntFlag{
84+
Name: "num-devices",
85+
Usage: "The number of devices to be generated.",
86+
Value: 8,
87+
Destination: &flags.numDevices,
88+
EnvVars: []string{"NUM_DEVICES"},
89+
},
8290
}
8391
cliFlags = append(cliFlags, flags.kubeClientConfig.Flags()...)
8492
cliFlags = append(cliFlags, flags.loggingConfig.Flags()...)

cmd/dra-example-kubeletplugin/state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type DeviceState struct {
6363
}
6464

6565
func NewDeviceState(config *Config) (*DeviceState, error) {
66-
allocatable, err := enumerateAllPossibleDevices()
66+
allocatable, err := enumerateAllPossibleDevices(config.flags.numDevices)
6767
if err != nil {
6868
return nil, fmt.Errorf("error enumerating all possible devices: %v", err)
6969
}

deployments/helm/dra-example-driver/templates/kubeletplugin.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ spec:
5353
valueFrom:
5454
fieldRef:
5555
fieldPath: metadata.namespace
56+
# Simulated number of devices the example driver will pretend to have.
57+
- name: NUM_DEVICES
58+
value: "8"
5659
volumeMounts:
5760
- name: plugins-registry
5861
mountPath: /var/lib/kubelet/plugins_registry

0 commit comments

Comments
 (0)