Summary
The Python client has no equivalent to the Go apimachinery's equality.Semantic.DeepEqual / resource.Quantity.Cmp() for comparing ResourceQuota objects.
When building controllers or automation that reconciles ResourceQuota resources, comparing two quota objects with plain string or == equality produces false negatives because Kubernetes allows the same quantity to be expressed in multiple representations:
| Value A |
Value B |
Semantically equal? |
== result |
"1" |
"1000m" |
✅ yes |
❌ False |
"1Gi" |
"1073741824" |
✅ yes |
❌ False |
"0.5" |
"500m" |
✅ yes |
❌ False |
The Go operator ecosystem handles this transparently via:
Python users have no equivalent and must write their own normalisation logic.
Proposed Solution
Add kubernetes/utils/resource_quota.py with:
get_resource_list_diff(a, b) — semantic diff of two ResourceList dicts, backed by the existing parse_quantity
resource_quotas_equal(quota_a, quota_b) — boolean guard mirroring the Go reconciler pattern
compare_resource_quotas(api_client, ...) — cluster-aware helper that fetches and compares two quotas
Export all public symbols from kubernetes.utils.
References
Summary
The Python client has no equivalent to the Go apimachinery's
equality.Semantic.DeepEqual/resource.Quantity.Cmp()for comparingResourceQuotaobjects.When building controllers or automation that reconciles
ResourceQuotaresources, comparing two quota objects with plain string or==equality produces false negatives because Kubernetes allows the same quantity to be expressed in multiple representations:==result"1""1000m""1Gi""1073741824""0.5""500m"The Go operator ecosystem handles this transparently via:
equality.Semantic.DeepEqualresource.Quantity.Cmp()Python users have no equivalent and must write their own normalisation logic.
Proposed Solution
Add
kubernetes/utils/resource_quota.pywith:get_resource_list_diff(a, b)— semantic diff of twoResourceListdicts, backed by the existingparse_quantityresource_quotas_equal(quota_a, quota_b)— boolean guard mirroring the Go reconciler patterncompare_resource_quotas(api_client, ...)— cluster-aware helper that fetches and compares two quotasExport all public symbols from
kubernetes.utils.References
Quantity.Cmp: https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.goparse_quantity:kubernetes/utils/quantity.py