---
title: Charmhub | Deploy Kubernetes Charm Libraries using Charmhub - The Open Operator
  Collection
description: Deploy the latest version of Kubernetes Charm Libraries on any cloud.
url: https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch
---

# Kubernetes Charm Libraries

[Canonical Telco](https://charmhub.io/publisher/telco-charmers "View all packages from Canonical Telco")

* [Canonical Telco](https://charmhub.io/publisher/telco-charmers "View all packages from Canonical Telco")

Platform:

22.04

edge 65

```
juju deploy kubernetes-charm-libraries --channel edge
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#drawer)

## charms.kubernetes\_charm\_libraries.v0.hugepages\_volumes\_patch

* [*Docstrings*Docstrings](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch)
  [*Code*Source code](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.kubernetes_charm_libraries.v0.hugepages_volumes_patch
    ```

    [Download hugepages\_volumes\_patch.py](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch/download)
  + *Last updated* 13 Sep 2024
  + *Revision* Library version 0.6

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()
```

---

Index

* [class HugePagesVolume](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#hugepagesvolume)
* [class KubernetesHugePagesVolumesPatchError](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kuberneteshugepagesvolumespatcherror)
* + [def \_\_init\_\_(
    self,
    message)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kuberneteshugepagesvolumespatcherror-__init__)
* [class KubernetesClient](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kubernetesclient)
* + [def \_\_init\_\_(
    self,
    namespace)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kubernetesclient-__init__)
* + [def pod\_is\_patched(
    self,
    pod\_name,
    requested\_volumemounts,
    requested\_resources,
    container\_name)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kubernetesclient-pod_is_patched)
* + [def statefulset\_is\_patched(
    self,
    statefulset\_name,
    requested\_volumes)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kubernetesclient-statefulset_is_patched)
* + [def replace\_statefulset(
    self,
    statefulset\_name,
    requested\_volumes,
    requested\_volumemounts,
    requested\_resources,
    container\_name)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kubernetesclient-replace_statefulset)
* + [def list\_volumes(
    self,
    statefulset\_name)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kubernetesclient-list_volumes)
* + [def list\_volumemounts(
    self,
    statefulset\_name,
    container\_name)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kubernetesclient-list_volumemounts)
* + [def list\_container\_resources(
    self,
    statefulset\_name,
    container\_name)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kubernetesclient-list_container_resources)
* [class KubernetesHugePagesPatchCharmLib](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kuberneteshugepagespatchcharmlib)
* + [def \_\_init\_\_(
    self,
    hugepages\_volumes,
    namespace,
    statefulset\_name,
    container\_name,
    pod\_name)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kuberneteshugepagespatchcharmlib-__init__)
* + [def configure(
    self)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kuberneteshugepagespatchcharmlib-configure)
* + [def is\_patched(
    self)](https://charmhub.io/kubernetes-charm-libraries/libraries/hugepages_volumes_patch#kuberneteshugepagespatchcharmlib-is_patched)

#### 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.
