Skip to content

Commit 9894ba5

Browse files
authored
Fix logic error in hostname overriding (#305)
1 parent 2ee49ef commit 9894ba5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

phase/gather_facts.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ func (p *GatherFacts) investigateHost(h *cluster.Host) error {
3434
h.Metadata.Arch = output
3535
p.IncProp(h.Metadata.Arch)
3636

37-
extra := h.InstallFlags.GetValue("--kubelet-extra-args")
38-
if extra != "" {
37+
if extra := h.InstallFlags.GetValue("--kubelet-extra-args"); extra != "" {
3938
ef := cluster.Flags{extra}
4039
if over := ef.GetValue("--hostname-override"); over != "" {
41-
if h.HostnameOverride != over {
40+
if h.HostnameOverride != "" && h.HostnameOverride != over {
4241
return fmt.Errorf("hostname and installFlags kubelet-extra-args hostname-override mismatch, only define either one")
4342
}
4443
h.HostnameOverride = over
@@ -49,8 +48,12 @@ func (p *GatherFacts) investigateHost(h *cluster.Host) error {
4948
log.Infof("%s: using %s from configuration as hostname", h, h.HostnameOverride)
5049
h.Metadata.Hostname = h.HostnameOverride
5150
} else {
52-
h.Metadata.Hostname = h.Configurer.Hostname(h)
53-
log.Infof("%s: using %s as hostname", h, h.Metadata.Hostname)
51+
n := h.Configurer.Hostname(h)
52+
if n == "" {
53+
return fmt.Errorf("%s: failed to resolve a hostname", h)
54+
}
55+
h.Metadata.Hostname = n
56+
log.Infof("%s: using %s as hostname", h, n)
5457
}
5558

5659
if h.PrivateAddress == "" {

0 commit comments

Comments
 (0)