-
Notifications
You must be signed in to change notification settings - Fork 100
Enable setting a default ComputeClass on projects #2470
Conversation
58af11f
to
dd0ba07
Compare
5d2af27
to
0a52614
Compare
b4ef87e
to
1e305b1
Compare
1e305b1
to
d3feb24
Compare
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 | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
if projectSpecifiedCCC != nil { | ||
return projectSpecifiedCCC, nil | ||
} |
There was a problem hiding this comment.
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.
if projectSpecifiedPCC != nil { | ||
return projectSpecifiedPCC, nil | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: slightly more performant.
if sets.New(defaultComputeClasses...).Has(projectSpecified) { | |
if slices.Contains(defaultComputeClasses, projectSpecified) { |
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)) | ||
} | ||
} |
There was a problem hiding this comment.
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.
1d70e3c
to
df43cfc
Compare
Signed-off-by: Nick Hale <[email protected]>
Signed-off-by: Nick Hale <[email protected]>
Signed-off-by: Nick Hale <[email protected]>
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 <[email protected]>
Add tests and update affected goldenfiles. Signed-off-by: Nick Hale <[email protected]>
Signed-off-by: Nick Hale <[email protected]>
Signed-off-by: Nick Hale <[email protected]>
Signed-off-by: Nick Hale <[email protected]>
Signed-off-by: Nick Hale <[email protected]>
Signed-off-by: Nick Hale <[email protected]>
df43cfc
to
f051f14
Compare
Enable selecting the default
ComputeClass
forApps
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 existingComputeClass
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