-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Validate k8s resource requirements for CPU, Memory and Ephemeral Volumes #944
feat: Validate k8s resource requirements for CPU, Memory and Ephemeral Volumes #944
Conversation
…al units Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
…y units for cpu, compare limits and requests for ephemeral and memory Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
0fba84b
to
6f24153
Compare
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #944 +/- ##
=======================================
+ Coverage 80.7% 81.0% +0.2%
=======================================
Files 50 51 +1
Lines 3908 3942 +34
Branches 793 801 +8
=======================================
+ Hits 3157 3195 +38
+ Misses 564 561 -3
+ Partials 187 186 -1 ☔ View full report in Codecov by Sentry. |
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
src/hera/workflows/validators.py
Outdated
@@ -43,30 +43,47 @@ def validate_name(name: str, max_length: Optional[int] = None, generate_name: bo | |||
return name | |||
|
|||
|
|||
def validate_storage_units(value: str) -> None: | |||
"""Validates the units of the given value. | |||
def validate_binary_units(value: str) -> None: |
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.
renamed from validate_storage_units
to validate_binary_units
as this applies to memory and ephemeral volumes
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.
Unfortunately this helper is public and we don't know who might use it outside of the core of Hera. Any chance we can leave validate_storage_units(value: str) -> None
as public and internally it passes the value to validate_binary_units
? That way we get the new function with improved functionality while maintaining backwards compatibility
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.
Thanks for your quick review!
In the commit below I kept the public function and used alias to refer to the _validate_binary_units
, which is now made private so that we can change the implementaion later if necessary.
To avoid confusion and also to make the function names consistent, other function names are now named more explicitly for their use cases (validate_storage_units
, validate_cpu_units
, validate_memory_units
) as well as converters.
src/hera/workflows/validators.py
Outdated
Raises: | ||
------ | ||
ValueError | ||
When the identified unit is not a supported one. The supported units are ['m', 'k', 'M', 'G', 'T', 'P', 'E']. |
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.
The supported units are ['m', 'k', 'M', 'G', 'T', 'P', 'E'].
Small - maybe this can go into the docstring of value
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.
Good point! I added supported units in docstrings for validators and converters in the value section 154d9fe.
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.
Thanks for the first time contribution @KengoA! This is really great :) Left some small feedback on backwards compatibility and docs. The rest looks great
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
Signed-off-by: KengoA <20113339+KengoA@users.noreply.github.com>
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.
LGTM! Thank you @KengoA 🚀
Pull Request Checklist
Description of PR
Currently, resource requirements are only partially validated for binary units with
hera.workflows.validators.validate_storage_units()
function for string values. The current implementaion misses some edge cases where the input is missing numerial values and only the unit is provided (i.e."Ki"
or"Mi"
), and the comparison between request and limit is limited to int values forcpu_request
andcpu_limit
.This PR
hera/workflows/resources.py