-
Notifications
You must be signed in to change notification settings - Fork 100
enhancement: add ComputeClasses and VolumeClasses fields to BaseResources #2472
Conversation
8c5b667
to
817a740
Compare
WalkthroughThe recent update introduces a significant overhaul in how compute and volume storage resources are managed, shifting from individual resource quantities to structured Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
pkg/controller/quota/testdata/basic/input.yaml
is excluded by:!**/*.yaml
pkg/openapi/generated/openapi_generated.go
is excluded by:!**/generated/**
Files selected for processing (14)
- pkg/apis/internal.admin.acorn.io/v1/baseresources.go (7 hunks)
- pkg/apis/internal.admin.acorn.io/v1/baseresources_test.go (5 hunks)
- pkg/apis/internal.admin.acorn.io/v1/computeclassresources.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/computeclassresources_test.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/quotarequests.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/quotarequests_test.go (23 hunks)
- pkg/apis/internal.admin.acorn.io/v1/resources.go (3 hunks)
- pkg/apis/internal.admin.acorn.io/v1/volumeclassresources.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/volumeclassresources_test.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/zz_generated.deepcopy.go (4 hunks)
- pkg/controller/quota/quota.go (4 hunks)
- pkg/controller/quota/testdata/basic/expected.golden (1 hunks)
- pkg/controller/quota/testdata/implicit-pv-bind/expected.golden (1 hunks)
- pkg/controller/quota/testdata/status-default-volume-size/expected.golden (1 hunks)
Additional comments: 56
pkg/controller/quota/testdata/implicit-pv-bind/expected.golden (2)
- 12-15: LGTM!
- 20-20: LGTM!
pkg/controller/quota/testdata/status-default-volume-size/expected.golden (2)
- 12-15: LGTM!
- 20-22: LGTM!
pkg/controller/quota/testdata/basic/expected.golden (2)
- 12-15: LGTM!
- 20-22: LGTM!
pkg/apis/internal.admin.acorn.io/v1/resources.go (3)
- 67-67: Ensure returning a new
resource.Quantity
instance inSubQuantity
does not introduce unexpected behavior elsewhere in the codebase.- 86-88: Renaming
ResourcesToString
toCountResourcesToString
and removing the parameter improves clarity and reduces complexity.- 103-111: Adding
QuantityResourceToString
enhances modularity by providing a dedicated function for string representation of a resource and its quantity.pkg/apis/internal.admin.acorn.io/v1/quotarequests.go (1)
- 113-113: Using
CountResourcesToString
in theToString
method aligns with the improvements made inresources.go
and enhances code readability.pkg/apis/internal.admin.acorn.io/v1/volumeclassresources.go (1)
- 1-119: The implementation of
VolumeClassResources
and its methods correctly supports the addition, removal, fitting, and string representation of volume class resources. Ensure that the logic inAdd
,Remove
,Fits
, andToString
methods correctly handles all edge cases, especially with unlimited resources.pkg/apis/internal.admin.acorn.io/v1/baseresources.go (5)
- 18-21: The addition of
ComputeClasses
andVolumeClasses
fields toBaseResources
struct aligns with the PR's objectives of improving resource categorization and tracking.- 32-39: Ensure the initialization of
ComputeClasses
andVolumeClasses
does not introduce unnecessary overhead when these fields are already initialized.- 50-52: The conditional removal of
VolumeClasses
based on theall
flag is logical. Verify that this behavior is consistent with the intended functionality across all use cases.- 84-89: The refactoring of the
Fits
method to include checks forComputeClasses
andVolumeClasses
is crucial for ensuring resources do not exceed their allocations. Confirm that the error aggregation logic correctly handles multiple errors.- 109-122: The updated
ToString
method now includesComputeClasses
andVolumeClasses
, enhancing the string representation ofBaseResources
. Ensure the string formatting logic is efficient and error-free.pkg/apis/internal.admin.acorn.io/v1/computeclassresources.go (1)
- 1-150: The implementation of
ComputeClassResources
and its methods correctly supports the addition, removal, fitting, and string representation of compute class resources. Ensure that the logic inAdd
,Remove
,Fits
, andToString
methods correctly handles all edge cases, especially with unlimited resources.pkg/apis/internal.admin.acorn.io/v1/volumeclassresources_test.go (1)
- 1-289: The tests for
VolumeClassResources
methods (Add
,Remove
,Equals
,Fits
,ToString
) appear comprehensive and correctly validate the functionality. Ensure that all edge cases, especially handling of unlimited resources, are covered.pkg/controller/quota/quota.go (4)
- 127-127: Converting the result of
replicas(container.Scale)
to anint
before adding it toquotaRequest.Spec.Resources.Containers
is correct. Ensure this conversion aligns with the expected data types throughout the codebase.- 142-156: The updates to
addCompute
to handleComputeClasses
with the correct multiplication of CPU and memory requests by the container scale are logical. Verify that the handling ofcomputeClass
and resource multiplication aligns with the intended functionality and does not introduce precision issues.- 201-205: The
addStorage
function's update to include volume class information when adding volume storage toquotaRequest.Spec.Resources
is correct. Ensure that the handling ofvolumeClass
aligns with the intended functionality and that the class-based resource tracking is accurately reflected.- 273-275: Changing the
replicas
function signature fromfunc replicas(s *int32) int
tofunc replicas(s *int32) int64
is logical given the context. Confirm that this change does not introduce type mismatches or conversion issues elsewhere in the codebase.pkg/apis/internal.admin.acorn.io/v1/baseresources_test.go (10)
- 20-34: Ensure the test case "add to existing BaseResources resources" correctly updates the
ComputeClasses
andVolumeClasses
to reflect the new fields' addition.- 38-54: The handling of unlimited values in "add where current and incoming have a resource specified with unlimited" is correctly implemented, following the expected logic that adding any value to unlimited remains unlimited.
- 56-79: The test case "add where current and incoming have ComputeClasses and VolumeClasses" correctly demonstrates the addition of resources within
ComputeClasses
andVolumeClasses
, including the doubling of values for matching classes.- 83-99: The test case "add where current is empty and incoming has ComputeClasses and VolumeClasses" correctly initializes the
BaseResources
with the incoming values when the current is empty.- 123-157: The handling of unlimited values in removal operations, such as "remove where current has a resource specified with unlimited" and "remove where incoming has a resource specified with unlimited", is correctly implemented, preserving the unlimited status when applicable.
- 160-178: The test case "remove where current and incoming have ComputeClasses and VolumeClasses" with
all
set to true correctly results in an emptyBaseResources
, demonstrating the removal logic's correctness.- 181-189: The test case "does not remove volume storage when all is false" correctly retains the
VolumeClasses
whenall
is not specified, demonstrating the conditional removal logic.- 218-234: The test cases for
BaseResourcesEquals
, including handling unlimited values and comparingComputeClasses
andVolumeClasses
, are correctly implemented, ensuring accurate equality checks.- 299-320: The test cases for
BaseResourcesFits
, including handling unlimited values and checking fits forComputeClasses
andVolumeClasses
, are correctly implemented, ensuring accurate fit checks.- 386-426: The
BaseResourcesToString
method's test cases, including handling unlimited values and multipleComputeClasses
andVolumeClasses
, are correctly implemented, ensuring accurate string representations.pkg/apis/internal.admin.acorn.io/v1/computeclassresources_test.go (5)
- 20-88: The test cases for
ComputeClassResourcesAdd
, including handling unlimited values and adding resources withAllComputeClasses
, are correctly implemented, demonstrating the addition logic for compute class resources.- 109-197: The test cases for
ComputeClassResourcesRemove
, including handling unlimited values and removing resources withAllComputeClasses
, are correctly implemented, demonstrating the removal logic for compute class resources.- 218-252: The test cases for
ComputeClassResourcesEquals
, including handling unlimited values, are correctly implemented, ensuring accurate equality checks for compute class resources.- 264-390: The test cases for
ComputeClassResourcesFits
, including handling unlimited values and fitting resources withAllComputeClasses
, are correctly implemented, ensuring accurate fit checks for compute class resources.- 404-445: The
ComputeClassResourcesToString
method's test cases, including handling unlimited values and multiple compute classes, are correctly implemented, ensuring accurate string representations for compute class resources.pkg/apis/internal.admin.acorn.io/v1/quotarequests_test.go (15)
- 24-34: The test case "add to empty QuotaRequestResources" correctly initializes the
QuotaRequestResources
with the incoming values, includingComputeClasses
andVolumeClasses
.- 43-63: The test case "add to existing QuotaRequestResources" correctly demonstrates the addition of resources within
QuotaRequestResources
, including the aggregation ofComputeClasses
andVolumeClasses
.- 72-90: The handling of unlimited values in "add where current has a resource specified with unlimited" is correctly implemented, following the expected logic that adding any value to unlimited remains unlimited.
- 99-117: The test case "add where incoming has a resource specified with unlimited" correctly updates the
QuotaRequestResources
to reflect unlimited values for all resources.- 126-144: The test case "add where current and incoming have a resource specified with unlimited" correctly maintains the unlimited status for all resources.
- 172-174: The test case "remove from empty QuotaRequestResources" correctly demonstrates that removing resources from an empty
QuotaRequestResources
results in no change.- 185-195: The test case "should never get negative values" correctly ensures that removing more resources than available results in an empty
QuotaRequestResources
.- 207-215: The test case "removes persistent resources with all" correctly demonstrates the removal of all resources when
all
is true.- 228-236: The test case "does not remove persistent resources without all" correctly retains resources when
all
is not specified, demonstrating conditional removal logic.- 251-269: The handling of unlimited values in removal operations, such as "remove where current has a resource specified with unlimited", is correctly implemented, preserving the unlimited status when applicable.
- 278-296: The test case "remove where incoming has a resource specified with unlimited" correctly retains the original resources when the incoming request specifies unlimited values.
- 305-321: The test case "remove where current and incoming have a resource specified with unlimited" correctly maintains the unlimited status for all resources.
- 388-405: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [352-442]
The test cases for
QuotaRequestResourcesEquals
, including handling unlimited values and comparingComputeClasses
andVolumeClassResources
, are correctly implemented, ensuring accurate equality checks.
- 489-505: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [473-542]
The test cases for
QuotaRequestResourcesFits
, including handling unlimited values and checking fits forComputeClasses
andVolumeClasses
, are correctly implemented, ensuring accurate fit checks.
- 615-639: The
QuotaRequestResourcesToString
method's test cases, including handling unlimited values and multipleComputeClasses
andVolumeClasses
, are correctly implemented, ensuring accurate string representations.pkg/apis/internal.admin.acorn.io/v1/zz_generated.deepcopy.go (4)
- 271-289: The
DeepCopyInto
andDeepCopy
methods forComputeClassResources
are correctly implemented to ensure a deep copy of map elements. No issues found.- 292-306: The
DeepCopyInto
andDeepCopy
methods forComputeResources
correctly perform deep copies ofMemory
andCPU
, which are presumably complex types requiring deep copying. No issues found.- 707-724: The
DeepCopyInto
andDeepCopy
methods forVolumeClassResources
are correctly implemented to ensure a deep copy of map elements. No issues found.- 743-755: The
DeepCopyInto
andDeepCopy
methods forVolumeResources
correctly perform a deep copy ofVolumeStorage
, which is presumably a complex type requiring deep copying. No issues found.
if in.ComputeClasses != nil { | ||
in, out := &in.ComputeClasses, &out.ComputeClasses | ||
*out = make(ComputeClassResources, len(*in)) | ||
for key, val := range *in { | ||
(*out)[key] = *val.DeepCopy() | ||
} | ||
} | ||
if in.VolumeClasses != nil { | ||
in, out := &in.VolumeClasses, &out.VolumeClasses | ||
*out = make(VolumeClassResources, len(*in)) | ||
for key, val := range *in { | ||
(*out)[key] = *val.DeepCopy() | ||
} | ||
} |
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.
Ensure that nil checks are performed before attempting to make deep copies of ComputeClasses
and VolumeClasses
to prevent potential nil pointer dereferences.
if in.ComputeClasses != nil {
+ if out.ComputeClasses == nil {
+ out.ComputeClasses = make(ComputeClassResources)
+ }
in, out := &in.ComputeClasses, &out.ComputeClasses
*out = make(ComputeClassResources, len(*in))
for key, val := range *in {
(*out)[key] = *val.DeepCopy()
}
}
if in.VolumeClasses != nil {
+ if out.VolumeClasses == nil {
+ out.VolumeClasses = make(VolumeClassResources)
+ }
in, out := &in.VolumeClasses, &out.VolumeClasses
*out = make(VolumeClassResources, len(*in))
for key, val := range *in {
(*out)[key] = *val.DeepCopy()
}
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if in.ComputeClasses != nil { | |
in, out := &in.ComputeClasses, &out.ComputeClasses | |
*out = make(ComputeClassResources, len(*in)) | |
for key, val := range *in { | |
(*out)[key] = *val.DeepCopy() | |
} | |
} | |
if in.VolumeClasses != nil { | |
in, out := &in.VolumeClasses, &out.VolumeClasses | |
*out = make(VolumeClassResources, len(*in)) | |
for key, val := range *in { | |
(*out)[key] = *val.DeepCopy() | |
} | |
} | |
if in.ComputeClasses != nil { | |
if out.ComputeClasses == nil { | |
out.ComputeClasses = make(ComputeClassResources) | |
} | |
in, out := &in.ComputeClasses, &out.ComputeClasses | |
*out = make(ComputeClassResources, len(*in)) | |
for key, val := range *in { | |
(*out)[key] = *val.DeepCopy() | |
} | |
} | |
if in.VolumeClasses != nil { | |
if out.VolumeClasses == nil { | |
out.VolumeClasses = make(VolumeClassResources) | |
} | |
in, out := &in.VolumeClasses, &out.VolumeClasses | |
*out = make(VolumeClassResources, len(*in)) | |
for key, val := range *in { | |
(*out)[key] = *val.DeepCopy() | |
} | |
} |
817a740
to
18bf563
Compare
…rces This commit enhances the BaseResources struct by adding ComputeClasses and VolumeClasses fields. These new fields allow for a more detailed specification of compute and storage resources, categorized by class instead of just by resource type. This enhancement is crucial for accurately tracking the usage of memory, CPU, and storage for each specific compute or volume class. Consequently, the QuotaRequest logic has been updated to account for these new fields. These new fields are maps and they introduce a unique approach to handle unlimited resources. They include special keys, `AllComputeClasses` and `AllVolumeClasses`. If a value is assigned to these keys in ComputeClassResources or VolumeClassResources, all compute or volume classes will be evaluated against the value. Signed-off-by: tylerslaton <[email protected]>
18bf563
to
ba9ce98
Compare
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
pkg/controller/quota/testdata/basic/input.yaml
is excluded by:!**/*.yaml
pkg/openapi/generated/openapi_generated.go
is excluded by:!**/generated/**
Files selected for processing (14)
- pkg/apis/internal.admin.acorn.io/v1/baseresources.go (7 hunks)
- pkg/apis/internal.admin.acorn.io/v1/baseresources_test.go (5 hunks)
- pkg/apis/internal.admin.acorn.io/v1/computeclassresources.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/computeclassresources_test.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/quotarequests.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/quotarequests_test.go (23 hunks)
- pkg/apis/internal.admin.acorn.io/v1/resources.go (3 hunks)
- pkg/apis/internal.admin.acorn.io/v1/volumeclassresources.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/volumeclassresources_test.go (1 hunks)
- pkg/apis/internal.admin.acorn.io/v1/zz_generated.deepcopy.go (4 hunks)
- pkg/controller/quota/quota.go (2 hunks)
- pkg/controller/quota/testdata/basic/expected.golden (1 hunks)
- pkg/controller/quota/testdata/implicit-pv-bind/expected.golden (1 hunks)
- pkg/controller/quota/testdata/status-default-volume-size/expected.golden (1 hunks)
Files skipped from review as they are similar to previous changes (14)
- pkg/apis/internal.admin.acorn.io/v1/baseresources.go
- pkg/apis/internal.admin.acorn.io/v1/baseresources_test.go
- pkg/apis/internal.admin.acorn.io/v1/computeclassresources.go
- pkg/apis/internal.admin.acorn.io/v1/computeclassresources_test.go
- pkg/apis/internal.admin.acorn.io/v1/quotarequests.go
- pkg/apis/internal.admin.acorn.io/v1/quotarequests_test.go
- pkg/apis/internal.admin.acorn.io/v1/resources.go
- pkg/apis/internal.admin.acorn.io/v1/volumeclassresources.go
- pkg/apis/internal.admin.acorn.io/v1/volumeclassresources_test.go
- pkg/apis/internal.admin.acorn.io/v1/zz_generated.deepcopy.go
- pkg/controller/quota/quota.go
- pkg/controller/quota/testdata/basic/expected.golden
- pkg/controller/quota/testdata/implicit-pv-bind/expected.golden
- pkg/controller/quota/testdata/status-default-volume-size/expected.golden
This commit enhances the BaseResources struct by adding ComputeClasses and VolumeClasses fields. These new fields allow for a more detailed specification of compute and storage resources, categorized by class instead of just by resource type.
This enhancement is crucial for accurately tracking the usage of memory, CPU, and storage for each specific compute or volume class. Consequently, the QuotaRequest logic has been updated to account for these new fields.
These new fields are maps and they introduce a unique approach to handle unlimited resources. They include special keys,
AllComputeClasses
andAllVolumeClasses
. If a value is assigned to these keys in ComputeClassResources or VolumeClassResources, all compute or volume classes will be evaluated against the value.Checklist
This is a title (#1216)
. Here's an exampleSummary by CodeRabbit
ComputeClasses
andVolumeClasses
.ComputeClasses
andVolumeClasses
.