Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow searching $TZDIR for timezone data #21063

Closed
wants to merge 1 commit into from

Conversation

saschagrunert
Copy link
Member

@saschagrunert saschagrunert commented Dec 20, 2023

glibc supports the environment variable as additional search path, means we allow to override the /usr/share/zoneinfo path by setting the variable.

Analogous change to containers/common#1772

Does this PR introduce a user-facing change?

Added `TZDIR` environment variable support to modify the global timezone search path of `/usr/share/zoneinfo`.

Copy link
Contributor

openshift-ci bot commented Dec 20, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 20, 2023
@saschagrunert saschagrunert changed the title Allow searching $TZDIR for timezone data WIP: Allow searching $TZDIR for timezone data Dec 20, 2023
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 20, 2023
@saschagrunert saschagrunert changed the title WIP: Allow searching $TZDIR for timezone data Allow searching $TZDIR for timezone data Dec 20, 2023
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 20, 2023
glibc supports the environment variable as additional search path, means
we allow to override the `/usr/share/zoneinfo` path by setting the
variable.

Analogous change to containers/common#1772

Signed-off-by: Sascha Grunert <[email protected]>
@@ -1708,6 +1708,14 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {
tz := c.Timezone()
if tz != "" {
timezonePath := filepath.Join("/usr/share/zoneinfo", tz)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all of this come from the similar code in containers/common?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say yes, especially since we have a clone of that code in cri-o/cri-o#7589. I stated that in cri-o/cri-o#7550 (comment). For CRI-O we would like to still maintain our own config field but reuse the helper functions per cri-o/cri-o#7550 (comment).

// https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzfile.c;h=8a923d0cccc927a106dc3e3c641be310893bab4e;hb=HEAD#l149
tzdir := os.Getenv("TZDIR")
if tzdir != "" {
timezonePath = filepath.Join(tzdir, tz)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait.... this seems wrong to me, it's completely different from the append-path approach in your c-c PR. And I don't see any other basic utils if TZDIR is missing. I'm still investigating, but for now, let's block this

/hold

(Oh, also, what Dan said. We don't want two inconsistent implementations. But that might be a bigger problem)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so the question to me would be: Do we want to mimic the glibc behavior and use $TZDIR as override or do we want to place it as a higher priority path? I'm leaning towards the override.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The glibc code you linked to implements it as an override; the wording in tzset(3) seems to confirm:

TZDIR If this variable is set its value takes precedence over the system configured timezone database directory path.

Okay, so it's c-c that is wrong. It squicks me out to have podman actually error out, instead of just ignoring the error, but there's precedent (podman run --tz=Foo/Bar also fails), so okay.

Please fix it so it actually works though (my Abc/Def test above).

Thanks for your PR and for providing good reference sources.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, following-up in c/common: containers/common#1774

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 20, 2023
@@ -513,6 +513,11 @@ json-file | f
assert "$output" == "../usr/share/zoneinfo/Europe/Berlin" "localtime is linked correctly"
}

@test "podman run --tz with zoneinfo and custom TZDIR env" {
# Setting the timezone should fail because it does not exist
TZDIR="$PODMAN_TMPDIR/zoneinfo" run_podman 127 run --rm --tz Europe/Berlin "$SYSTEMD_IMAGE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please don't just do error-status checks. Error messages must be confirmed:

    assert "$output" =~ "Error: setting timezone for container .*: stat $PODMAN_TMPDIR/zoneinfo/Europe/Berlin: no such file or directory"

Also,

    skip_if_remote "TZDIR not propagated remotely"

@edsantiago
Copy link
Member

Also, it doesn't seem to be working:

$ mkdir -p /tmp/zoneinfo/Abc
$ cp /usr/share/zoneinfo/Pacific/Chatham /tmp/zoneinfo/Abc/Def

$ TZDIR=/tmp/zoneinfo TZ=Abc/Def date
Thu Dec 21 03:15:13 AM +1345 2023       <--- OK, it works on f39

$ TZDIR=/tmp/zoneinfo bin/podman run --rm --tz=Abc/Def quay.io/libpod/testimage:20221018 date
Error: running container create option: finding timezone: unknown time zone Abc/Def
^^^^^ but not with podman

@saschagrunert
Copy link
Member Author

@sohankunkerkar @rhatdan @vrothberg @edsantiago @Luap99 considering cri-o/cri-o#7589, do we want to move the timezone related bits into c/common helper functions and reuse them in CRI-O and Podman?

@sohankunkerkar
Copy link
Member

@sohankunkerkar @rhatdan @vrothberg @edsantiago @Luap99 considering cri-o/cri-o#7589, do we want to move the timezone related bits into c/common helper functions and reuse them in CRI-O and Podman?

Yeah, that's a good idea. We can reuse the setContainerTimeZone and copyTimezoneFile functions by placing them in c/common.

@saschagrunert
Copy link
Member Author

Awesome, let me close this one then and vendor c/common code once it is there.

@saschagrunert saschagrunert deleted the tzdir branch December 21, 2023 08:08
saschagrunert added a commit to saschagrunert/common that referenced this pull request Dec 21, 2023
The TZDIR environment variable override the lookup paths and does not
append them. This patch fixes that behavior and is a follow-up on:

containers#1772

Ref: containers/podman#21063 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
saschagrunert added a commit to saschagrunert/common that referenced this pull request Dec 21, 2023
The TZDIR environment variable override the lookup paths and does not
append them. This patch fixes that behavior and is a follow-up on:

containers#1772

Ref: containers/podman#21063 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
saschagrunert added a commit to saschagrunert/common that referenced this pull request Dec 21, 2023
The TZDIR environment variable override the lookup paths and does not
append them. This patch fixes that behavior and is a follow-up on:

containers#1772

Ref: containers/podman#21063 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Mar 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants