python icon indicating copy to clipboard operation
python copied to clipboard

Quantity util functions inconsistently available

Open duncs opened this issue 6 months ago • 4 comments

What happened (please include outputs or screenshots):

Calls to parse_quantity work, but format_quantity do not, even though they are in the same file

from kubernetes import utils
decimal = utils.parse_quantity("1234Ki")
result = utils.format_quantity(decimal,"Mi")
print(result)

returns

Traceback (most recent call last):
  File "/home/dferguson/tmp/py_k8s/./t1.py", line 3, in <module>
    result = utils.format_quantity(decimal,"Mi") # format_quantity not found
               ^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'kubernetes.utils' has no attribute 'format_quantity'. Did you mean: 'parse_quantity'?

whereas:

from kubernetes.utils import quantity
decimal = quantity.parse_quantity("1234Ki")
result = quantity.format_quantity(decimal,"Mi")
print(result)

works as expected

What you expected to happen:

Using utils.format_quantity finds the function correctly

How to reproduce it (as minimally and precisely as possible): See above

Anything else we need to know?: Easily fixed by amending kubernetes/utils/__init__.py

-from .quantity import parse_quantity
+from .quantity import parse_quantity,format_quantity

Quicker to type up the issue in here rather than fork/pull request for such a small fix

Environment:

  • Kubernetes version (kubectl version):
Client Version: v1.32.0
Kustomize Version: v5.5.0
Server Version: v1.31.9-eks-5d4a308
  • OS (e.g., MacOS 10.13.6): Windows WSL2 5.15.167.4-microsoft-standard-WSL2
  • Python version (python --version): Python 3.12.3
  • Python client version (pip list | grep kubernetes): kubernetes 33.1.0

duncs avatar Jul 22 '25 08:07 duncs

/assign @yliaog

roycaihw avatar Jul 30 '25 20:07 roycaihw

@duncs could you help create a PR? thanks.

yliaog avatar Jul 31 '25 17:07 yliaog

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-triage-robot avatar Oct 29 '25 18:10 k8s-triage-robot

The Kubernetes project currently lacks enough active 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 rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle rotten

k8s-triage-robot avatar Nov 28 '25 18:11 k8s-triage-robot