Quantity util functions inconsistently available
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
/assign @yliaog
@duncs could you help create a PR? thanks.
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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