crate.operator.utils.formatting module

crate.operator.utils.formatting.b64decode(s: str) str

Wrapper to base 64 encode a string and return a string.

crate.operator.utils.formatting.b64encode(s: str) str

Wrapper to base 64 decode a string and return a string.

crate.operator.utils.formatting.convert_to_bytes(value)

Converts disk size strings used in Kubernetes, e.g. "256Gi" or Bytes to bitmath.Byte.

Parameters

value (Union[str, int]) –

Return type

Byte

crate.operator.utils.formatting.encode_decode_wrapper(fn, s)

Encode s to bytes, call fn with that and decode the result again.

The function uses UTF-8 for encoding and decoding.

Parameters
  • fn (Callable[[bytes], bytes]) – A function that should be called with the byte encoding and who’s response should be decoded to string again.

  • s (str) – The string to encode, pass to fn, and decode.

Return type

str

crate.operator.utils.formatting.format_bitmath(value)

Format a bitmath.Byte such that it is safe to use with Kubernetes.

Under the hood, the format {value}{unit} is used, but without the trailing B. Additionally, the “best” unit is picked. For example, passing bitmath.GiB(0.25) would result in "256Mi".

Parameters

value (Byte) –

Return type

str