Skip to content

Commit 7db9d06

Browse files
committed
Rename all instances of hostname to dnsname (with proper capitalization)
Signed-off-by: Kevin Klues <[email protected]>
1 parent dbb02c3 commit 7db9d06

File tree

3 files changed

+67
-66
lines changed

3 files changed

+67
-66
lines changed

cmd/compute-domain-daemon/hostname.go renamed to cmd/compute-domain-daemon/dnsnames.go

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,31 @@ import (
2929
)
3030

3131
const (
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
}

cmd/compute-domain-daemon/main.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ func run(ctx context.Context, cancel context.CancelFunc, flags *Flags) error {
185185
}
186186
klog.Infof("config: %v", config)
187187

188-
// Prepare Hostname manager
189-
hostnameManager := NewHostnameManager(flags.cliqueID, flags.maxNodesPerIMEXDomain, nodesConfigPath)
188+
// Prepare DNS name manager
189+
dnsNameManager := NewDNSNameManager(flags.cliqueID, flags.maxNodesPerIMEXDomain, nodesConfigPath)
190190

191-
// Create static nodes config file with hostnames
192-
if err := hostnameManager.WriteNodesConfig(); err != nil {
191+
// Create static nodes config file with DNS names
192+
if err := dnsNameManager.WriteNodesConfig(); err != nil {
193193
return fmt.Errorf("failed to create static nodes config: %w", err)
194194
}
195195

@@ -220,9 +220,9 @@ func run(ctx context.Context, cancel context.CancelFunc, flags *Flags) error {
220220
wg.Add(1)
221221
go func() {
222222
defer wg.Done()
223-
if featuregates.Enabled(featuregates.HostnameSupport) {
224-
// Use new hostname-based functionality
225-
if err := IMEXDaemonUpdateLoopWithHostnames(ctx, controller, processManager, hostnameManager); err != nil {
223+
if featuregates.Enabled(featuregates.IMEXDaemonsWithDNSNames) {
224+
// Use new DNS name-based functionality
225+
if err := IMEXDaemonUpdateLoopWithDNSNames(ctx, controller, processManager, dnsNameManager); err != nil {
226226
klog.Errorf("IMEXDaemonUpdateLoop failed, initiate shutdown: %s", err)
227227
cancel()
228228
}
@@ -277,23 +277,23 @@ func IMEXDaemonUpdateLoopWithIPs(ctx context.Context, controller *Controller, cl
277277
}
278278
}
279279

280-
// IMEXDaemonUpdateLoopWithHostnames reacts to ComputeDomain status changes by updating the
281-
// /etc/hosts file with IP to hostname mappings and restarting the IMEX daemon.
282-
func IMEXDaemonUpdateLoopWithHostnames(ctx context.Context, controller *Controller, processManager *ProcessManager, hostnameManager *HostnameManager) error {
280+
// IMEXDaemonUpdateLoopWithDNSNames reacts to ComputeDomain status changes by updating the
281+
// /etc/hosts file with IP to DNS name mappings and restarting the IMEX daemon.
282+
func IMEXDaemonUpdateLoopWithDNSNames(ctx context.Context, controller *Controller, processManager *ProcessManager, dnsNameManager *DNSNameManager) error {
283283
for {
284284
klog.Infof("wait for nodes update")
285285
select {
286286
case <-ctx.Done():
287-
klog.Infof("shutdown: stop IMEXDaemonUpdateLoopWithHostnames")
287+
klog.Infof("shutdown: stop IMEXDaemonUpdateLoopWithDNSNames")
288288
return nil
289289
case nodes := <-controller.GetNodesUpdateChan():
290-
if err := hostnameManager.UpdateHostnameMappings(nodes); err != nil {
291-
return fmt.Errorf("failed to update hostname => IP mappings: %w", err)
290+
if err := dnsNameManager.UpdateDNSNameMappings(nodes); err != nil {
291+
return fmt.Errorf("failed to update DNS name => IP mappings: %w", err)
292292
}
293293
if err := processManager.EnsureStarted(); err != nil {
294294
return fmt.Errorf("failed to ensure IMEX daemon is started: %w", err)
295295
}
296-
hostnameManager.LogHostnameMappings()
296+
dnsNameManager.LogDNSNameMappings()
297297
}
298298
}
299299
}

pkg/featuregates/featuregates.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const (
3434
// MPSSupport allows MPS (Multi-Process Service) settings to be specified.
3535
MPSSupport featuregate.Feature = "MPSSupport"
3636

37-
// HostnameSupport allows using hostnames instead of raw IPs for IMEX daemons.
38-
HostnameSupport featuregate.Feature = "HostnameSupport"
37+
// IMEXDaemonsWithDNSNames allows using DNS names instead of raw IPs for IMEX daemons.
38+
IMEXDaemonsWithDNSNames featuregate.Feature = "IMEXDaemonsWithDNSNames"
3939
)
4040

4141
// FeatureGates is a singleton representing the set of all feature gates and their values.
@@ -59,7 +59,7 @@ var defaultFeatureGates = map[featuregate.Feature]featuregate.VersionedSpecs{
5959
Version: version.MajorMinor(25, 8),
6060
},
6161
},
62-
HostnameSupport: {
62+
IMEXDaemonsWithDNSNames: {
6363
{
6464
Default: false,
6565
PreRelease: featuregate.Alpha,

0 commit comments

Comments
 (0)