INNER CODE UNIT · Python
cpus_equal
weaveworks/kubediff · kubedifflib/_diff.py:52
def cpus_equal(a, b):
"""Compares cpu specs for equality. cpu specs can be ints, floats or strings '{:d}m',
where 'm' denotes 'milli-', ie. 1/1000th of an integer value.
Eg. "50m" is equal to 0.05."""
def parse(x):
return int(x[:-1]) / 1000. if x.endswith('m') else float(x)
return parse(a) == parse(b)
# Kubernetes outputs "creationTimestamp: null" in a blank object
# e.g. from kubectl create deploy foo --image=foo --output=yaml --dry-run
# so allow that to compare equal to any real value that comes back.
def creation_timestamp_equal(a, b):
"""Compares creation timestamps, allowing a source value of None to match any time"""
if a is None:
return True