@@ -143,36 +143,43 @@ func (ign *DynamicIgnition) GenerateIgnitionConfig() error {
143
143
144
144
// Add or set the time zone for the machine
145
145
if len (ign .TimeZone ) > 0 {
146
- var (
147
- err error
148
- tz string
149
- )
146
+ var err error
147
+ tz := ign .TimeZone
150
148
// local means the same as the host
151
149
// look up where it is pointing to on the host
152
150
if ign .TimeZone == "local" {
153
- tz , err = getLocalTimeZone ()
154
- if err != nil {
155
- return fmt .Errorf ("error getting local timezone: %q" , err )
151
+ if env , ok := os .LookupEnv ("TZ" ); ok {
152
+ tz = env
153
+ } else {
154
+ tz , err = getLocalTimeZone ()
155
+ if err != nil {
156
+ return fmt .Errorf ("error getting local timezone: %q" , err )
157
+ }
156
158
}
157
- } else {
158
- tz = ign .TimeZone
159
159
}
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
- },
160
+ // getLocalTimeZone() can return empty string, do not add broken symlink in that case
161
+ // coreos will default to UTC
162
+ if tz == "" {
163
+ logrus .Info ("Unable to determine local timezone, machine will default to UTC" )
164
+ } else {
165
+ tzLink := Link {
166
+ Node : Node {
167
+ Group : GetNodeGrp ("root" ),
168
+ Path : "/etc/localtime" ,
169
+ Overwrite : BoolToPtr (false ),
170
+ User : GetNodeUsr ("root" ),
171
+ },
172
+ LinkEmbedded1 : LinkEmbedded1 {
173
+ Hard : BoolToPtr (false ),
174
+ // We always want this value in unix form (../usr/share/zoneinfo) because this is being
175
+ // set in the machine OS (always Linux) and systemd needs the relative symlink. However,
176
+ // filepath.join on windows will use a "\\" separator so use path.Join() which always
177
+ // uses the slash.
178
+ Target : path .Join ("../usr/share/zoneinfo" , tz ),
179
+ },
180
+ }
181
+ ignStorage .Links = append (ignStorage .Links , tzLink )
174
182
}
175
- ignStorage .Links = append (ignStorage .Links , tzLink )
176
183
}
177
184
178
185
// This service gets environment variables that are provided
0 commit comments