Skip to content

Add semantic ResourceQuota comparison utility #2577

@sajjadghf

Description

@sajjadghf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions