Skip to content

Commit 9ce7087

Browse files
Merge pull request #26026 from baude/issue25950
Do not error on tz detection
2 parents d8d0913 + d7eaf42 commit 9ce7087

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

pkg/machine/ignition/ignition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (ign *DynamicIgnition) GenerateIgnitionConfig() error {
151151
if ign.TimeZone == "local" {
152152
tz, err = getLocalTimeZone()
153153
if err != nil {
154-
return err
154+
return fmt.Errorf("error getting local timezone: %q", err)
155155
}
156156
} else {
157157
tz = ign.TimeZone
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
package ignition
22

33
import (
4-
"errors"
54
"os"
65
"os/exec"
76
"strings"
7+
8+
"github.com/sirupsen/logrus"
89
)
910

1011
func getLocalTimeZone() (string, error) {
12+
trimTzFunc := func(s string) string {
13+
return strings.TrimPrefix(strings.TrimSuffix(s, "\n"), "Timezone=")
14+
}
15+
16+
// perform a variety of ways to see if we can determine the tz
1117
output, err := exec.Command("timedatectl", "show", "--property=Timezone").Output()
12-
if errors.Is(err, exec.ErrNotFound) {
13-
output, err = os.ReadFile("/etc/timezone")
18+
if err == nil {
19+
return trimTzFunc(string(output)), nil
1420
}
15-
if err != nil {
16-
return "", err
21+
logrus.Debugf("Timedatectl show --property=Timezone failed: %s", err)
22+
output, err = os.ReadFile("/etc/timezone")
23+
if err == nil {
24+
return trimTzFunc(string(output)), nil
1725
}
18-
// Remove prepended field and the newline
19-
return strings.TrimPrefix(strings.TrimSuffix(string(output), "\n"), "Timezone="), nil
26+
logrus.Debugf("unable to read /etc/timezone, falling back to empty timezone: %s", err)
27+
// if we cannot determine the tz, return empty string
28+
return "", nil
2029
}

0 commit comments

Comments
 (0)