Skip to content
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

format_quantity function missing to convert Decimal values in to K8s quantity string #2205

Open
rkschamer opened this issue Mar 1, 2024 · 9 comments · May be fixed by #2216
Open

format_quantity function missing to convert Decimal values in to K8s quantity string #2205

rkschamer opened this issue Mar 1, 2024 · 9 comments · May be fixed by #2216
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@rkschamer
Copy link

rkschamer commented Mar 1, 2024

What is the feature and why do you need it:

There is parse_quantity to convert a canonical K8s quantity into a Decimal value. However, an opposite function, like format_quantity is missing, making it hard to transform a Decimal into a K8s quantity.

My use case was that I needed to load the resource requirements of serval pods, finding the maximum value and setting it for all pods. Due to potentially different SI suffixes, I've used parse_quantity, however setting the resource requirements for all other Pods, requires me to convert back from a Decimal into a canonical K8s quantity.

Describe the solution you'd like to see:

So far, I've implemented the function in my project, but I think that might be something also others could benefit. For this reason, I'd like to open a pull request to contribute this function.

Tasks

No tasks being tracked yet.
@rkschamer rkschamer added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 1, 2024
@roycaihw
Copy link
Member

/help
/assign @rkschamer

@k8s-ci-robot
Copy link
Contributor

@roycaihw:
This request has been marked as needing help from a contributor.

Guidelines

Please ensure that the issue body includes answers to the following questions:

  • Why are we solving this issue?
  • To address this issue, are there any code changes? If there are code changes, what needs to be done in the code and what places can the assignee treat as reference points?
  • Does this issue have zero to low barrier of entry?
  • How can the assignee reach out to you for help?

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/help
/assign @rkschamer

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Mar 13, 2024
@rkschamer rkschamer linked a pull request Apr 4, 2024 that will close this issue
@rkschamer
Copy link
Author

rkschamer commented Apr 4, 2024

Hi @roycaihw,

thanks for looking into my request. I'm sorry that it took me a while to come back to you.

I'm not entirely sure, on which aspect my help is needed. Maybe it my description for the desired function was not quite clear. So let me try again:

There is already utils.parse_quantity which I used in my project, but I also needed a way to convert a Decimal number back into a Kubernetes quantity. I propose to add this functionality to the Python K8s client.

I opened the issue to ask if such a function is desired and since, I've already implemented it for my own project, I want to contribute. To illustrate my request a bit more, I've no created a draft PR for the function, so that you can have a look (there is also an example how to use the function): #2216

Please let me know if you're in favor of the change. Then I'll convert into an actual PR and sign the CLA.

I'm removing the 'help wanted', since to indicate that I've replied to your request.

/remove-help

@roycaihw roycaihw removed the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Apr 4, 2024
@roycaihw
Copy link
Member

roycaihw commented Apr 4, 2024

Hi @rkschamer, the feature sounds good! Please feel free to convert the draft to an actual PR and we can review and merge it

@rkschamer
Copy link
Author

Hi @rkschamer, the feature sounds good! Please feel free to convert the draft to an actual PR and we can review and merge it

Thanks, @roycaihw! I've now added tests and converted to an actual PR. Please feel free to review the PR.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 4, 2024
@rkschamer
Copy link
Author

rkschamer commented Jul 26, 2024

From my point of view, this PR is still valid. I'm just awaiting a code review. I'm sorry about the extend of the PR. Majority of the changes is in tests. I could reduce, if you want.

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 26, 2024
@superlazyname
Copy link

superlazyname commented Sep 30, 2024

Could this feature be merged in? This seems really helpful. Thanks for making this @rkschamer

People on Stack Overflow are suggesting to roll your own converter from '100m' to decimal and back and that's obviously less than ideal from a maintainability standpoint, it seems like only Golang has code in it to convert both ways.

@rkschamer
Copy link
Author

@superlazyname, I'd be very happy if my PR #2216 could be merged. I'm just waiting for a review from @roycaihw, who is assigned to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants