python icon indicating copy to clipboard operation
python copied to clipboard

Adding utils.format_quantity

Open rkschamer opened this issue 1 year ago • 8 comments

What type of PR is this?

/kind feature

What this PR does / why we need it:

PR adds a utils.format_quantity, which converts a decimal number into a canonical kubernetes quantity.

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. This PR proposes to add this functionality to the Python K8s client.

Which issue(s) this PR fixes:

Fixes #2205

Special notes for your reviewer:

I couldn't find any tests for the utils modules, neither the parse_quantity function. I'd be very happy to add some tests for format_quantity, but so far I just didn't find the right place for them. Please let me know where I should put them.

Does this PR introduce a user-facing change?

Adding `utils.format_quantity` to convert decimal numbers into a canonical Kubernetes quantity.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

I think that's not applicable for this change - I'm not sure though.


rkschamer avatar Apr 04 '24 15:04 rkschamer

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: rkschamer / name: René Kschamer (76ffd7139bab637485196e1e7fabd499c9a148ab, d1deeebf7ebdd93661255f6bf583d1c42846b5e5, 0f3f8eca8fbd770afacd62c9d13233d688fbb22f)

Welcome @rkschamer!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

k8s-ci-robot avatar Apr 04 '24 15:04 k8s-ci-robot

/kind feature

rkschamer avatar Apr 04 '24 15:04 rkschamer

I couldn't find any tests for the utils modules, neither the parse_quantity function. I'd be very happy to add some tests for format_quantity, but so far I just didn't find the right place for them. Please let me know where I should put them.

You could use https://github.com/kubernetes-client/python/blob/master/kubernetes/e2e_test/test_utils.py

Perfect, thank you. I've now added the tests for format_quantity and also took the liberty to add a test for parse_quantity. Since pytest haven't been used in test_utils.py I refrained from using @pytest.mark.parametrize. Please let me know if I should change this.

With the tests, I now consider my change as ready for review and hence, I've also changed to an actual PR.

rkschamer avatar Apr 05 '24 12:04 rkschamer

Hi @roycaihw,

I don't want to be pushy, but do you think, you can have a look on the PR?

Thank you, René

rkschamer avatar Apr 30 '24 12:04 rkschamer

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

This bot triages PRs 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 PR is closed

You can:

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

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

/lifecycle stale

k8s-triage-robot avatar Jul 29 '24 12:07 k8s-triage-robot

/remove-lifecycle stale

rkschamer avatar Aug 14 '24 11:08 rkschamer

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

This bot triages PRs 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 PR is closed

You can:

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

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

/lifecycle stale

k8s-triage-robot avatar Nov 12 '24 11:11 k8s-triage-robot

I appreciate any review on the PR.

/remove-lifecycle stale

rkschamer avatar Nov 26 '24 15:11 rkschamer

Dear reviewers, can you help to review this PR?

Much appreciated.

/assign @kubernetes/sig-pr-reviews /remove-lifecycle rotten /help

rkschamer avatar Jan 29 '25 14:01 rkschamer

thanks for the PR

/lgtm /approve

yliaog avatar Jan 29 '25 15:01 yliaog

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rkschamer, yliaog

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar Jan 29 '25 15:01 k8s-ci-robot