furiko-io / furiko

Kubernetes cron and batch job platform
https://furiko.io
Apache License 2.0
478 stars 21 forks source link

feat(cron): Support multiple cron expressions #127

Closed irvinlim closed 1 year ago

irvinlim commented 1 year ago

Closes #7.

Overview

This PR introduces support for multiple cron expressions per JobConfig.

For example, given the following JobConfig spec:

spec:
  schedule:
    cron:
      expressions:
        - '0/30 10-19 * * *'
        - '0 0/2 * * *'

This allows us to specify that the JobConfig shall be periodically scheduled as follows:

  1. Every 30 minutes, starting at 10:00 and ending at 19:30.
  2. Every 2 hours outside of 10:00-20:00 (i.e. 00:00, 02:00, ..., 08:00, 20:00, 22:00)

API Semantics

  1. At most one of expression/expressions is allowed in spec.schedule.cron.
  2. The order of cron expressions does not matter.
  3. When multiple cron expressions fall on the same time, only one of them will trigger a schedule. In the above example, 10:00, 12:00, ... are covered by both 0/30 10-19 * * * and 0 0/2 * * *. However, the JobConfig will be scheduled only once.

Changes

  1. Adds a new field expressions to spec.schedule.cron and make both expression/expressions optional.
  2. Update validation webhook to validate new field.
  3. Add the Expression interface, which is implemented by *cronexpr.Expression, as well as a new multiExpression implementation.
  4. Support multiExpression which returns the earliest next value for Next().
  5. Update CLI to display multiple cron expressions correctly.
codecov[bot] commented 1 year ago

Codecov Report

Base: 70.36% // Head: 70.60% // Increases project coverage by +0.24% :tada:

Coverage data is based on head (c08ae2c) compared to base (c8e12c6). Patch coverage: 82.60% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #127 +/- ## ========================================== + Coverage 70.36% 70.60% +0.24% ========================================== Files 194 200 +6 Lines 10284 10386 +102 ========================================== + Hits 7236 7333 +97 - Misses 2661 2664 +3 - Partials 387 389 +2 ``` | [Impacted Files](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io) | Coverage Δ | | |---|---|---| | [pkg/execution/util/cronschedule/option.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2V4ZWN1dGlvbi91dGlsL2Nyb25zY2hlZHVsZS9vcHRpb24uZ28=) | `100.00% <ø> (ø)` | | | [pkg/execution/variablecontext/provider.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2V4ZWN1dGlvbi92YXJpYWJsZWNvbnRleHQvcHJvdmlkZXIuZ28=) | `55.10% <0.00%> (-3.60%)` | :arrow_down: | | [pkg/cli/format/schedule.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2NsaS9mb3JtYXQvc2NoZWR1bGUuZ28=) | `37.93% <37.93%> (ø)` | | | [pkg/execution/util/cron/util.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2V4ZWN1dGlvbi91dGlsL2Nyb24vdXRpbC5nbw==) | `53.84% <53.84%> (ø)` | | | [pkg/execution/util/cronschedule/schedule.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2V4ZWN1dGlvbi91dGlsL2Nyb25zY2hlZHVsZS9zY2hlZHVsZS5nbw==) | `77.32% <85.71%> (ø)` | | | [pkg/cli/common/config.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2NsaS9jb21tb24vY29uZmlnLmdv) | `88.88% <88.88%> (ø)` | | | [pkg/cli/cmd/cmd\_get\_jobconfig.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2NsaS9jbWQvY21kX2dldF9qb2Jjb25maWcuZ28=) | `79.71% <91.66%> (+4.40%)` | :arrow_up: | | [pkg/cli/format/time.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2NsaS9mb3JtYXQvdGltZS5nbw==) | `85.00% <91.66%> (+2.64%)` | :arrow_up: | | [pkg/execution/util/cron/parser.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-cGtnL2V4ZWN1dGlvbi91dGlsL2Nyb24vcGFyc2VyLmdv) | `79.31% <91.66%> (ø)` | | | [apis/execution/v1alpha1/jobconfig\_types.go](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io#diff-YXBpcy9leGVjdXRpb24vdjFhbHBoYTEvam9iY29uZmlnX3R5cGVzLmdv) | `100.00% <100.00%> (ø)` | | | ... and [13 more](https://codecov.io/gh/furiko-io/furiko/pull/127?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io) | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=furiko-io)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.