Skip to content

Commit

Permalink
fix: add hardcoded utc prefix to crontab (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
njtran committed Mar 4, 2024
1 parent f02e55a commit 831d3c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/apis/v1beta1/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,16 @@ func (in *Budget) IsActive(c clock.Clock) (bool, error) {
if in.Schedule == nil && in.Duration == nil {
return true, nil
}
schedule, err := cron.ParseStandard(lo.FromPtr(in.Schedule))
schedule, err := cron.ParseStandard(fmt.Sprintf("TZ=UTC %s", lo.FromPtr(in.Schedule)))
if err != nil {
// Should only occur if there's a discrepancy
// with the validation regex and the cron package.
return false, fmt.Errorf("invariant violated, invalid cron %s", schedule)
}
// Walk back in time for the duration associated with the schedule
checkPoint := c.Now().Add(-lo.FromPtr(in.Duration).Duration)
checkPoint := c.Now().UTC().Add(-lo.FromPtr(in.Duration).Duration)
nextHit := schedule.Next(checkPoint)
return !nextHit.After(c.Now()), nil
return !nextHit.After(c.Now().UTC()), nil
}

func GetIntStrFromValue(str string) intstr.IntOrString {
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/v1beta1/nodepool_budgets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ var _ = Describe("Budgets", func() {
})
})
Context("IsActive", func() {
It("should always consider a schedule and time in UTC", func() {
// Set the time to start of June 2000 in a time zone 1 hour ahead of UTC
fakeClock = clock.NewFakeClock(time.Date(2000, time.June, 0, 0, 0, 0, 0, time.FixedZone("fake-zone", 3600)))
budgets[0].Schedule = lo.ToPtr("@daily")
budgets[0].Duration = lo.ToPtr(metav1.Duration{Duration: lo.Must(time.ParseDuration("30m"))})
// IsActive should use UTC, not the location of the clock that's inputted.
active, err := budgets[0].IsActive(fakeClock)
Expect(err).To(Succeed())
Expect(active).To(BeFalse())
})
It("should return that a schedule is active when schedule and duration are nil", func() {
budgets[0].Schedule = nil
budgets[0].Duration = nil
Expand Down

0 comments on commit 831d3c6

Please sign in to comment.