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

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:
argoyle committed 2026-10-09 07:54:30 +00:00
1 parent 40311eaeaa
commit 52d52a222c
4 files changed
+88 -16

No files matched your search

+62 -1
View File
@@ -106,6 +106,7 @@ func Test_doCheck(t *testing.T) {
slackResponse string
wantErr bool
wantOut []string
wantNotOut []string
}{
{
name: "error getting cronjobs",
@@ -181,6 +182,57 @@ func Test_doCheck(t *testing.T) {
},
wantErr: true,
},
{
name: "invalid time zone",
args: args{
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return &cronjobv1.CronJobList{
Items: []cronjobv1.CronJob{
{
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *", TimeZone: strP("Nowhere/Special")},
},
},
}, nil
},
},
},
},
},
wantErr: true,
},
{
name: "schedule evaluated in cronjob time zone",
args: args{
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
// Ran 6h ago at its daily local time; read as UTC the next run would be 30 minutes ago
last := time.Now().Add(-6 * time.Hour).Truncate(time.Minute)
local := last.In(time.FixedZone("IST", 5*3600+1800)) // Asia/Kolkata has no DST
return &cronjobv1.CronJobList{
Items: []cronjobv1.CronJob{
{
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
Spec: cronjobv1.CronJobSpec{Schedule: fmt.Sprintf("%d %d * * *", local.Minute(), local.Hour()), TimeZone: strP("Asia/Kolkata")},
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: last}},
},
},
}, nil
},
},
},
},
},
timeout: 100 * time.Millisecond,
slackResponse: `{"ok": true}`,
wantErr: false,
wantOut: []string{"Checking some-ns/some-name since"},
wantNotOut: []string{"was not scheduled"},
},
{
name: "only correctly running cronjobs",
args: args{
@@ -308,6 +360,11 @@ func Test_doCheck(t *testing.T) {
if err := doCheck(tt.args.client, fmt.Sprintf("http://%s", baseURL), ic, 10*time.Millisecond, buff); (err != nil) != tt.wantErr {
t.Errorf("doCheck() error = %v, wantErr %v", err, tt.wantErr)
}
for _, o := range tt.wantNotOut {
if strings.Contains(buff.String(), o) {
t.Errorf("doCheck() got %s, did not want %s", buff.String(), o)
}
}
if len(tt.wantOut) > 0 {
for _, o := range tt.wantOut {
if !strings.Contains(buff.String(), o) {
@@ -404,7 +461,7 @@ func (b batchApi) CronJobs(namespace string) batchv1.CronJobInterface {
}
func (b batchApi) Jobs(namespace string) batchv1.JobInterface {
//TODO implement me
// TODO implement me
panic("implement me")
}
@@ -463,3 +520,7 @@ var _ batchv1.CronJobInterface = &cronApi{}
func boolP(b bool) *bool {
return &b
}
func strP(s string) *string {
return &s
}