Skip to content

Commit

Permalink
cmd/initContainer: Unbreak 'enter' on hosts without a /etc/localtime
Browse files Browse the repository at this point in the history
It's not mandatory to have a /etc/localtime. If it's absent then it
means that the UTC timezone is being used. One such example of an
operating system is Fedora CoreOS.

Fallout from b9a0bd5

#656
  • Loading branch information
debarshiray committed Jan 4, 2021
1 parent a0b5987 commit d231919
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/cmd/initContainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,14 @@ func sanitizeRedirectionTarget(target string) string {
func updateTimeZoneFromLocalTime() error {
localTimeEvaled, err := filepath.EvalSymlinks("/etc/localtime")
if err != nil {
if os.IsNotExist(err) {
if err := writeTimeZone("UTC"); err != nil {
return err
}

return nil
}

return fmt.Errorf("failed to resolve /etc/localtime: %w", err)
}

Expand All @@ -605,6 +613,14 @@ func updateTimeZoneFromLocalTime() error {
return fmt.Errorf("failed to extract time zone: %w", err)
}

if err := writeTimeZone(timeZone); err != nil {
return err
}

return nil
}

func writeTimeZone(timeZone string) error {
const etcTimeZone = "/etc/timezone"

if err := os.Remove(etcTimeZone); err != nil {
Expand All @@ -614,8 +630,7 @@ func updateTimeZoneFromLocalTime() error {
}

timeZoneBytes := []byte(timeZone + "\n")
err = ioutil.WriteFile(etcTimeZone, timeZoneBytes, 0664)
if err != nil {
if err := ioutil.WriteFile(etcTimeZone, timeZoneBytes, 0664); err != nil {
return fmt.Errorf("failed to create new %s: %w", etcTimeZone, err)
}

Expand Down

0 comments on commit d231919

Please sign in to comment.