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

Add instance placement scriptlet extension #652

Closed
victoitor opened this issue Mar 24, 2024 · 11 comments
Closed

Add instance placement scriptlet extension #652

victoitor opened this issue Mar 24, 2024 · 11 comments
Assignees
Labels
API Changes to the REST API Documentation Documentation needs updating Easy Good for new contributors Feature New feature, not a bug
Milestone

Comments

@victoitor
Copy link

victoitor commented Mar 24, 2024

Currently, the instance placement scriptlet does not have enough functionality to implement even the default scheduler. Some extra functionality is needed both to be able to reproduce it and to extend it in simple ways.

This was discussed int this linuxcontainers forum post.

The desired extra functionality would be the following:

  • get_instances function which would then take optional project and/or location args. We should be able to obtain instance configuration options and cluster node placement from this list.
  • get_cluster_members function taking as input a cluster group to return a list of cluster nodes in that cluster group.
@stgraber stgraber added this to the soon milestone Mar 25, 2024
@stgraber stgraber added Documentation Documentation needs updating Feature New feature, not a bug API Changes to the REST API Easy Good for new contributors labels Mar 27, 2024
@stgraber stgraber changed the title Add instance placement scriptlet functionality Add instance placement scriptlet extension Mar 27, 2024
@christina-zh
Copy link

Im interested in working on this issue, can I be assigned to it please?

@stgraber
Copy link
Member

stgraber commented Mar 28, 2024

So as mentioned, the goal here is to expose two new functions to instance scriptlets.
Those are defined in:

  • internal/server/scriptlet/load/load.go
  • internal/server/scriptlet/instance_placement.go
  • doc/explanation/clustering.md

This will need API extensions, let's go with one for each function, so:

  • instances_scriptlet_get_instances
  • instances_scriptlet_get_cluster_members

The functions themselves need to be added to instance_placement.go, you can look at the existing functions there like getInstanceResourcesFunc and getClusterMemberStateFunc.

We'll want get_instances to take optional location and project arguments.
Then it should call GetInstances() from the database with a suitable filter (location/project) and turn the result into an []api.Instance which it then returns.

For get_cluster_members, it should take an optional group argument and use GetNodes() to get the cluster members, then filter by group if needed and turn that into a []api.ClusterMember to return.

As far as commits for this one, it should be a somewhat repetitive:

  • api: instances_scriptlet_get_instances
  • doc/instances/scriptlet: Add get_instances
  • incusd/scriptlet: Add get_instances
  • api: instances_scriptlet_get_cluster_members
  • doc/instances/scriptlet: Add get_cluster_members
  • incusd/scriptlet: Add get_cluster_members

For testing, you'd need an Incus cluster with at least two servers in it.
That can be done pretty easily with a couple of virtual machines, but you can also add the feature without being able to validate it yourself and I can do the validation for you.

@awalvie
Copy link
Contributor

awalvie commented Apr 8, 2024

Is this still being worked on? If not can I pick this up? Love the project and would like to start contributing!

@stgraber
Copy link
Member

stgraber commented Apr 8, 2024

Hey @awalvie, this is currently assigned to a group of student to work on.
Those groups usually get a few easy issues and a more difficult one to work on, this is the case here.

If the group in question somehow can't resolve this one, I'll be happy to assign it to you.

I realize we're a bit short on unassigned issues right now (weird problem to have ;)), but I just opened #741 which may be interesting for you, though a completely different part of Incus :)

@awalvie
Copy link
Contributor

awalvie commented Apr 8, 2024

Haha, it's a good problem to have though! I'll check out the linked issue!

@christina-zh
Copy link

christina-zh commented Apr 15, 2024

Hello @stgraber We have a few questions regarding this issue:

  1. Should we be adding the API extensions in internal/server/scriptlet/instance_placement.go or internal/version/api.go (or both)?
  2. Since get_instances() will be taking optional parameters (location and project), is it correct to call GetInstances() when location and project are not being passed in and call GetInstancesWithFilter() when the parameters are available?
  3. In the codebase there's usually a calling object before the call to GetInstances() or GetInstancesWithFilter(). Should we be getting the calling object from conf.GetInstanceServer(remote)?

@stgraber
Copy link
Member

Should we be adding the API extensions in internal/server/scriptlet/instance_placement.go or internal/version/api.go (or both)?

The commit api: XYZ should only include the doc/api-extensions.md and internal/version/api.go changes as that's effectively where the API extension gets allocated.

Your changes to instance_placement.go will go into the incusd/scriptlet commit.

In the codebase there's usually a calling object before the call to GetInstances() or GetInstancesWithFilter(). Should we be getting the calling object from conf.GetInstanceServer(remote)?

No, those are client-side functions, you're running from within the server, so in the server, you instead hit the database functions which in this case would be GetInstances() from the DB code.

internal/server/db/cluster/instances.mapper.go:func GetInstances(ctx context.Context, tx *sql.Tx, filters ...InstanceFilter) ([]Instance, error) {

That function takes an InstanceFilter which will let you filter by Project or Location.

@christina-zh
Copy link

Thank you for answering our previous questions @stgraber ! We want to ask for clarification on the get_cluster_members function. Since GetNodes() returns a list of NodeInfo, should we be passing that list into GetCandidateMembers(...) to filter offline nodes or is looping through the list and checking for the group enough?

@stgraber
Copy link
Member

I think it'd make sense to filter the list based on what's allowed, so indeed limiting it to the list of candidates.

@christina-zh
Copy link

Ok that makes sense. Also, since ToAPI(...) takes NodeInfoArgs as the third parameter, should we be setting the fields in the struct similar to how it's being done in instance_placement.go (near the bottom of it)?

@stgraber
Copy link
Member

Yeah, that should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Changes to the REST API Documentation Documentation needs updating Easy Good for new contributors Feature New feature, not a bug
Development

No branches or pull requests

4 participants