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

Enable setting a default ComputeClass on projects #2470

Closed
wants to merge 10 commits into from

Conversation

njhale
Copy link
Contributor

@njhale njhale commented Feb 1, 2024

Enable selecting the default ComputeClass for Apps deployed to a project via a new project spec field.

The DefaultComputeClass field contains the name of a [Project|Cluster]ComputeClassInstance to select as the default. If no compute classes with that name exist, the existing ComputeClass defaulting rules are applied.

This PR also extends API validation for project create and update to ensure that a compute class with a matching name exists when the field is set.

Part of https://github.com/acorn-io/manager/issues/1943

@njhale njhale force-pushed the enhance-project-default-cc branch 6 times, most recently from 58af11f to dd0ba07 Compare February 7, 2024 06:53
@acorn-io acorn-io deleted a comment from coderabbitai bot Feb 7, 2024
@njhale njhale force-pushed the enhance-project-default-cc branch 4 times, most recently from 5d2af27 to 0a52614 Compare February 12, 2024 19:11
@njhale njhale marked this pull request as ready for review February 12, 2024 19:12
@njhale njhale force-pushed the enhance-project-default-cc branch 6 times, most recently from b4ef87e to 1e305b1 Compare February 15, 2024 18:08
pkg/project/handlers.go Outdated Show resolved Hide resolved
Comment on lines +23 to +27
if cc := project.Spec.DefaultComputeClass; cc != "" && project.Status.DefaultComputeClass != cc {
// The spec has been changed, update the status field to match.
project.Status.DefaultComputeClass = cc
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to default and supported region(s), we should always have a status value for default compute class. Otherwise, the status field is not necessary.

t := clusterComputeClass // Create a new variable that isn't being iterated on to get a pointer
defaultCCC = &t

// Create a new variable that isn't being iterated on to get a pointer
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment still necessary?

Related: should we bump to Go 1.22?

Comment on lines 42 to 76
if projectSpecifiedCCC != nil {
return projectSpecifiedCCC, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Spoke about this offline: if a user specifies a compute class that doesn't exist, then we should error here.

Additionally, we should check that the default region on the project is supported by the compute class.

Lastly, validation should be added for the user changing the default region on the project to ensure that the default compute class, if one is set, supports the region.

Comment on lines 77 to 102
if projectSpecifiedPCC != nil {
return projectSpecifiedPCC, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here.

defaultComputeClasses = append(defaultComputeClasses, ccc.Name)
}

if sets.New(defaultComputeClasses...).Has(projectSpecified) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: slightly more performant.

Suggested change
if sets.New(defaultComputeClasses...).Has(projectSpecified) {
if slices.Contains(defaultComputeClasses, projectSpecified) {

Comment on lines 38 to 62
if _, err := computeclasses.GetAsProjectComputeClassInstance(ctx, v.Client, project.Name, defaultComputeClass); apierrors.IsNotFound(err) {
// The compute class does not exist, return an invalid error
result = append(result, field.Invalid(field.NewPath("spec", "defaultComputeClass"), defaultComputeClass, "default compute class does not exist"))
} else if err != nil {
// Some other error occurred while trying to get the compute class, return an internal error.
result = append(result, field.InternalError(field.NewPath("spec", "defaultComputeClass"), err))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I left this comment elsewhere, but this is where we should ensure that the selected compute class supports the default region of the project.

@njhale njhale force-pushed the enhance-project-default-cc branch 2 times, most recently from 1d70e3c to df43cfc Compare February 20, 2024 16:00
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Add API-level validation of the defaultComputeClass spec field that
requires a referenced compute class exist on project create or update.

Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Add tests and update affected goldenfiles.

Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
@njhale njhale closed this Feb 20, 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.

3 participants