@@ -29,31 +29,31 @@ import (
2929)
3030
3131const (
32- hostsFilePath = "/etc/hosts"
33- hostnameFormat = "compute-domain-daemon-%d"
32+ hostsFilePath = "/etc/hosts"
33+ dnsNameFormat = "compute-domain-daemon-%d"
3434)
3535
36- // HostnameManager manages the allocation of static hostnames to IP addresses.
37- type HostnameManager struct {
36+ // DNSNameManager manages the allocation of static DNS names to IP addresses.
37+ type DNSNameManager struct {
3838 sync.Mutex
39- ipToHostname map [string ]string
39+ ipToDNSName map [string ]string
4040 cliqueID string
4141 maxNodesPerIMEXDomain int
4242 nodesConfigPath string
4343}
4444
45- // NewHostnameManager creates a new hostname manager.
46- func NewHostnameManager (cliqueID string , maxNodesPerIMEXDomain int , nodesConfigPath string ) * HostnameManager {
47- return & HostnameManager {
48- ipToHostname : make (map [string ]string ),
45+ // NewDNSNameManager creates a new DNS name manager.
46+ func NewDNSNameManager (cliqueID string , maxNodesPerIMEXDomain int , nodesConfigPath string ) * DNSNameManager {
47+ return & DNSNameManager {
48+ ipToDNSName : make (map [string ]string ),
4949 cliqueID : cliqueID ,
5050 maxNodesPerIMEXDomain : maxNodesPerIMEXDomain ,
5151 nodesConfigPath : nodesConfigPath ,
5252 }
5353}
5454
55- // UpdateHostnameMappings updates the /etc/hosts file with IP to hostname mappings.
56- func (m * HostnameManager ) UpdateHostnameMappings (nodes []* nvapi.ComputeDomainNode ) error {
55+ // UpdateDNSNameMappings updates the /etc/hosts file with IP to DNS name mappings.
56+ func (m * DNSNameManager ) UpdateDNSNameMappings (nodes []* nvapi.ComputeDomainNode ) error {
5757 m .Lock ()
5858 defer m .Unlock ()
5959
@@ -71,83 +71,83 @@ func (m *HostnameManager) UpdateHostnameMappings(nodes []*nvapi.ComputeDomainNod
7171 currentIPs [node .IPAddress ] = true
7272 }
7373
74- for ip := range m .ipToHostname {
74+ for ip := range m .ipToDNSName {
7575 if ! currentIPs [ip ] {
76- delete (m .ipToHostname , ip )
76+ delete (m .ipToDNSName , ip )
7777 }
7878 }
7979
8080 // Add new IPs to map (filling in holes where others were removed)
8181 for _ , node := range cliqueNodes {
82- // If IP already has a hostname , skip it
83- if _ , exists := m .ipToHostname [node .IPAddress ]; exists {
82+ // If IP already has a DNS name , skip it
83+ if _ , exists := m .ipToDNSName [node .IPAddress ]; exists {
8484 continue
8585 }
8686
87- hostname , err := m .allocateHostname (node .IPAddress )
87+ dnsName , err := m .allocateDNSName (node .IPAddress )
8888 if err != nil {
89- return fmt .Errorf ("failed to allocate hostname for IP %s: %w" , node .IPAddress , err )
89+ return fmt .Errorf ("failed to allocate DNS name for IP %s: %w" , node .IPAddress , err )
9090 }
91- m .ipToHostname [node .IPAddress ] = hostname
91+ m .ipToDNSName [node .IPAddress ] = dnsName
9292 }
9393
9494 // Update the hosts file with current mappings
9595 return m .updateHostsFile ()
9696}
9797
98- // LogHostnameMappings logs the current compute-domain-daemon mappings from memory.
99- func (m * HostnameManager ) LogHostnameMappings () {
98+ // LogDNSNameMappings logs the current compute-domain-daemon mappings from memory.
99+ func (m * DNSNameManager ) LogDNSNameMappings () {
100100 m .Lock ()
101101 defer m .Unlock ()
102102
103- if len (m .ipToHostname ) == 0 {
103+ if len (m .ipToDNSName ) == 0 {
104104 klog .Infof ("No compute-domain-daemon mappings found" )
105105 return
106106 }
107107
108108 klog .Infof ("Current compute-domain-daemon mappings:" )
109- for ip , hostname := range m .ipToHostname {
110- klog .Infof (" %s -> %s" , ip , hostname )
109+ for ip , dnsName := range m .ipToDNSName {
110+ klog .Infof (" %s -> %s" , ip , dnsName )
111111 }
112112}
113113
114- // allocateHostname allocates a hostname for an IP address, reusing existing hostnames if possible.
115- func (m * HostnameManager ) allocateHostname (ip string ) (string , error ) {
116- // If IP already has a hostname , return it
117- if hostname , exists := m .ipToHostname [ip ]; exists {
118- return hostname , nil
114+ // allocateDNSName allocates a DNS name for an IP address, reusing existing DNS names if possible.
115+ func (m * DNSNameManager ) allocateDNSName (ip string ) (string , error ) {
116+ // If IP already has a DNS name , return it
117+ if dnsName , exists := m .ipToDNSName [ip ]; exists {
118+ return dnsName , nil
119119 }
120120
121- // Find the next available hostname
121+ // Find the next available DNS name
122122 for i := 0 ; i < m .maxNodesPerIMEXDomain ; i ++ {
123- hostname := fmt .Sprintf (hostnameFormat , i )
124- // Check if this hostname is already in use
123+ dnsName := fmt .Sprintf (dnsNameFormat , i )
124+ // Check if this DNS name is already in use
125125 inUse := false
126- for _ , existingHostname := range m .ipToHostname {
127- if existingHostname == hostname {
126+ for _ , existingDNSName := range m .ipToDNSName {
127+ if existingDNSName == dnsName {
128128 inUse = true
129129 break
130130 }
131131 }
132132 if ! inUse {
133- m .ipToHostname [ip ] = hostname
134- return hostname , nil
133+ m .ipToDNSName [ip ] = dnsName
134+ return dnsName , nil
135135 }
136136 }
137137
138- // If all hostnames are used, return an error
139- return "" , fmt .Errorf ("no hostnames available (max: %d)" , m .maxNodesPerIMEXDomain )
138+ // If all DNS names are used, return an error
139+ return "" , fmt .Errorf ("no DNS names available (max: %d)" , m .maxNodesPerIMEXDomain )
140140}
141141
142- // updateHostsFile updates the /etc/hosts file with current IP to hostname mappings.
143- func (m * HostnameManager ) updateHostsFile () error {
142+ // updateHostsFile updates the /etc/hosts file with current IP to DNS name mappings.
143+ func (m * DNSNameManager ) updateHostsFile () error {
144144 // Read hosts file
145145 hostsContent , err := os .ReadFile (hostsFilePath )
146146 if err != nil {
147147 return fmt .Errorf ("failed to read %s: %w" , hostsFilePath , err )
148148 }
149149
150- // Grab any lines to preserve, skipping existing hostname mappings
150+ // Grab any lines to preserve, skipping existing DNS name mappings
151151 var preservedLines []string
152152 for _ , line := range strings .Split (string (hostsContent ), "\n " ) {
153153 line = strings .TrimSpace (line )
@@ -177,9 +177,9 @@ func (m *HostnameManager) updateHostsFile() error {
177177 // Add a separator comment
178178 newHostsContent .WriteString ("# Compute Domain Daemon mappings\n " )
179179
180- // Add new hostname mappings
181- for ip , hostname := range m .ipToHostname {
182- newHostsContent .WriteString (fmt .Sprintf ("%s\t %s\n " , ip , hostname ))
180+ // Add new DNS name mappings
181+ for ip , dnsName := range m .ipToDNSName {
182+ newHostsContent .WriteString (fmt .Sprintf ("%s\t %s\n " , ip , dnsName ))
183183 }
184184
185185 // Write the updated hosts file
@@ -190,8 +190,8 @@ func (m *HostnameManager) updateHostsFile() error {
190190 return nil
191191}
192192
193- // WriteNodesConfig creates a static nodes config file with hostnames .
194- func (m * HostnameManager ) WriteNodesConfig () error {
193+ // WriteNodesConfig creates a static nodes config file with DNS names .
194+ func (m * DNSNameManager ) WriteNodesConfig () error {
195195 // Ensure the directory exists
196196 dir := filepath .Dir (m .nodesConfigPath )
197197 if err := os .MkdirAll (dir , 0755 ); err != nil {
@@ -205,14 +205,15 @@ func (m *HostnameManager) WriteNodesConfig() error {
205205 }
206206 defer f .Close ()
207207
208- // Write static hostnames
208+ // Write static DNS names
209209 for i := 0 ; i < m .maxNodesPerIMEXDomain ; i ++ {
210- hostname := fmt .Sprintf (hostnameFormat , i )
211- if _ , err := fmt .Fprintf (f , "%s\n " , hostname ); err != nil {
210+ dnsName := fmt .Sprintf (dnsNameFormat , i )
211+ if _ , err := fmt .Fprintf (f , "%s\n " , dnsName ); err != nil {
212212 return fmt .Errorf ("failed to write to nodes config file: %w" , err )
213213 }
214214 }
215215
216- klog .Infof ("Created static nodes config file with %d hostnames using format %s" , m .maxNodesPerIMEXDomain , hostnameFormat )
216+ klog .Infof ("Created static nodes config file with %d DNS names using format %s" , m .maxNodesPerIMEXDomain , dnsNameFormat )
217+
217218 return nil
218219}
0 commit comments