Skip to content

Commit

Permalink
Merge pull request #65 from bart0sh/PR003-add-num-devices-parameter
Browse files Browse the repository at this point in the history
add num-devices parameter
  • Loading branch information
k8s-ci-robot authored Sep 30, 2024
2 parents 303c1d2 + 009b41f commit 2713efd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 1 addition & 2 deletions cmd/dra-example-kubeletplugin/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (
"github.com/google/uuid"
)

func enumerateAllPossibleDevices() (AllocatableDevices, error) {
numGPUs := 8
func enumerateAllPossibleDevices(numGPUs int) (AllocatableDevices, error) {
seed := os.Getenv("NODE_NAME")
uuids := generateUUIDs(seed, numGPUs)

Expand Down
12 changes: 10 additions & 2 deletions cmd/dra-example-kubeletplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ type Flags struct {
kubeClientConfig flags.KubeClientConfig
loggingConfig *flags.LoggingConfig

nodeName string
cdiRoot string
nodeName string
cdiRoot string
numDevices int
}

type Config struct {
Expand Down Expand Up @@ -79,6 +80,13 @@ func newApp() *cli.App {
Destination: &flags.cdiRoot,
EnvVars: []string{"CDI_ROOT"},
},
&cli.IntFlag{
Name: "num-devices",
Usage: "The number of devices to be generated.",
Value: 8,
Destination: &flags.numDevices,
EnvVars: []string{"NUM_DEVICES"},
},
}
cliFlags = append(cliFlags, flags.kubeClientConfig.Flags()...)
cliFlags = append(cliFlags, flags.loggingConfig.Flags()...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dra-example-kubeletplugin/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type DeviceState struct {
}

func NewDeviceState(config *Config) (*DeviceState, error) {
allocatable, err := enumerateAllPossibleDevices()
allocatable, err := enumerateAllPossibleDevices(config.flags.numDevices)
if err != nil {
return nil, fmt.Errorf("error enumerating all possible devices: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# Simulated number of devices the example driver will pretend to have.
- name: NUM_DEVICES
value: "8"
volumeMounts:
- name: plugins-registry
mountPath: /var/lib/kubelet/plugins_registry
Expand Down

0 comments on commit 2713efd

Please sign in to comment.