Skip to content

Commit 8b17bb2

Browse files
authored
Merge pull request #618 from klueska/fix-cd-node-index
Fix bug in generation of compute domain node index
2 parents b332500 + 57f0e92 commit 8b17bb2

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

api/nvidia.com/resource/v1beta1/computedomain.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ type ComputeDomainNode struct {
9494
CliqueID string `json:"cliqueID"`
9595
// The Index field is used to ensure a consistent IP-to-DNS name
9696
// mapping across all machines within an IMEX domain. Each node's index
97-
// directly determines its DNS name. It is marked as optional (but not
97+
// directly determines its DNS name within a given NVLink partition
98+
// (i.e. clique). In other words, the 2-tuple of (CliqueID, Index) will
99+
// always be unique. This field is marked as optional (but not
98100
// omitempty) in order to support downgrades and avoid an API bump.
99101
// +kubebuilder:validation:Optional
100102
Index int `json:"index"`

cmd/compute-domain-daemon/computedomain.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (m *ComputeDomainManager) UpdateComputeDomainNodeInfo(ctx context.Context,
245245
// If there isn't one, create one and append it to the list
246246
if nodeInfo == nil {
247247
// Get the next available index for this new node
248-
nextIndex, err := getNextAvailableIndex(newCD.Status.Nodes, m.config.maxNodesPerIMEXDomain)
248+
nextIndex, err := getNextAvailableIndex(m.config.cliqueID, newCD.Status.Nodes, m.config.maxNodesPerIMEXDomain)
249249
if err != nil {
250250
return fmt.Errorf("error getting next available index: %w", err)
251251
}
@@ -286,22 +286,26 @@ func (m *ComputeDomainManager) UpdateComputeDomainNodeInfo(ctx context.Context,
286286
//
287287
// getNextAvailableIndex finds the next available index for the current node by
288288
// seeing which ones are already taken by other nodes in the ComputeDomain
289-
// status. It fills in gaps where it can, and returns an error if no index is
290-
// available within maxNodesPerIMEXDomain.
289+
// status that have the same cliqueID. It fills in gaps where it can, and returns
290+
// an error if no index is available within maxNodesPerIMEXDomain.
291291
//
292292
// By filling gaps in the index sequence (rather than always appending), we
293293
// maintain stable DNS names for existing nodes even when intermediate nodes
294294
// are removed from the compute domain and new ones are added.
295-
func getNextAvailableIndex(nodes []*nvapi.ComputeDomainNode, maxNodesPerIMEXDomain int) (int, error) {
296-
if len(nodes) >= maxNodesPerIMEXDomain {
297-
return -1, fmt.Errorf("cannot add more nodes, already at maximum (%d)", maxNodesPerIMEXDomain)
295+
func getNextAvailableIndex(currentCliqueID string, nodes []*nvapi.ComputeDomainNode, maxNodesPerIMEXDomain int) (int, error) {
296+
// Filter nodes to only consider those with the same cliqueID
297+
var cliqueNodes []*nvapi.ComputeDomainNode
298+
for _, node := range nodes {
299+
if node.CliqueID == currentCliqueID {
300+
cliqueNodes = append(cliqueNodes, node)
301+
}
298302
}
299303

300304
// Create a map to track used indices
301305
usedIndices := make(map[int]bool)
302306

303-
// Collect all currently used indices
304-
for _, node := range nodes {
307+
// Collect all currently used indices from nodes with the same cliqueID
308+
for _, node := range cliqueNodes {
305309
usedIndices[node.Index] = true
306310
}
307311

@@ -313,7 +317,7 @@ func getNextAvailableIndex(nodes []*nvapi.ComputeDomainNode, maxNodesPerIMEXDoma
313317

314318
// Ensure nextIndex is within the range 0..maxNodesPerIMEXDomain
315319
if nextIndex < 0 || nextIndex >= maxNodesPerIMEXDomain {
316-
return -1, fmt.Errorf("no available indices within maxNodesPerIMEXDomain (%d)", maxNodesPerIMEXDomain)
320+
return -1, fmt.Errorf("no available indices within maxNodesPerIMEXDomain (%d) for cliqueID %s", maxNodesPerIMEXDomain, currentCliqueID)
317321
}
318322

319323
return nextIndex, nil

deployments/helm/nvidia-dra-driver-gpu/crds/resource.nvidia.com_computedomains.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ spec:
8888
description: |-
8989
The Index field is used to ensure a consistent IP-to-DNS name
9090
mapping across all machines within an IMEX domain. Each node's index
91-
directly determines its DNS name. It is marked as optional (but not
91+
directly determines its DNS name within a given NVLink partition
92+
(i.e. clique). In other words, the 2-tuple of (CliqueID, Index) will
93+
always be unique. This field is marked as optional (but not
9294
omitempty) in order to support downgrades and avoid an API bump.
9395
type: integer
9496
ipAddress:

0 commit comments

Comments
 (0)