diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-12-16 22:37:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-16 22:37:49 +0100 |
commit | 52d5f367b144f755dd20b18d88c5f79bc6b0c3fe (patch) | |
tree | e0e87c0e5e7861960107a697bcf01c2d6ebfe72c /pkg | |
parent | 2c98694559b6413ec4f9abdb6d3750b6dd46cc4f (diff) | |
parent | a86495ea6fdd56519afc65586c0f7f9c0f4f5ab2 (diff) | |
download | podman-52d5f367b144f755dd20b18d88c5f79bc6b0c3fe.tar.gz podman-52d5f367b144f755dd20b18d88c5f79bc6b0c3fe.tar.bz2 podman-52d5f367b144f755dd20b18d88c5f79bc6b0c3fe.zip |
Merge pull request #12609 from baude/tz
Set machine timezone
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/machine/config.go | 1 | ||||
-rw-r--r-- | pkg/machine/ignition.go | 33 | ||||
-rw-r--r-- | pkg/machine/ignition_darwin.go | 16 | ||||
-rw-r--r-- | pkg/machine/ignition_linux.go | 15 | ||||
-rw-r--r-- | pkg/machine/qemu/machine.go | 2 |
5 files changed, 67 insertions, 0 deletions
diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 55d5dd7b4..e5e701303 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -21,6 +21,7 @@ type InitOptions struct { IsDefault bool Memory uint64 Name string + TimeZone string URI url.URL Username string } diff --git a/pkg/machine/ignition.go b/pkg/machine/ignition.go index 5c465d37d..9368cc8ed 100644 --- a/pkg/machine/ignition.go +++ b/pkg/machine/ignition.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "net/url" + "path/filepath" ) /* @@ -44,6 +45,7 @@ func getNodeGrp(grpName string) NodeGroup { type DynamicIgnition struct { Name string Key string + TimeZone string VMName string WritePath string } @@ -76,6 +78,37 @@ func NewIgnitionFile(ign DynamicIgnition) error { Links: getLinks(ign.Name), } + // Add or set the time zone for the machine + if len(ign.TimeZone) > 0 { + var ( + err error + tz string + ) + // local means the same as the host + // lookup where it is pointing to on the host + if ign.TimeZone == "local" { + tz, err = getLocalTimeZone() + if err != nil { + return err + } + } else { + tz = ign.TimeZone + } + tzLink := Link{ + Node: Node{ + Group: getNodeGrp("root"), + Path: "/etc/localtime", + Overwrite: boolToPtr(false), + User: getNodeUsr("root"), + }, + LinkEmbedded1: LinkEmbedded1{ + Hard: boolToPtr(false), + Target: filepath.Join("/usr/share/zoneinfo", tz), + }, + } + ignStorage.Links = append(ignStorage.Links, tzLink) + } + // ready is a unit file that sets up the virtual serial device // where when the VM is done configuring, it will send an ack // so a listening host knows it can being interacting with it diff --git a/pkg/machine/ignition_darwin.go b/pkg/machine/ignition_darwin.go new file mode 100644 index 000000000..9ede4b026 --- /dev/null +++ b/pkg/machine/ignition_darwin.go @@ -0,0 +1,16 @@ +//+build darwin + +package machine + +import ( + "os" + "strings" +) + +func getLocalTimeZone() (string, error) { + tzPath, err := os.Readlink("/etc/localtime") + if err != nil { + return "", err + } + return strings.TrimPrefix(tzPath, "/var/db/timezone/zoneinfo"), nil +} diff --git a/pkg/machine/ignition_linux.go b/pkg/machine/ignition_linux.go new file mode 100644 index 000000000..6db5a8e7a --- /dev/null +++ b/pkg/machine/ignition_linux.go @@ -0,0 +1,15 @@ +package machine + +import ( + "os/exec" + "strings" +) + +func getLocalTimeZone() (string, error) { + output, err := exec.Command("timedatectl", "show", "--property=Timezone").Output() + if err != nil { + return "", err + } + // Remove prepended field and the newline + return strings.TrimPrefix(strings.TrimSuffix(string(output), "\n"), "Timezone="), nil +} diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 57c32bf74..19cd131e1 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -145,6 +145,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) error { // Get image as usual v.ImageStream = opts.ImagePath dd, err := machine.NewFcosDownloader(vmtype, v.Name, opts.ImagePath) + if err != nil { return err } @@ -235,6 +236,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) error { Name: opts.Username, Key: key, VMName: v.Name, + TimeZone: opts.TimeZone, WritePath: v.IgnitionFilePath, } return machine.NewIgnitionFile(ign) |