fix: evaluate schedules in the cronjob's spec.timeZone (#428)
Unbound Release / Check Preconditions (push) Successful in 3s
Unbound Release / Create Tag (push) Skipped
Unbound Release / Create Release (push) Successful in 15s
Unbound Release / Generate Changelog and Handle PR (push) Successful in 17s
Release / release (push) Successful in 21s
cron-checker / test (push) Successful in 2m12s
cron-checker / vulnerabilities (push) Successful in 2m15s
cron-checker / build (push) Successful in 50s
Unbound Release / Check Preconditions (push) Successful in 3s
Unbound Release / Create Tag (push) Skipped
Unbound Release / Create Release (push) Successful in 15s
Unbound Release / Generate Changelog and Handle PR (push) Successful in 17s
Release / release (push) Successful in 21s
cron-checker / test (push) Successful in 2m12s
cron-checker / vulnerabilities (push) Successful in 2m15s
cron-checker / build (push) Successful in 50s
Schedules were always evaluated in UTC because `schedule.Next` uses the location of `lastScheduleTime`, which the API returns in UTC. A CronJob with `spec.timeZone` set was therefore reported as not running every day. For example, Paidit's `prod/dayclose` runs at `0 7 * * *` Europe/Stockholm: it ran at 05:00Z, but cron-checker expected 07:00Z and alerted every minute from 09:02 local time. - Convert `since` to the CronJob's `spec.timeZone` before computing the next run. CronJobs without a `timeZone` behave as before. - An invalid time zone returns an error, the same way an invalid schedule does. - Embed `time/tzdata`, because the image is `FROM scratch` and has no zoneinfo. - Tests: an invalid time zone, and a time-zone case that fails without the fix. - Bumped golang.org/x/net to v0.60.0. govulncheck was already failing on main with five x/net advisories, which blocks the build job. - Bumped the go toolchain to 1.27.2 for eight stdlib advisories. This is the same change as Renovate #427, which will close once this is merged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01C8SW6vsbkrTKjLNatQ8JTg Reviewed-on: https://gitea.unbound.se/unboundsoftware/cron-checker/pulls/428
This commit was merged in pull request #428.
This commit is contained in:
1 parent
40311eaeaa
commit
52d52a222c
4 files changed
+88
-16
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
_ "time/tzdata" // the image is FROM scratch, so embed zoneinfo for spec.timeZone
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/multiplay/go-slack/chat"
|
||||
@@ -19,8 +20,10 @@ import (
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
var checkFunc = doCheck
|
||||
var exitFunc = os.Exit
|
||||
var (
|
||||
checkFunc = doCheck
|
||||
exitFunc = os.Exit
|
||||
)
|
||||
|
||||
func main() {
|
||||
slackUrl := kingpin.Flag("slack-url", "The Slack Webhook URL").Envar("SLACK_URL").Required().String()
|
||||
@@ -68,6 +71,14 @@ func doCheck(client Client, slackUrl string, ic chan os.Signal, sleepTime time.D
|
||||
if c.Status.LastScheduleTime != nil {
|
||||
since = *c.Status.LastScheduleTime
|
||||
}
|
||||
// The schedule is evaluated in the location of since, so use the cronjob's time zone (UTC if unset)
|
||||
if c.Spec.TimeZone != nil {
|
||||
loc, err := time.LoadLocation(*c.Spec.TimeZone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading time zone of %s/%s (%s): %w", c.Namespace, c.Name, *c.Spec.TimeZone, err)
|
||||
}
|
||||
since = v1.NewTime(since.In(loc))
|
||||
}
|
||||
schedule, err := parser.Parse(c.Spec.Schedule)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing schedule of %s/%s (%s): %w", c.Namespace, c.Name, c.Spec.Schedule, err)
|
||||
|
||||
Reference in new issue
Block a user