Skip to content

Commit b431f06

Browse files
committed
pkg/machine: do not add broken localtime symlink
The timezone might be empty so the zoneinfo link would then be invalid. Signed-off-by: Paul Holzinger <[email protected]>
1 parent 7800db6 commit b431f06

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

pkg/machine/ignition/ignition.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,36 +142,38 @@ func (ign *DynamicIgnition) GenerateIgnitionConfig() error {
142142

143143
// Add or set the time zone for the machine
144144
if len(ign.TimeZone) > 0 {
145-
var (
146-
err error
147-
tz string
148-
)
145+
var err error
146+
tz := ign.TimeZone
149147
// local means the same as the host
150148
// look up where it is pointing to on the host
151149
if ign.TimeZone == "local" {
152150
tz, err = getLocalTimeZone()
153151
if err != nil {
154152
return fmt.Errorf("error getting local timezone: %q", err)
155153
}
156-
} else {
157-
tz = ign.TimeZone
158154
}
159-
tzLink := Link{
160-
Node: Node{
161-
Group: GetNodeGrp("root"),
162-
Path: "/etc/localtime",
163-
Overwrite: BoolToPtr(false),
164-
User: GetNodeUsr("root"),
165-
},
166-
LinkEmbedded1: LinkEmbedded1{
167-
Hard: BoolToPtr(false),
168-
// We always want this value in unix form (/path/to/something) because this is being
169-
// set in the machine OS (always Linux). However, filepath.join on windows will use a "\\"
170-
// separator; therefore we use ToSlash to convert the path to unix style
171-
Target: filepath.ToSlash(filepath.Join("/usr/share/zoneinfo", tz)),
172-
},
155+
// getLocalTimeZone() can return empty string, do not add broken symlink in that case
156+
// coreos will default to UTC
157+
if tz == "" {
158+
logrus.Info("Unable to determine local timezone, machine will default to UTC")
159+
} else {
160+
tzLink := Link{
161+
Node: Node{
162+
Group: GetNodeGrp("root"),
163+
Path: "/etc/localtime",
164+
Overwrite: BoolToPtr(false),
165+
User: GetNodeUsr("root"),
166+
},
167+
LinkEmbedded1: LinkEmbedded1{
168+
Hard: BoolToPtr(false),
169+
// We always want this value in unix form (/path/to/something) because this is being
170+
// set in the machine OS (always Linux). However, filepath.join on windows will use a "\\"
171+
// separator; therefore we use ToSlash to convert the path to unix style
172+
Target: filepath.ToSlash(filepath.Join("/usr/share/zoneinfo", tz)),
173+
},
174+
}
175+
ignStorage.Links = append(ignStorage.Links, tzLink)
173176
}
174-
ignStorage.Links = append(ignStorage.Links, tzLink)
175177
}
176178

177179
// This service gets environment variables that are provided

0 commit comments

Comments
 (0)