---
title: Charmhub | Deploy Observability Libs using Charmhub - The Open Operator Collection
description: Deploy the latest version of Observability Libs as a Kubernetes Operator
  on any cloud.
url: https://charmhub.io/observability-libs/libraries/kubernetes_service_patch
---

# Observability Libs

[Jon Seager](https://charmhub.io/publisher/jnsgruk "View all packages from Jon Seager")

* [Jon Seager](https://charmhub.io/publisher/jnsgruk "View all packages from Jon Seager")

Platform:

edge 454c1f8

```
juju deploy observability-libs --channel edge
```

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

[Toggle side navigation](https://charmhub.io/observability-libs/libraries/kubernetes_service_patch#drawer)

## charms.observability\_libs.v1.kubernetes\_service\_patch

* [*Docstrings*Docstrings](https://charmhub.io/observability-libs/libraries/kubernetes_service_patch)
  [*Code*Source code](https://charmhub.io/observability-libs/libraries/kubernetes_service_patch/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.observability_libs.v1.kubernetes_service_patch
    ```

    [Download kubernetes\_service\_patch.py](https://charmhub.io/observability-libs/libraries/kubernetes_service_patch/download)
  + *Last updated* 05 Dec 2024
  + *Revision* Library version 1.13

#### [DEPRECATED!] KubernetesServicePatch Library.

The `kubernetes_service_patch` library is DEPRECATED and will be removed in October 2025.

For patching the Kubernetes service created by Juju during the deployment of a charm,
`ops.Unit.set_ports` functionality should be used instead.

---

Index

* [class KubernetesServicePatch](https://charmhub.io/observability-libs/libraries/kubernetes_service_patch#kubernetesservicepatch)
* + [def \_\_init\_\_(
    self,
    charm,
    ports,
    service\_name,
    service\_type,
    additional\_labels,
    additional\_selectors,
    additional\_annotations)](https://charmhub.io/observability-libs/libraries/kubernetes_service_patch#kubernetesservicepatch-__init__)
* + [def is\_patched(
    self)](https://charmhub.io/observability-libs/libraries/kubernetes_service_patch#kubernetesservicepatch-is_patched)

#### class KubernetesServicePatch

Description

A utility for patching the Kubernetes service set up by Juju. None

Methods

KubernetesServicePatch.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
ports

,
service\_name

,
service\_type: ServiceType

,
additional\_labels

,
additional\_selectors

,
additional\_annotations
)

Constructor for KubernetesServicePatch.

Arguments

charm

the charm that is instantiating the library.

ports

a list of ServicePorts

service\_name

allows setting custom name to the patched service. If none given,
application name will be used.

service\_type

desired type of K8s service. Default value is in line with ServiceSpec's
default value.

additional\_labels

Labels to be added to the kubernetes service (by default only
"app.kubernetes.io/name" is set to the service name)

additional\_selectors

Selectors to be added to the kubernetes service (by default only
"app.kubernetes.io/name" is set to the service name)

additional\_annotations

Annotations to be added to the kubernetes service.

refresh\_event

an optional bound event or list of bound events which
will be observed to re-apply the patch (e.g. on port change).
The `install` and `upgrade-charm` events would be observed regardless.

KubernetesServicePatch.
is\_patched(

*self*
)

Reports if the service patch has been applied.

Returns

bool

A boolean indicating if the service patch has been applied.
