@@ -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
0 commit comments