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

chore: simple in memory provisioning scheduler #2815

Merged
merged 4 commits into from
Sep 25, 2024

Conversation

jvmakine
Copy link
Contributor

Rough domain model for provisioning deployments.

  • Task is a single executable task to bring the infra from one state to another
  • Deployment is a list of sequentially executable tasks
  • Provisioner is an interface for calling provisioners, wrapping calls to provisioner plugins

This is a WIP, and there are a lot of TODOs around, but I wanted to get this out to keep PRs small.

@jvmakine jvmakine requested review from a team and deniseli and removed request for a team September 25, 2024 01:23
@ftl-robot ftl-robot mentioned this pull request Sep 25, 2024
@jvmakine jvmakine merged commit 1297472 into main Sep 25, 2024
91 checks passed
@jvmakine jvmakine deleted the juho/inmem-provisioning-scheduler branch September 25, 2024 21:47
}

// next running or pending task. Nil if all tasks are done.
func (d *Deployment) next() *Task {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use optional.Option instead of nil to indicate existence.

Desired []*provisioner.Resource
Existing []*provisioner.Resource
// populated only when the task is done
Output []*provisioner.Resource
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be cleaner if this wasn't public, and was instead returned by Progress() once the task is complete?

)

// Task is a unit of work for a deployment
type Task struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all these be public? Generally I think unless a type is purely data it's preferable to have private fields and a constructor, to make it very clear what is and isn't required at construction time.

}

// ExtractResources from a module schema
func ExtractResources(sch *schema.Module) ([]*provisioner.Resource, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

var result []*provisioner.Resource
for _, decl := range sch.Decls {
if db, ok := decl.(*schema.Database); ok {
if db.Type == "postgres" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch?

if existing == nil {
continue
}
if mysqlTo, ok := r.Resource.(*provisioner.Resource_Mysql); ok {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better pattern we can use here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very least this should be a type switch rather than a set of if/else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants