Skip to content

Commit

Permalink
Allow either a resourceClaimName or a deviceClassName to be specified
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Klues <[email protected]>
  • Loading branch information
klueska committed Jan 13, 2025
1 parent 36c5d68 commit 3e51cd8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
5 changes: 4 additions & 1 deletion api/nvidia.com/resource/gpu/v1alpha1/multinode.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ type MultiNodeEnvironmentList struct {
Items []MultiNodeEnvironment `json:"items"`
}

// +kubebuilder:validation:XValidation:rule="(has(self.resourceClaimName) ? !has(self.deviceClassName) : has(self.deviceClassName))",message="Exactly one of 'resourceClaimName' or 'deviceClassName' must be set."

// MultiNodeEnvironmentSpec provides the spec for a MultiNodeEnvironment.
type MultiNodeEnvironmentSpec struct {
NumNodes int `json:"numNodes"`
ResourceClaimName string `json:"resourceClaimName"`
ResourceClaimName string `json:"resourceClaimName,omitempty"`
DeviceClassName string `json:"deviceClassName,omitempty"`
}
8 changes: 5 additions & 3 deletions cmd/nvidia-dra-controller/mnenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ func (m *MultiNodeEnvironmentManager) onMultiNodeEnvironmentAdd(obj any) error {
Controller: ptr.To(true),
}

dc, err := m.createDeviceClass("", ownerReference)
dc, err := m.createDeviceClass(mne.Spec.DeviceClassName, ownerReference)
if err != nil {
return fmt.Errorf("error creating DeviceClass '%s': %w", "<generated-name>", err)
}

if _, err := m.createResourceClaim(mne.Namespace, mne.Spec.ResourceClaimName, dc.Name, ownerReference); err != nil {
return fmt.Errorf("error creating ResourceClaim '%s/%s': %w", mne.Namespace, mne.Spec.ResourceClaimName, err)
if mne.Spec.ResourceClaimName != "" {
if _, err := m.createResourceClaim(mne.Namespace, mne.Spec.ResourceClaimName, dc.Name, ownerReference); err != nil {
return fmt.Errorf("error creating ResourceClaim '%s/%s': %w", mne.Namespace, mne.Spec.ResourceClaimName, err)
}
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@ spec:
spec:
description: MultiNodeEnvironmentSpec provides the spec for a MultiNodeEnvironment.
properties:
deviceClassName:
type: string
numNodes:
type: integer
resourceClaimName:
type: string
required:
- numNodes
- resourceClaimName
type: object
x-kubernetes-validations:
- message: Exactly one of 'resourceClaimName' or 'deviceClassName' must
be set.
rule: '(has(self.resourceClaimName) ? !has(self.deviceClassName) : has(self.deviceClassName))'
type: object
served: true
storage: true
11 changes: 0 additions & 11 deletions deployments/helm/k8s-dra-driver/templates/deviceclass-imex.yaml

This file was deleted.

0 comments on commit 3e51cd8

Please sign in to comment.