piceli.k8s.templates.auxiliary.resource_request#

Module Contents#

Classes#

Resources

Represents Kubernetes resources, facilitating arithmetic operations and validation.

ContainerResourcesData

Resources of a kubernetes container

ResourcesData

Resources of a kubernetes pod

NodeResources

Resources of a kubernetes node

ClusterResources

Resources of a kubernetes cluster

API#

class piceli.k8s.templates.auxiliary.resource_request.Resources[source]#

Represents Kubernetes resources, facilitating arithmetic operations and validation.

Attributes: :param Optional[str] memory: The amount of memory allocated for the resource. Specified in Kubernetes quantity string format (e.g., ‘200Mi’, ‘1Gi’). :param Optional[str] cpu: The amount of CPU allocated for the resource. Specified in Kubernetes quantity string format (e.g., ‘100m’ for 100 millicpu). :param Optional[str] ephemeral_storage: The amount of ephemeral storage allocated for the resource. Specified in Kubernetes quantity string format.

The class supports creating Resources objects from dictionaries, converting between string and numerical representations, and performing arithmetic operations on resource quantities. These capabilities are essential for managing resource allocations in Kubernetes deployments.

memory: Optional[str]#

None

cpu: Optional[str]#

None

ephemeral_storage: Optional[str]#

None

classmethod from_dict(resources: dict[str, str]) piceli.k8s.templates.auxiliary.resource_request.Resources[source]#

Creates a Resources object from a dictionary of string quantities.

Parameters:

resources (dict[str, str]) – A dictionary where keys are resource types (‘memory’, ‘cpu’, ‘ephemeral-storage’) and values are quantities in string format.

Returns:

A Resources object with the specified resources.

classmethod from_quantity_dict(resources: dict[str, int | float | None]) piceli.k8s.templates.auxiliary.resource_request.Resources[source]#

Creates a Resources object from a dictionary of quantities, converting them to string format.

Parameters:

resources (dict[str, int | float | None]) – A dictionary where keys are resource types and values are quantities in kilo, mega, etc.

Returns:

A Resources object with resources converted to Kubernetes-compatible string representations.

to_dict() dict[str, str][source]#

creates a dict from a Resources object

to_quantity_dict() dict[str, Optional[float]][source]#

creates a dict from a Resources object containing the quantity in k

__post_init__() None[source]#
get_k8s_request() dict[source]#

returns a dict compatible with kubernetes client

get_quantity(resource: str) int | float[source]#

gets the quantity in k from a resource (cpu can be a float)

static _bytes_to_str(num: float, base: int, suffix: str) str[source]#
static _cores_to_str(num: float) str[source]#
static bytes_to_str(num: float, resource: str) str[source]#

gets a human readable string representation

property resources: list[str]#

gets a list of the resources specified in this object

__add__(other: piceli.k8s.templates.auxiliary.resource_request.Resources) piceli.k8s.templates.auxiliary.resource_request.Resources[source]#
__sub__(other: piceli.k8s.templates.auxiliary.resource_request.Resources) piceli.k8s.templates.auxiliary.resource_request.Resources[source]#
__abs__() piceli.k8s.templates.auxiliary.resource_request.Resources[source]#
__mul__(other: float | int) piceli.k8s.templates.auxiliary.resource_request.Resources[source]#
__truediv__(other: Union[float, int, piceli.k8s.templates.auxiliary.resource_request.Resources]) Union[piceli.k8s.templates.auxiliary.resource_request.Resources, float][source]#
__eq__(other: object) bool[source]#
any_lower(other: piceli.k8s.templates.auxiliary.resource_request.Resources) bool[source]#

if any of the values is lower it will return True

any_greater(other: piceli.k8s.templates.auxiliary.resource_request.Resources) bool[source]#

if any of the values is greater it will return True

get_cpu_memory_ratio() float[source]#

returns the ratio between cpu and memory (CPU:memory ratio (vCPU:GiB)

class piceli.k8s.templates.auxiliary.resource_request.ContainerResourcesData[source]#

Resources of a kubernetes container

container_name: str#

None

requested_resources: piceli.k8s.templates.auxiliary.resource_request.Resources#

None

used_resources: piceli.k8s.templates.auxiliary.resource_request.Resources#

None

property max_usage: Optional[float]#

returns the max usage of the pod max(used_cpu/requested_cpu, used_memory/requested_memory)

__str__() str[source]#
class piceli.k8s.templates.auxiliary.resource_request.ResourcesData[source]#

Resources of a kubernetes pod

pod_name: str#

None

labels: dict[str, str]#

None

node_name: Optional[str]#

None

pod_status: Optional[str]#

None

pod_status_reason: Optional[str]#

None

pod_status_message: Optional[str]#

None

last_update: Optional[datetime.datetime]#

None

containers: dict[str, piceli.k8s.templates.auxiliary.resource_request.ContainerResourcesData]#

‘field(…)’

property max_usage: Optional[float]#

returns the max usage of the pod max(used_cpu/requested_cpu, used_memory/requested_memory)

property summary: list[str]#

Returns a list of string summarizing pod data

class piceli.k8s.templates.auxiliary.resource_request.NodeResources[source]#

Resources of a kubernetes node

node_name: str#

None

allocatable: piceli.k8s.templates.auxiliary.resource_request.Resources#

None

capacity: piceli.k8s.templates.auxiliary.resource_request.Resources#

None

allocatable_pods: int#

None

capacity_pods: int#

None

classmethod from_node_status(node: kubernetes.client.V1Node) piceli.k8s.templates.auxiliary.resource_request.NodeResources[source]#

creates a ClusterResources object from a list of kubernetes nodes

class piceli.k8s.templates.auxiliary.resource_request.ClusterResources[source]#

Resources of a kubernetes cluster

total_allocatable: piceli.k8s.templates.auxiliary.resource_request.Resources#

None

total_capacity: piceli.k8s.templates.auxiliary.resource_request.Resources#

None

total_allocatable_pods: int#

None

total_capacity_pods: int#

None

nodes: list[piceli.k8s.templates.auxiliary.resource_request.NodeResources]#

None

pods_map: dict[str, piceli.k8s.templates.auxiliary.resource_request.ResourcesData]#

None

property pods: list[piceli.k8s.templates.auxiliary.resource_request.ResourcesData]#

returns a list of pods

get_pod(pod_name: str) piceli.k8s.templates.auxiliary.resource_request.ResourcesData | None[source]#

returns a pod by name

classmethod from_cluster_info(nodes: list[kubernetes.client.V1Node], pods: list[kubernetes.client.V1Pod], pods_metrics: list[dict]) piceli.k8s.templates.auxiliary.resource_request.ClusterResources[source]#

creates a ClusterResources object from a list of kubernetes nodes