Skip to content

Commit

Permalink
fix: pick first interface valid hostname (vs. last one)
Browse files Browse the repository at this point in the history
Looks like the code before change in siderolabs#1578 returned the first hostname
found while interating over interfaces and addressing methods, but siderolabs#1578
supposedly inadvertently flipped that to iterate over all interfaces (so
last interface wins).

Problem is that both `DHCP` and `Static` addressing methods provide
hostnames, while DHCP hostname comes from DHCP server, while `Static`
defines hostname as `talos-10-5-0-2` (by IP).

If we were to fix it for real, we should build a list of hostname with
priorities coming from different sources and pick a hostname with the
highest priority, so this fix is more of a bandaid rather than a real
fix.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Jan 12, 2021
1 parent 275ca76 commit af5c34b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/app/networkd/pkg/networkd/networkd.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func (n *Networkd) decideHostname() (hostname, domainname string, address net.IP

// Loop through address responses and use the first hostname
// and address response.
outer:
for _, intName := range interfaceNames {
iface := n.Interfaces[intName]

Expand All @@ -329,7 +330,7 @@ func (n *Networkd) decideHostname() (hostname, domainname string, address net.IP

address = method.Address().IP

break
break outer
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/app/networkd/pkg/networkd/networkd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ func dhcpConfigFile() config.Provider {
{
DeviceInterface: "eth0",
},
{
DeviceInterface: "eth1",
DeviceCIDR: "192.168.0.10/24",
DeviceMTU: 9100,
},
},
},
},
Expand Down

0 comments on commit af5c34b

Please sign in to comment.