@@ -30,7 +30,6 @@ import (
3030)
3131
3232const (
33- maxDNSNames = 18
3433 hostsFilePath = "/etc/hosts"
3534 dnsNamePrefix = "compute-domain-daemon-"
3635 dnsNameFormat = dnsNamePrefix + "%d"
@@ -42,17 +41,19 @@ type IPToDNSNameMap map[string]string
4241// DNSNameManager manages the allocation of static DNS names to IP addresses.
4342type DNSNameManager struct {
4443 sync.Mutex
45- ipToDNSName IPToDNSNameMap
46- cliqueID string
47- nodesConfigPath string
44+ ipToDNSName IPToDNSNameMap
45+ cliqueID string
46+ maxNodesPerIMEXDomain int
47+ nodesConfigPath string
4848}
4949
5050// NewDNSNameManager creates a new DNS name manager.
51- func NewDNSNameManager (cliqueID string , nodesConfigPath string ) * DNSNameManager {
51+ func NewDNSNameManager (cliqueID string , maxNodesPerIMEXDomain int , nodesConfigPath string ) * DNSNameManager {
5252 return & DNSNameManager {
53- ipToDNSName : make (IPToDNSNameMap ),
54- cliqueID : cliqueID ,
55- nodesConfigPath : nodesConfigPath ,
53+ ipToDNSName : make (IPToDNSNameMap ),
54+ cliqueID : cliqueID ,
55+ maxNodesPerIMEXDomain : maxNodesPerIMEXDomain ,
56+ nodesConfigPath : nodesConfigPath ,
5657 }
5758}
5859
@@ -135,7 +136,7 @@ func (m *DNSNameManager) allocateDNSName(ip string) (string, error) {
135136 }
136137
137138 // Find the next available DNS name
138- for i := 0 ; i < maxDNSNames ; i ++ {
139+ for i := 0 ; i < m . maxNodesPerIMEXDomain ; i ++ {
139140 dnsName := fmt .Sprintf (dnsNameFormat , i )
140141 // Check if this DNS name is already in use
141142 inUse := false
@@ -152,7 +153,7 @@ func (m *DNSNameManager) allocateDNSName(ip string) (string, error) {
152153 }
153154
154155 // If all DNS names are used, return an error
155- return "" , fmt .Errorf ("no DNS names available (max: %d)" , maxDNSNames )
156+ return "" , fmt .Errorf ("no DNS names available (max: %d)" , m . maxNodesPerIMEXDomain )
156157}
157158
158159// updateHostsFile updates the /etc/hosts file with current IP to DNS name mappings.
@@ -216,14 +217,14 @@ func (m *DNSNameManager) WriteNodesConfig() error {
216217 defer f .Close ()
217218
218219 // Write static DNS names
219- for i := 0 ; i < maxDNSNames ; i ++ {
220+ for i := 0 ; i < m . maxNodesPerIMEXDomain ; i ++ {
220221 dnsName := fmt .Sprintf (dnsNameFormat , i )
221222 if _ , err := fmt .Fprintf (f , "%s\n " , dnsName ); err != nil {
222223 return fmt .Errorf ("failed to write to nodes config file: %w" , err )
223224 }
224225 }
225226
226- klog .Infof ("Created static nodes config file with %d DNS names using format %s" , maxDNSNames , dnsNameFormat )
227+ klog .Infof ("Created static nodes config file with %d DNS names using format %s" , m . maxNodesPerIMEXDomain , dnsNameFormat )
227228
228229 return nil
229230}
0 commit comments