Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create BookingScheduler #60

Open
rallyos opened this issue May 23, 2023 · 1 comment · May be fixed by #61
Open

Create BookingScheduler #60

rallyos opened this issue May 23, 2023 · 1 comment · May be fixed by #61
Labels
enhancement New feature or request

Comments

@rallyos
Copy link
Collaborator

rallyos commented May 23, 2023

Creation of BookingScheduler resource

Why

Since the release of the cost-saving app, we have needed a way to make bookings recurring and with that provide flexibility and automation to the users. In the last weeks, we got questions about the possibility to easily make bookings on a given schedule, which gives us a perfect moment to finally implement this.

How

We agreed that we'll use the Kubernetes cronjob/job relation as an inspiration. Meaning that we'll create a new resource BookingScheduler which will be able to create bookings on a given schedule.
Note that bookings are still the only object that controls wether a resource should be reserved or not. The BookingScheduler is just a creator of bookings, with some extra options to control when and for how long a booking should be created.

Fields

  • schedule — A string in the crontab format which will be used to schedule reconciliation and with that — creation of bookings on a given date time. Since it is used internally by Kubernetes for their cronjob implementation, the plan is to use cron for parsing it to a next date time.
  • duration — We need a field to store how long the booking should be. For now, I suggest we use minutes for it. So, a 2-hour booking will have duration: 120.
  • template / bookingTemplate — Where we place the booking spec fields. Taking direct inspiration from how deployments and other resources that have it. Supposedly this will make things more maintainable as we won't have to sync or duplicate resource fields between the scheduler and the booking. I don't think there are many suggestions out there on how to do it, so we'll experiment. My first try would be to directly point the template field to the booking spec struct.

Logic Flow

  1. Create the BookingScheduler with the given schedule and a duration.
  2. The creation triggers the reconciliation function.
    1. Create the booking based on the given params.
    2. Parse the schedule using the current time (ex. now.next(cron), which gives us the next date time a booking should be created.
    3. Use that date time to queue the next reconciliation of the booking scheduler. Return a queue object with a value in minutes that is basically the next occurrence — now, in minutes.
  3. On the next reconciliation, the process continues from step 1.1

Possible issues to have in mind

We discussed these in a more detailed document and we agreed on possible solutions to try, so to keep things short I'll just mention the highlights so we have then in mind when working on this.

  • Possible execution delay
  • Duplicating booking fields makes things hard to maintain
  • How modifying the BookingScheduler should affect the bookings.

Changes to Booking

  • OwnerReferences — Pointing scheduled bookings to a BookingScheduler will allow us to properly manage the effects in case of a state change or deletion of the BookingScheduler.
@rallyos rallyos added the enhancement New feature or request label May 23, 2023
@aleicher
Copy link
Member

🚀 would be very useful to have

@rallyos rallyos linked a pull request Jun 13, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants