fix: evaluate schedules in the cronjob's spec.timeZone
Schedules were always evaluated in UTC, so a cronjob with timeZone set (e.g. 0 7 * * * Europe/Stockholm) was reported as not running every day. Embed tzdata since the image is built from scratch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C8SW6vsbkrTKjLNatQ8JTg
This commit is contained in:
1 parent
40311eaeaa
commit
5c09dfc80e
2 files changed
+75
-3
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