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

enhancement: add ComputeClasses and VolumeClasses fields to BaseResources #2472

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

tylerslaton
Copy link
Contributor

@tylerslaton tylerslaton commented Feb 1, 2024

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.

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)

Summary by CodeRabbit

  • New Features
    • Introduced management of compute and volume storage resources through ComputeClasses and VolumeClasses.
  • Refactor
    • Updated resource tracking and allocation methods to support new ComputeClasses and VolumeClasses.
  • Tests
    • Adjusted and added tests for new resource management functionality.
  • Documentation
    • Updated method descriptions to reflect changes in resource management.

@tylerslaton tylerslaton marked this pull request as ready for review February 5, 2024 21:08
Copy link

coderabbitai bot commented Feb 5, 2024

Walkthrough

The recent update introduces a significant overhaul in how compute and volume storage resources are managed, shifting from individual resource quantities to structured ComputeClasses and VolumeClasses. This change affects resource tracking, allocation, and comparison across the system. Modifications include updates to resource addition, removal, fit checks, and string representation, alongside the introduction of new structures and methods tailored to handle the complexities of compute and volume class resources efficiently.

Changes

Files Change Summary
.../v1/baseresources.go
.../v1/quotarequests.go
Introduced ComputeClasses and VolumeClasses, updated methods for resource management, and modified ToString representations.
.../v1/baseresources_test.go
.../v1/quotarequests_test.go
Adjusted tests for adding, removing, and comparing resources, including handling of ComputeClasses and VolumeClasses.
.../v1/computeclassresources.go
.../v1/volumeclassresources.go
Added functionality for managing compute and volume class resources, with methods for resource operations.
.../v1/computeclassresources_test.go
.../v1/volumeclassresources_test.go
Provided tests for compute and volume class resource functions.
.../v1/resources.go Updated resource subtraction logic and string conversion functions.
.../v1/zz_generated.deepcopy.go Updated DeepCopyInto for BaseResources and added copy methods for new resource types.
.../controller/quota/quota.go Modified quota request handling to accommodate computeClasses and volumeClasses.
.../controller/quota/testdata/.../expected.golden Updated test data to reflect new resource allocation specifications with computeClasses and volumeClasses.

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 92d24ac and 817a740.
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 in SubQuantity does not introduce unexpected behavior elsewhere in the codebase.
  • 86-88: Renaming ResourcesToString to CountResourcesToString 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 the ToString method aligns with the improvements made in resources.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 in Add, Remove, Fits, and ToString 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 and VolumeClasses fields to BaseResources struct aligns with the PR's objectives of improving resource categorization and tracking.
  • 32-39: Ensure the initialization of ComputeClasses and VolumeClasses does not introduce unnecessary overhead when these fields are already initialized.
  • 50-52: The conditional removal of VolumeClasses based on the all 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 for ComputeClasses and VolumeClasses 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 includes ComputeClasses and VolumeClasses, enhancing the string representation of BaseResources. 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 in Add, Remove, Fits, and ToString 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 an int before adding it to quotaRequest.Spec.Resources.Containers is correct. Ensure this conversion aligns with the expected data types throughout the codebase.
  • 142-156: The updates to addCompute to handle ComputeClasses with the correct multiplication of CPU and memory requests by the container scale are logical. Verify that the handling of computeClass 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 to quotaRequest.Spec.Resources is correct. Ensure that the handling of volumeClass aligns with the intended functionality and that the class-based resource tracking is accurately reflected.
  • 273-275: Changing the replicas function signature from func replicas(s *int32) int to func 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 and VolumeClasses 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 and VolumeClasses, 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 empty BaseResources, demonstrating the removal logic's correctness.
  • 181-189: The test case "does not remove volume storage when all is false" correctly retains the VolumeClasses when all is not specified, demonstrating the conditional removal logic.
  • 218-234: The test cases for BaseResourcesEquals, including handling unlimited values and comparing ComputeClasses and VolumeClasses, are correctly implemented, ensuring accurate equality checks.
  • 299-320: The test cases for BaseResourcesFits, including handling unlimited values and checking fits for ComputeClasses and VolumeClasses, are correctly implemented, ensuring accurate fit checks.
  • 386-426: The BaseResourcesToString method's test cases, including handling unlimited values and multiple ComputeClasses and VolumeClasses, 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 with AllComputeClasses, 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 with AllComputeClasses, 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 with AllComputeClasses, 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, including ComputeClasses and VolumeClasses.
  • 43-63: The test case "add to existing QuotaRequestResources" correctly demonstrates the addition of resources within QuotaRequestResources, including the aggregation of ComputeClasses and VolumeClasses.
  • 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 comparing ComputeClasses and VolumeClassResources, 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 for ComputeClasses and VolumeClasses, are correctly implemented, ensuring accurate fit checks.

  • 615-639: The QuotaRequestResourcesToString method's test cases, including handling unlimited values and multiple ComputeClasses and VolumeClasses, are correctly implemented, ensuring accurate string representations.
pkg/apis/internal.admin.acorn.io/v1/zz_generated.deepcopy.go (4)
  • 271-289: The DeepCopyInto and DeepCopy methods for ComputeClassResources are correctly implemented to ensure a deep copy of map elements. No issues found.
  • 292-306: The DeepCopyInto and DeepCopy methods for ComputeResources correctly perform deep copies of Memory and CPU, which are presumably complex types requiring deep copying. No issues found.
  • 707-724: The DeepCopyInto and DeepCopy methods for VolumeClassResources are correctly implemented to ensure a deep copy of map elements. No issues found.
  • 743-755: The DeepCopyInto and DeepCopy methods for VolumeResources correctly perform a deep copy of VolumeStorage, which is presumably a complex type requiring deep copying. No issues found.

Comment on lines +17 to +30
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()
}
}
Copy link

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.

Suggested change
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()
}
}

…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]>
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 3103a5e and ba9ce98.
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

@tylerslaton tylerslaton merged commit e5c17fb into acorn-io:main Feb 6, 2024
4 checks passed
@tylerslaton tylerslaton deleted the compute-class-quota branch February 6, 2024 17:38
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.

2 participants