Kubernetes Charm Libraries

  • Canonical Telco
Channel Revision Published Runs on
latest/edge 55 28 Oct 2024
Ubuntu 22.04
juju deploy kubernetes-charm-libraries --channel edge
Show information

Platform:

Ubuntu
22.04

charms.kubernetes_charm_libraries.v0.hugepages_volumes_patch

Charm library used to manage HugePages volumes in Kubernetes charms.

  • Using the configure endpoint, it will:
    • Replace the volumes in the StatefulSet with the new requested ones
    • Replace the volume mounts in the container in the Pod with the new requested ones.
    • Replace the resource requirements in the container in the Pod with the new requested ones.
Usage

from charms.kubernetes_charm_libraries.v0.kubernetes_hugepages_volumes_patch import (
    KubernetesHugePagesPatchCharmLib,
    HugePagesVolume,
)


class YourCharm(CharmBase):

    def __init__(self, *args):
        super().__init__(*args)
        self._kubernetes_volumes_patch = KubernetesHugePagesPatchCharmLib(
            statefulset_name=self.model.app.name,
            container_name=self._bessd_container_name,
            pod_name=self._pod_name,
            hugepages_volumes=self._volumes_request_from_config(),
        )
        self.framework.observe(self.on.config_changed, self.on_config_changed)

    def _volumes_request_from_config(self) -> list[HugePagesVolume]:
        return [
            HugePagesVolume(
                mount_path="/dev/hugepages",
                size="1Gi",
                limit="4Gi",
            )
        ]

    def on_config_changed(self, event: ConfigChangedEvent):
        self._kubernetes_volumes_patch.configure()

class HugePagesVolume

Description

HugePagesVolume. None

class KubernetesHugePagesVolumesPatchError

Description

KubernetesHugePagesVolumesPatchError. None

Methods

KubernetesHugePagesVolumesPatchError. __init__( self , message: str )

class KubernetesClient

Description

Class containing all the Kubernetes specific calls. None

Methods

KubernetesClient. __init__( self , namespace: str )

KubernetesClient. pod_is_patched( self , pod_name: str , requested_volumemounts , requested_resources: ResourceRequirements , container_name: str )

Return whether pod contains the given volumes mounts and resources.

Description

Args: pod_name: Pod name requested_volumemounts: Iterable of volume mounts requested_resources: requested resources container_name: Container name

Raises: KubernetesHugePagesVolumesPatchError: If the user-provided pod name does not exist.

Returns: bool: Whether pod contains the given volumes mounts and resources.

KubernetesClient. statefulset_is_patched( self , statefulset_name: str , requested_volumes )

Return whether the statefulset contains the given volumes.

Description

Args: statefulset_name: Statefulset name requested_volumes: Iterable of volumes

Raises: KubernetesHugePagesVolumesPatchError: If the user-provided statefulset name does not exist.

Returns: bool: Whether the statefulset contains the given volumes.

KubernetesClient. replace_statefulset( self , statefulset_name: str , requested_volumes , requested_volumemounts , requested_resources: ResourceRequirements , container_name: str )

Update a StatefulSet and a container in its spec.

Description

Raises: KubernetesHugePagesVolumesPatchError: If the user-provided statefulset name does not exist, or replacing statefulset failed.

Args: statefulset_name: Statefulset name requested_volumes: Iterable of new volumes to be set in the StatefulSet requested_volumemounts: Iterable of new volume mounts to be set in the given container requested_resources: new resource requirements to be set in the given container container_name: Container name

KubernetesClient. list_volumes( self , statefulset_name: str )

List current volumes in the given StatefulSet.

Description

Args: statefulset_name: Statefulset name

Raises: KubernetesHugePagesVolumesPatchError: If the user-provided statefulset name does not exist.

Returns: list[Volume]: List of current volumes in the given StatefulSet

KubernetesClient. list_volumemounts( self , statefulset_name: str , container_name: str )

List current volume mounts in the given container.

Description

Args: statefulset_name: Statefulset name container_name: Container name

Raises: KubernetesHugePagesVolumesPatchError: If the user-provided statefulset name does not exist.

Returns: list[VolumeMount]: List of current volume mounts in the given container

KubernetesClient. list_container_resources( self , statefulset_name: str , container_name: str )

Return resource requirements in the given container.

Description

Args: statefulset_name: Statefulset name container_name: Container name

Raises: KubernetesHugePagesVolumesPatchError: If the user-provided statefulset name does not exist.

Returns: ResourceRequirements: resource requirements in the given container

class KubernetesHugePagesPatchCharmLib

Description

Class to be instantiated by charms requiring changes in HugePages volumes. None

Methods

KubernetesHugePagesPatchCharmLib. __init__( self , hugepages_volumes , namespace: str , statefulset_name: str , container_name: str , pod_name: str )

Construct the KubernetesHugePagesPatchCharmLib.

Arguments

hugepages_volumes

list of HugePagesVolume to be created.

namespace

Namespace where the StatefulSet is located

statefulset_name

Statefulset name

container_name

Container name

pod_name

Pod name

KubernetesHugePagesPatchCharmLib. configure( self )

Description

Configure HugePages in the StatefulSet and container. None

KubernetesHugePagesPatchCharmLib. is_patched( self )

Return whether statefulset and pod are patched.

Returns

bool

Whether statefulset and pod are patched.

Description

Validates that the statefulset contains the appropriate volumes and that the pod also contains the appropriate volume mounts and resource requirements.