Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

fix: handle multiple compute classes in a project #2459

Merged
merged 8 commits into from
Jan 30, 2024
Merged

fix: handle multiple compute classes in a project #2459

merged 8 commits into from
Jan 30, 2024

Conversation

keyallis
Copy link
Contributor

acorn-io/manager#1819

Handle the case of multiple compute classes being configured as default for a project spanning multiple regions.

Checklist

  • The title of this PR would make a good line in Acorn's Release Note's Changelog
  • The title of this PR ends with a link to the main issue being address in parentheses, like: This is a title (#1216). Here's an example
  • All relevant issues are referenced in the PR description. NOTE: don't use GitHub keywords that auto-close issues
  • Commits follow contributing guidance
  • Automated tests added to cover the changes. If tests couldn't be added, an explanation is provided in the Verification and Testing section
  • Changes to user-facing functionality, API, CLI, and upgrade impacts are clearly called out in PR description
  • PR has at least two approvals before merging (or a reasonable exception, like it's just a docs change)

Copy link
Contributor

@thedadams thedadams left a comment

Choose a reason for hiding this comment

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

The two failing tests here are testing that an app cannot use a compute class that is not for its region. The reason they are failing is that the app is not specifying a region, so the "wrong" compute class is no longer being included.

The tests should be updated such that the app specifically tries to use the compute class that is not for its region. That should fail (which would mean the test would pass).

@@ -584,13 +584,20 @@ func (s *Validator) checkScheduling(ctx context.Context, params *apiv1.App, proj
return append(validationErrors, field.Invalid(field.NewPath("spec", "image"), params.Spec.Image, fmt.Sprintf("error listing compute classes: %v", err)))
}

filteredComputeClasses := new(apiv1.ComputeClassList)
for _, cc := range computeClasses.Items {
if slices.Contains(cc.SupportedRegions, params.Spec.Region) || slices.Contains(cc.SupportedRegions, defaultRegion) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the params.Spec.Region != "", then we don't want to check the defaultRegion here.

However, we also need to collect all the compute classes that may be specified by a user or acornfile. In order of precidence:

  1. params.Spec.ComputeClasses
  2. app.Status.AppSpec.{Containers,Jobs}[].ComputeClass as well as app.Status.AppSpec.{Containers,Jobs}[].Sidecars[].ComputeClass
  3. The default for the region.

By including all of these here, the checks below will catch if an app is trying to use a compute class that is not for the region.

In order to check 2, you would need the imageDetails.AppSpec from where this method is called.

Copy link
Contributor

Choose a reason for hiding this comment

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

@keyallis keyallis requested a review from thedadams January 26, 2024 18:10
@keyallis keyallis marked this pull request as ready for review January 29, 2024 17:35
Copy link
Member

@njhale njhale left a comment

Choose a reason for hiding this comment

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

left a nit, but otherwise lgtm

if !tt.noComputeClass {
for _, computeClass := range computeClasses {
if err := kclient.Create(ctx, computeClass); err != nil {
t.Fatal(err)
Copy link
Member

Choose a reason for hiding this comment

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

nit: you can use require.NoError(t, err) to end the testcase early.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test structure was lifted from the function below this one so I'd prefer not to change much about it other than the looping. I thought about combining the two blocks together as well but figured it would be easier to review if it was just it's own function

integration/run/run_test.go Outdated Show resolved Hide resolved
pkg/controller/defaults/memory.go Outdated Show resolved Hide resolved
pkg/controller/defaults/memory.go Outdated Show resolved Hide resolved
pkg/controller/defaults/memory.go Outdated Show resolved Hide resolved
pkg/controller/resolvedofferings/computeclass.go Outdated Show resolved Hide resolved
pkg/controller/resolvedofferings/computeclass.go Outdated Show resolved Hide resolved
pkg/controller/scheduling/scheduling.go Outdated Show resolved Hide resolved
@keyallis keyallis requested a review from thedadams January 30, 2024 18:31
Oscar Ward added 7 commits January 30, 2024 13:07
…default for a project spanning multiple regions

Signed-off-by: Oscar Ward <[email protected]>
Signed-off-by: Oscar Ward <[email protected]>
… class, update unit tests

Signed-off-by: Oscar Ward <[email protected]>
Signed-off-by: Oscar Ward <[email protected]>
Signed-off-by: Oscar Ward <[email protected]>
app, err := c.AppRun(ctx, image.ID, &client.AppRunOptions{Name: testcase})
app, err := c.AppRun(ctx, image.ID, &client.AppRunOptions{
Name: testcase,
Region: apiv1.LocalRegion,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this changing? We should be able to continue to use the default region here instead of specifying one, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was left over from previous versions of this PR, I've reverted it.

Signed-off-by: Oscar Ward <[email protected]>
@keyallis keyallis requested a review from thedadams January 30, 2024 22:08
@keyallis keyallis merged commit ce9166e into acorn-io:main Jan 30, 2024
3 of 4 checks passed
@keyallis keyallis deleted the issue-manager-1819 branch January 30, 2024 23:00
keyallis pushed a commit that referenced this pull request Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants