@@ -218,9 +218,16 @@ func (m *ComputeDomainManager) UpdateComputeDomainNodeInfo(ctx context.Context,
218218
219219 // If there isn't one, create one and append it to the list
220220 if nodeInfo == nil {
221+ // Get the next available index for this new node
222+ nextIndex , err := getNextAvailableIndex (newCD .Status .Nodes , m .config .maxNodesPerIMEXDomain )
223+ if err != nil {
224+ return fmt .Errorf ("error getting next available index: %w" , err )
225+ }
226+
221227 nodeInfo = & nvapi.ComputeDomainNode {
222228 Name : m .config .nodeName ,
223229 CliqueID : m .config .cliqueID ,
230+ Index : nextIndex ,
224231 }
225232 newCD .Status .Nodes = append (newCD .Status .Nodes , nodeInfo )
226233 }
@@ -243,6 +250,46 @@ func (m *ComputeDomainManager) UpdateComputeDomainNodeInfo(ctx context.Context,
243250 return nil
244251}
245252
253+ // The Index field in the Nodes section of the ComputeDomain status ensures a
254+ // consistent IP-to-DNS name mapping across all machines within a given IMEX
255+ // domain. Each node's index directly determines its DNS name using the format
256+ // "compute-domain-daemon-{index}".
257+ //
258+ // getNextAvailableIndex finds the next available index for the current node by
259+ // seeing which ones are already taken by other nodes in the ComputeDomain
260+ // status. It fills in gaps where it can, and returns an error if no index is
261+ // available within maxNodesPerIMEXDomain.
262+ //
263+ // By filling gaps in the index sequence (rather than always appending), we
264+ // maintain stable DNS names for existing nodes even when intermediate nodes
265+ // are removed from the compute domain and new ones are added.
266+ func getNextAvailableIndex (nodes []* nvapi.ComputeDomainNode , maxNodesPerIMEXDomain int ) (int , error ) {
267+ if len (nodes ) >= maxNodesPerIMEXDomain {
268+ return - 1 , fmt .Errorf ("cannot add more nodes, already at maximum (%d)" , maxNodesPerIMEXDomain )
269+ }
270+
271+ // Create a map to track used indices
272+ usedIndices := make (map [int ]bool )
273+
274+ // Collect all currently used indices
275+ for _ , node := range nodes {
276+ usedIndices [node .Index ] = true
277+ }
278+
279+ // Find the next available index, starting from 0 and filling gaps
280+ nextIndex := 0
281+ for usedIndices [nextIndex ] {
282+ nextIndex ++
283+ }
284+
285+ // Ensure nextIndex is within the range 0..maxNodesPerIMEXDomain
286+ if nextIndex < 0 || nextIndex >= maxNodesPerIMEXDomain {
287+ return - 1 , fmt .Errorf ("no available indices within maxNodesPerIMEXDomain (%d)" , maxNodesPerIMEXDomain )
288+ }
289+
290+ return nextIndex , nil
291+ }
292+
246293// If we've reached the expected number of nodes and if there was actually a
247294// change compared to the previously known set of nodes: pass info to IMEX
248295// daemon controller.
0 commit comments