---
title: Charmhub | Deploy Kubernetes using Charmhub - The Open Operator Collection
description: Deploy the latest version of Kubernetes on any cloud.
url: https://charmhub.io/k8s/libraries/k8sd_api_manager
---

# Kubernetes

[Canonical Kubernetes](https://charmhub.io/publisher/containers "View all packages from Canonical Kubernetes")

* [Canonical Kubernetes](https://charmhub.io/publisher/containers "View all packages from Canonical Kubernetes")

Platform:

26.04

24.04

22.04

20.04

1.32/stable 1918

```
juju deploy k8s --channel 1.32/stable
```

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

[Toggle side navigation](https://charmhub.io/k8s/libraries/k8sd_api_manager#drawer)

## charms.k8s.v0.k8sd\_api\_manager

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

    Fetch library

    ```
    charmcraft fetch-lib charms.k8s.v0.k8sd_api_manager
    ```

    [Download k8sd\_api\_manager.py](https://charmhub.io/k8s/libraries/k8sd_api_manager/download)
  + *Last updated* 18 Jun 2025
  + *Revision* Library version 0.8

Module for managing k8sd API interactions.

This module provides a high-level interface for interacting with K8sd. It
simplifies tasks such as token management and component updates.

The core of the module is the K8sdAPIManager, which handles the creation
and management of HTTP connections to interact with the k8sd API. This
class utilises different connection factories (UnixSocketConnectionFactory
and HTTPConnectionFactory) to establish connections through either Unix
sockets or HTTP protocols.

Example usage for creating a join token for K8sd:

```
try:
    factory = UnixSocketConnectionFactory('/path/to/socket')
    api_manager = K8sdAPIManager(factory)
    join_token = api_manager.create_join_token('node-name')
except K8sdAPIManagerError as e:
    logger.error("An error occurred: %s", e.message)
```

Similarly, the module allows for requesting authentication tokens and
managing K8s components.

---

Index

* [class ErrorCodes](https://charmhub.io/k8s/libraries/k8sd_api_manager#errorcodes)
* [class K8sdAPIManagerError](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanagererror)
* [class K8sdConnectionError](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdconnectionerror)
* [class InvalidResponseError](https://charmhub.io/k8s/libraries/k8sd_api_manager#invalidresponseerror)
* + [def \_\_init\_\_(
    self,
    code,
    msg,
    method,
    endpoint,
    reason,
    body)](https://charmhub.io/k8s/libraries/k8sd_api_manager#invalidresponseerror-__init__)
* [class BaseRequestModel](https://charmhub.io/k8s/libraries/k8sd_api_manager#baserequestmodel)
* + [def check\_status\_code(
    cls,
    v)](https://charmhub.io/k8s/libraries/k8sd_api_manager#baserequestmodel-check_status_code)
* + [def check\_error\_code(
    cls,
    v,
    info)](https://charmhub.io/k8s/libraries/k8sd_api_manager#baserequestmodel-check_error_code)
* [class EmptyResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#emptyresponse)
* [class TokenMetadata](https://charmhub.io/k8s/libraries/k8sd_api_manager#tokenmetadata)
* [class AuthTokenResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#authtokenresponse)
* [class CreateJoinTokenResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#createjointokenresponse)
* [class ClusterMember](https://charmhub.io/k8s/libraries/k8sd_api_manager#clustermember)
* [class DNSConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#dnsconfig)
* [class IngressConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#ingressconfig)
* [class LoadBalancerConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#loadbalancerconfig)
* [class LocalStorageConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#localstorageconfig)
* [class NetworkConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#networkconfig)
* [class GatewayConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#gatewayconfig)
* [class MetricsServerConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#metricsserverconfig)
* [class UserFacingClusterConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#userfacingclusterconfig)
* [class UserFacingDatastoreConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#userfacingdatastoreconfig)
* [class BootstrapConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#bootstrapconfig)
* [class CreateClusterRequest](https://charmhub.io/k8s/libraries/k8sd_api_manager#createclusterrequest)
* [class UpdateClusterConfigRequest](https://charmhub.io/k8s/libraries/k8sd_api_manager#updateclusterconfigrequest)
* [class NodeJoinConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#nodejoinconfig)
* [class ControlPlaneNodeJoinConfig](https://charmhub.io/k8s/libraries/k8sd_api_manager#controlplanenodejoinconfig)
* [class JoinClusterRequest](https://charmhub.io/k8s/libraries/k8sd_api_manager#joinclusterrequest)
* + [def serialize\_token(
    self,
    token)](https://charmhub.io/k8s/libraries/k8sd_api_manager#joinclusterrequest-serialize_token)
* + [def serialize\_config(
    self,
    config)](https://charmhub.io/k8s/libraries/k8sd_api_manager#joinclusterrequest-serialize_config)
* [class DatastoreStatus](https://charmhub.io/k8s/libraries/k8sd_api_manager#datastorestatus)
* [class ClusterStatus](https://charmhub.io/k8s/libraries/k8sd_api_manager#clusterstatus)
* [class ClusterMetadata](https://charmhub.io/k8s/libraries/k8sd_api_manager#clustermetadata)
* [class GetClusterStatusResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#getclusterstatusresponse)
* [class KubeConfigMetadata](https://charmhub.io/k8s/libraries/k8sd_api_manager#kubeconfigmetadata)
* [class GetKubeConfigResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#getkubeconfigresponse)
* [class RefreshCertificatesPlanMetadata](https://charmhub.io/k8s/libraries/k8sd_api_manager#refreshcertificatesplanmetadata)
* [class RefreshCertificatesPlanResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#refreshcertificatesplanresponse)
* [class RefreshCertificatesRunRequest](https://charmhub.io/k8s/libraries/k8sd_api_manager#refreshcertificatesrunrequest)
* [class RefreshCertificatesRunMetadata](https://charmhub.io/k8s/libraries/k8sd_api_manager#refreshcertificatesrunmetadata)
* [class RefreshCertificatesRunResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#refreshcertificatesrunresponse)
* [class GetClusterConfigMetadata](https://charmhub.io/k8s/libraries/k8sd_api_manager#getclusterconfigmetadata)
* [class GetClusterConfigResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#getclusterconfigresponse)
* [class NodeStatus](https://charmhub.io/k8s/libraries/k8sd_api_manager#nodestatus)
* [class GetNodeStatusMetadata](https://charmhub.io/k8s/libraries/k8sd_api_manager#getnodestatusmetadata)
* [class GetNodeStatusResponse](https://charmhub.io/k8s/libraries/k8sd_api_manager#getnodestatusresponse)
* [class UnixSocketHTTPConnection](https://charmhub.io/k8s/libraries/k8sd_api_manager#unixsockethttpconnection)
* + [def \_\_init\_\_(
    self,
    unix\_socket,
    timeout)](https://charmhub.io/k8s/libraries/k8sd_api_manager#unixsockethttpconnection-__init__)
* + [def connect(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#unixsockethttpconnection-connect)
* [class ConnectionFactory](https://charmhub.io/k8s/libraries/k8sd_api_manager#connectionfactory)
* + [def create\_connection(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#connectionfactory-create_connection)
* [class UnixSocketConnectionFactory](https://charmhub.io/k8s/libraries/k8sd_api_manager#unixsocketconnectionfactory)
* + [def \_\_init\_\_(
    self,
    unix\_socket,
    timeout)](https://charmhub.io/k8s/libraries/k8sd_api_manager#unixsocketconnectionfactory-__init__)
* + [def create\_connection(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#unixsocketconnectionfactory-create_connection)
* [class HTTPConnectionFactory](https://charmhub.io/k8s/libraries/k8sd_api_manager#httpconnectionfactory)
* + [def \_\_init\_\_(
    self,
    host,
    port,
    timeout)](https://charmhub.io/k8s/libraries/k8sd_api_manager#httpconnectionfactory-__init__)
* + [def create\_connection(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#httpconnectionfactory-create_connection)
* [class K8sdAPIManager](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager)
* + [def \_\_init\_\_(
    self,
    factory)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-__init__)
* + [def create\_join\_token(
    self,
    name,
    worker)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-create_join_token)
* + [def join\_cluster(
    self,
    config)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-join_cluster)
* + [def remove\_node(
    self,
    name,
    force)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-remove_node)
* + [def update\_cluster\_config(
    self,
    config)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-update_cluster_config)
* + [def get\_cluster\_config(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-get_cluster_config)
* + [def get\_node\_status(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-get_node_status)
* + [def get\_cluster\_status(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-get_cluster_status)
* + [def is\_cluster\_bootstrapped(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-is_cluster_bootstrapped)
* + [def is\_cluster\_ready(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-is_cluster_ready)
* + [def check\_k8sd\_ready(
    self)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-check_k8sd_ready)
* + [def bootstrap\_k8s\_snap(
    self,
    request)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-bootstrap_k8s_snap)
* + [def request\_auth\_token(
    self,
    username,
    groups)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-request_auth_token)
* + [def revoke\_auth\_token(
    self,
    token)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-revoke_auth_token)
* + [def get\_kubeconfig(
    self,
    server)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-get_kubeconfig)
* + [def refresh\_certs(
    self,
    extra\_sans,
    expiration\_seconds)](https://charmhub.io/k8s/libraries/k8sd_api_manager#k8sdapimanager-refresh_certs)

#### class ErrorCodes

Enumerate the response codes from the k8s api.

Attributes

STATUS\_NODE\_UNAVAILABLE

returned when the node isn't in the cluster

STATUS\_NODE\_IN\_USE

returned when the node is in the cluster already

#### class K8sdAPIManagerError

Description

Base exception for K8sd API Manager errors. None

#### class K8sdConnectionError

Description

Raised when there is a connection error. None

#### class InvalidResponseError

Raised when the response is invalid or unexpected.

Attributes

code
(int)

HTTP Status code

Methods

InvalidResponseError.
\_\_init\_\_(

*self*

,
code: int

,
msg: str

,
method

,
endpoint

,
reason

,
body
)

Initialise the InvalidResponseError.

Arguments

code
(int)

http response code

msg
(str)

Message associated with the error

method
(Optional[str])

The method used to make the request

endpoint
(Optional[str])

The endpoint used to make the request

reason
(Optional[str])

The reason for the error

body
(Optional[str])

The body of the response

#### class BaseRequestModel

Base model for k8s request responses.

Attributes

type
(str)

The type of the request.

status
(str)

The status of the response, defaults to an empty string.

status\_code
(int)

The status code of the response.

operation
(str)

The operation of the request, defaults to an empty string.

error\_code
(int)

The error code associated with the response.

error
(str)

The error message, defaults to an empty string.

Methods

BaseRequestModel.
check\_status\_code(

cls

,
v
)

Validate the status\_code field.

Arguments

v
(int)

The value of the status\_code field to validate.

Returns

int

The validated status code if it is 200.

BaseRequestModel.
check\_error\_code(

cls

,
v

,
info: ValidationInfo
)

Validate the error\_code field.

Arguments

v
(int)

The value of the error\_code field to validate.

info
(ValidationInfo)

The validation information.

Returns

int

The validated error code if it is 0.

#### class EmptyResponse

Description

Response model for request that do not expect any return value. None

#### class TokenMetadata

Model representing metadata for a token.

Attributes

token
(SecretStr)

The token string. (accessible via .get\_secret\_value() )

#### class AuthTokenResponse

Response model for Kubernetes authentication token requests.

Attributes

metadata
(TokenMetadata)

Metadata containing the authentication token.

#### class CreateJoinTokenResponse

Response model for join token creation requests.

Attributes

metadata
(TokenMetadata)

Metadata containing the join token.

#### class ClusterMember

Represents a member in the k8sd cluster.

Attributes

name
(str)

Name of the cluster member.

address
(str)

Address of the cluster member.

cluster\_role
(str)

Cluster Role of the node in the cluster.

datastore\_role
(str)

Role of the member in the cluster.

#### class DNSConfig

Configuration for the DNS settings of the cluster.

Attributes

model\_config

ConfigDict instance for the model.

enabled

Optional flag which.

cluster\_domain

The domain name of the cluster.

service\_ip

The IP address of the DNS service within the cluster.

upstream\_nameservers

List of upstream nameservers for DNS resolution.

#### class IngressConfig

Configuration for the ingress settings of the cluster.

Attributes

model\_config

ConfigDict instance for the model.

enabled

Optional flag which represents the status of Ingress.

enable\_proxy\_protocol

Optional flag to enable or disable proxy protocol.

#### class LoadBalancerConfig

Configuration for the load balancer settings of the cluster.

Attributes

model\_config

ConfigDict instance for the model.

enabled

Optional flag which represents the status of LoadBalancer.

cidrs

List of CIDR blocks for the load balancer.

l2\_mode

Optional flag to enable or disable layer 2 mode.

l2\_interfaces

List of layer 2 interfaces for the load balancer.

bgp\_mode

Optional flag to enable or disable BGP.

bgp\_local\_asn

The local ASN for BGP configuration.

bgp\_peer\_address

The peer address for BGP configuration.

bgp\_peer\_asn

The peer ASN for BGP configuration.

bgp\_peer\_port

The port for BGP peering.

#### class LocalStorageConfig

Configuration for the local storage settings of the cluster.

Attributes

model\_config

ConfigDict instance for the model.

enabled

Optional flag which represents the status of Storage.

local\_path

The local path for storage.

reclaim\_policy

The policy for reclaiming local storage.

set\_default

Optional flag to set this as the default storage option.

#### class NetworkConfig

Configuration for the network settings of the cluster.

Attributes

model\_config

ConfigDict instance for the model.

enabled

Optional flag which represents the status of Network.

#### class GatewayConfig

Configuration for the gateway settings of the cluster.

Attributes

model\_config

ConfigDict instance for the model.

enabled

Optional flag which represents the status of Gateway.

#### class MetricsServerConfig

Configuration for the metrics server settings of the cluster.

Attributes

model\_config

ConfigDict instance for the model.

enabled

Optional flag which represents the status of MetricsServer.

#### class UserFacingClusterConfig

Aggregated configuration model for the user-facing aspects of a cluster.

Attributes

model\_config

ConfigDict instance for the model.

network

Network configuration for the cluster.

dns

DNS configuration for the cluster.

ingress

Ingress configuration for the cluster.

load\_balancer

Load balancer configuration for the cluster.

local\_storage

Local storage configuration for the cluster.

gateway

Gateway configuration for the cluster.

metrics\_server

Metrics server configuration for the cluster.

cloud\_provider

The cloud provider for the cluster.

annotations

Dictionary that can be used to store arbitrary metadata configuration.

#### class UserFacingDatastoreConfig

Aggregated configuration model for the user-facing datastore aspects of a cluster.

Attributes

model\_config

ConfigDict instance for the model.

type

Type of the datastore. For runtime updates, this needs to be "external".

servers

Server addresses of the external datastore.

ca\_crt

CA certificate of the external datastore cluster in PEM format.

client\_crt

client certificate of the external datastore cluster in PEM format.

client\_key

client key of the external datastore cluster in PEM format.

#### class BootstrapConfig

Configuration model for bootstrapping a Canonical K8s cluster.

Attributes

cluster\_config
(UserFacingClusterConfig)

The cluster configuration settings.

control\_plane\_taints
(List[str])

Register with the following control-plane taints

pod\_cidr
(str)

The IP address range for the cluster's pods.

service\_cidr
(str)

The IP address range for the cluster services.

disable\_rbac
(bool)

Flag to disable role-based access control

secure\_port
(int)

The secure port used for Kubernetes.

k8s\_dqlite\_port
(int)

The port used by Dqlite.

datastore\_type
(str)

The type of datastore used by the cluster.

datastore\_servers
(List[str])

The servers used by the datastore.

datastore\_ca\_cert
(str)

The CA certificate for the datastore.

datastore\_client\_cert
(str)

The client certificate for accessing the datastore.

datastore\_client\_key
(str)

The client key for accessing the datastore.

extra\_sans
(List[str])

List of extra sans for the self-signed certificates

ca\_cert
(str)

The CA certificate for Kubernetes services.

ca\_key
(str)

The CA key for Kubernetes services.

client\_ca\_cert
(str)

The client CA certificate for Kubernetes services.

client\_ca\_key
(str)

The client CA key for Kubernetes services.

front\_proxy\_ca\_cert
(str)

The front proxy CA certificate.

front\_proxy\_ca\_key
(str)

The front proxy CA key.

front\_proxy\_client\_cert
(str)

The front proxy client certificate.

front\_proxy\_client\_key
(str)

The front proxy client key.

api\_server\_kubelet\_client\_cert
(str)

The kubelet client certificate for the API server.

api\_server\_kubelet\_client\_key
(str)

The kubelet client key for the API server.

admin\_client\_cert
(str)

The admin client certificate.

admin\_client\_key
(str)

The admin client key.

kube\_proxy\_client\_cert
(str)

The kube-proxy client certificate.

kube\_proxy\_client\_key
(str)

The kube-proxy client key.

kube\_scheduler\_client\_cert
(str)

The kube-scheduler client certificate.

kube\_scheduler\_client\_key
(str)

The kube-scheduler client key.

kube\_controller\_manager\_client\_cert
(str)

The controller manager client certificate.

kube\_controller\_manager\_client\_key
(str)

The controller manager client key.

service\_account\_key
(str)

The service account key.

api\_server\_cert
(str)

The API server certificate.

api\_server\_key
(str)

The API server key.

kubelet\_cert
(str)

The kubelet certificate.

kubelet\_key
(str)

The kubelet key.

kubelet\_client\_cert
(str)

The kubelet client certificate.

kubelet\_client\_key
(str)

The kubelet client key.

extra\_node\_config\_files
(Dict[str, str])

Additional configuration files for nodes.

extra\_node\_kube\_apiserver\_args
(Dict[str, Optional[str]])

key-value
service args .

extra\_node\_kube\_controller\_manager\_args
(Dict[str, Optional[str]])

key-value service args .

extra\_node\_kube\_scheduler\_args
(Dict[str, Optional[str]])

key-value
service args .

extra\_node\_kube\_proxy\_args
(Dict[str, Optional[str]])

key-value
service args .

extra\_node\_kubelet\_args
(Dict[str, Optional[str]])

key-value service
args .

extra\_node\_containerd\_args
(Dict[str, Optional[str]])

key-value
service args .

extra\_node\_k8s\_dqlite\_args
(Dict[str, Optional[str]])

key-value
service args

extra\_node\_containerd\_config
(Dict[str, Any])

key-value config args

containerd\_base\_dir
(str)

The base directory for containerd.

#### class CreateClusterRequest

Request model for creating a new Canonical Kubernetes cluster.

Attributes

name
(str)

The name of the cluster to be created.

address
(str)

The address where the cluster is hosted.

config
(BootstrapConfig)

Additional configuration parameters for the cluster.

#### class UpdateClusterConfigRequest

Request model for updating Cluster config.

Attributes

config
(Optional[UserFacingClusterConfig])

The cluster configuration.

datastore
(Optional[UserFacingDatastoreConfig])

The clusters datastore configuration.

#### class NodeJoinConfig

Request model for the config on a node joining the cluster.

Attributes

model\_config

ConfigDict instance for the model.

kubelet\_cert
(str)

node's certificate

kubelet\_key
(str)

node's certificate key

kubelet\_client\_cert
(str)

Kubelet client certificate

kubelet\_client\_key
(str)

Kubelet client key

kube\_proxy\_client\_cert
(str)

Kube-proxy client certificate

kube\_proxy\_client\_key
(str)

Kube-proxy client key

extra\_node\_kube\_proxy\_args
(Dict[str, str])

key-value service args

extra\_node\_kubelet\_args
(Dict[str, str])

key-value service args

extra\_node\_containerd\_args
([Dict[str,str]])

key-value service args

extra\_node\_containerd\_config
([Dict[str,Any]])

key-value config args

containerd\_base\_dir
(str)

The base directory for containerd.

#### class ControlPlaneNodeJoinConfig

Request model for the config on a control-plane node joining the cluster.

Attributes

model\_config

ConfigDict instance for the model.

extra\_sans
(List[str])

List of extra sans for the self-signed certificates

apiserver\_crt
(str)

API server certificate

apiserver\_key
(str)

API server certificate key

front\_proxy\_client\_crt
(str)

Front proxy client certificate

front\_proxy\_client\_key
(str)

Front proxy client key

admin\_client\_cert
(str)

Admin client certificate

admin\_client\_key
(str)

Admin client key

kube\_scheduler\_client\_cert
(str)

Kube-scheduler client certificate

kube\_scheduler\_client\_key
(str)

Kube-scheduler client key

kube\_controller\_manager\_client\_cert
(str)

Controller manager client certificate

kube\_controller\_manager\_client\_key
(str)

Controller manager client key

extra\_node\_config\_files
(Dict[str, str])

Additional node config files

extra\_node\_kube\_apiserver\_args
(Dict[str, Optional[str]])

API server args .

extra\_node\_kube\_controller\_manager\_args
(Dict[str, Optional[str]])

Controller manager args

extra\_node\_kube\_scheduler\_args
(Dict[str, Optional[str]])

Scheduler args

extra\_node\_k8s\_dqlite\_args
(Dict[str, Optional[str]])

Dqlite args

extra\_node\_containerd\_config
(Dict[str, Any])

Containerd config

#### class JoinClusterRequest

Request model for a node joining the cluster.

Attributes

model\_config

ConfigDict instance for the model.

name
(str)

node's certificate

address
(str)

node's certificate key

token
(str)

token

config
(NodeJoinConfig)

Node Config

Methods

JoinClusterRequest.
serialize\_token(

*self*

,
token: SecretStr
)

Serialize the token to a string.

Arguments

token
(SecretStr)

The token to serialize.

Returns

str

The serialized token.

JoinClusterRequest.
serialize\_config(

*self*

,
config
)

Serialize the config to a YAML string.

Arguments

config
(Optional[NodeJoinConfig])

The config to serialize.

Returns

Optional[str]

The serialized config.

#### class DatastoreStatus

information regarding the active datastore.

Attributes

datastore\_type
(str)

external or k8s-dqlite datastore

servers

(List(str)): list of server addresses of the external datastore cluster.

#### class ClusterStatus

Represents the overall status of the k8sd cluster.

Attributes

ready
(bool)

Indicates if the cluster is ready.

members
(List[ClusterMember])

List of members in the cluster.

config
(UserFacingClusterConfig)

information about the cluster configuration.

datastore
(DatastoreStatus)

information regarding the active datastore.

#### class ClusterMetadata

Metadata containing status information about the k8sd cluster.

Attributes

status
(ClusterStatus)

The status of the k8sd cluster.

#### class GetClusterStatusResponse

Response model for getting the status of the k8sd cluster.

Attributes

metadata
(ClusterMetadata)

Metadata containing the cluster status.
Can be None if the status is not available.

#### class KubeConfigMetadata

Metadata containing kubeconfig.

Attributes

kubeconfig
(KubeConfigMetadata)

The status of the k8sd cluster.

#### class GetKubeConfigResponse

Response model for getting the kubeconfig from the cluster.

Attributes

metadata
(KubeconfigMetadata)

Metadata containing the kubeconfig.

#### class RefreshCertificatesPlanMetadata

Metadata for the certificates plan response.

Description

Attributes:
model\_config: ConfigDict instance for the model.
seed (int): The seed for the new certificates.
certificate\_signing\_requests (Optional[list[str]]): List of names
of the CertificateSigningRequests that need to be signed externally (for worker nodes).

#### class RefreshCertificatesPlanResponse

Response model for the refresh certificates plan.

Attributes

metadata
(RefreshCertificatesPlanMetadata)

Metadata for the certificates plan response.

#### class RefreshCertificatesRunRequest

Request model for running the refresh certificates run.

Attributes

model\_config

ConfigDict instance for the model.

seed
(int)

The seed for the new certificates from plan response.

expiration\_seconds
(int)

The duration of the new certificates.

extra\_sans
(list[str])

List of extra sans for the new certificates.

#### class RefreshCertificatesRunMetadata

Metadata for RefreshCertificatesRunResponse.

Description

Attributes:
model\_config: ConfigDict instance for the model.
expiration\_seconds (int): The duration of the new certificates
(might not match the requested value).

#### class RefreshCertificatesRunResponse

Response model for the refresh certificates run.

Attributes

metadata
(RefreshCertificatesRunMetadata)

Metadata for the certificates run response.

#### class GetClusterConfigMetadata

Metadata containing the cluster config.

Attributes

status
(UserFacingClusterConfig)

The configuration of the cluster.

datastore
(UserFacingDatastoreConfig)

The configuration of the datastore.

pod\_cidr
(str)

The CIDR range for the pods in the cluster.

service\_cidr
(str)

The CIDR range for the services in the cluster.

#### class GetClusterConfigResponse

Response model for the get cluster config endpoint.

Attributes

metadata
(GetClusterConfigMetadata)

Metadata containing the cluster config.

#### class NodeStatus

Represents the status of a node in the cluster.

Attributes

name
(Optional[str])

The name of the node.

address
(Optional[str])

The address of the node.

cluster\_role
(Optional[str])

The role of the node in the cluster.

datastore\_role
(Optional[str])

The role of the node in the datastore cluster.

#### class GetNodeStatusMetadata

Metadata containing the node status.

Attributes

status
(NodeStatus)

The status of the local node.

taints
(Optional[List[str]])

List of taints applied to the node.

#### class GetNodeStatusResponse

Response model for the get node status endpoint.

Attributes

metadata
(GetNodeStatusMetadata)

Metadata containing the node status.

#### class UnixSocketHTTPConnection

Description

HTTP connection over a Unix socket. None

Methods

UnixSocketHTTPConnection.
\_\_init\_\_(

*self*

,
unix\_socket: str

,
timeout: int
)

Initialise the UnixSocketHTTPConnection.

Arguments

unix\_socket
(str)

Path to the Unix socket.

timeout
(int)

Connection timeout in seconds.

UnixSocketHTTPConnection.
connect(

*self*
)

Establish a connection to the server using a Unix socket.

#### class ConnectionFactory

Description

Abstract factory for creating connection objects. None

Methods

ConnectionFactory.
create\_connection(

*self*
)

Create a new connection instance.

#### class UnixSocketConnectionFactory

Description

Concrete factory for creating Unix socket connections. None

Methods

UnixSocketConnectionFactory.
\_\_init\_\_(

*self*

,
unix\_socket: str

,
timeout: int
)

Initialize a new instance of UnixSocketConnectionFactory.

Arguments

unix\_socket
(str)

The file path to the Unix socket.

timeout
(int)

The timeout for the connection in seconds.
Defaults to 30 seconds.

UnixSocketConnectionFactory.
create\_connection(

*self*
)

Create and manage a Unix socket HTTP connection.

Returns

UnixSocketHTTPConnection

The created Unix socket HTTP connection.

#### class HTTPConnectionFactory

Description

Concrete factory for creating HTTP connections. None

Methods

HTTPConnectionFactory.
\_\_init\_\_(

*self*

,
host: str

,
port

,
timeout: int
)

Initialize a new instance of HTTPConnectionFactory.

Arguments

host
(str)

Hostname for the HTTP connection.

port
(int)

Port for the HTTP connection.

timeout
(int)

The timeout for the connection in seconds.
Defaults to 30 seconds.

HTTPConnectionFactory.
create\_connection(

*self*
)

Create and manage an HTTP connection.

Returns

HTTPConnection

The created HTTP connection.

#### class K8sdAPIManager

Description

Manager for K8sd API interactions. None

Methods

K8sdAPIManager.
\_\_init\_\_(

*self*

,
factory: ConnectionFactory
)

Initialise the K8sdAPIManager.

Arguments

factory
(ConnectionFactory)

An instance of a connection factory that will be used
to create connections. This factory determines the type
of connection (e.g., Unix socket or HTTP).

K8sdAPIManager.
create\_join\_token(

*self*

,
name: str

,
worker: bool
)

Create a join token.

Arguments

name
(str)

Name of the node.

worker
(bool)

Whether the node should join as control-plane or worker.

Returns

SecretStr

The generated join token if successful.

K8sdAPIManager.
join\_cluster(

*self*

,
config: JoinClusterRequest
)

Join a node to the k8s cluster.

Arguments

config

JoinClusterRequest: config to join the cluster

K8sdAPIManager.
remove\_node(

*self*

,
name: str

,
force: bool
)

Remove a node from the cluster.

Arguments

name
(str)

Name of the node that should be removed.

force
(bool)

Forcibly remove the node

K8sdAPIManager.
update\_cluster\_config(

*self*

,
config: UpdateClusterConfigRequest
)

Enable or disable a k8s component.

Arguments

config
(UpdateClusterConfigRequest)

The cluster configuration.

K8sdAPIManager.
get\_cluster\_config(

*self*
)

Retrieve the cluster configuration.

Returns

GetClusterConfigResponse

The cluster configuration.

Description

Worker nodes are not allowed to call this endpoint:
https://github.com/canonical/k8s-snap/blob/0a5edd2/src/k8s/pkg/k8sd/api/endpoints.go#L121-L126

K8sdAPIManager.
get\_node\_status(

*self*
)

Retrieve the status of the local node.

Returns

GetNodeStatusResponse

The status of the local node.

K8sdAPIManager.
get\_cluster\_status(

*self*
)

Retrieve cluster status.

Returns

cluster\_status

status of the cluster.

K8sdAPIManager.
is\_cluster\_bootstrapped(

*self*
)

Check if K8sd has been bootstrapped.

Returns

bool

True if the cluster has been bootstrapped, False otherwise.

K8sdAPIManager.
is\_cluster\_ready(

*self*
)

Check if the Kubernetes cluster is ready.

Returns

bool

True if the cluster is ready, False otherwise.

Description

The cluster is ready if at least one k8s node is in READY state.

K8sdAPIManager.
check\_k8sd\_ready(

*self*
)

Check if k8sd is ready using various microcluster endpoints.

K8sdAPIManager.
bootstrap\_k8s\_snap(

*self*

,
request: CreateClusterRequest
)

Bootstrap the k8s cluster.

Arguments

request
(CreateClusterRequest)

The request model to bootstrap the cluster.

K8sdAPIManager.
request\_auth\_token(

*self*

,
username: str

,
groups
)

Request a Kubernetes authentication token.

Arguments

username
(str)

Username for which the token is requested.

groups
(List[str])

Groups associated with the user.

Returns

SecretStr

The authentication token.

K8sdAPIManager.
revoke\_auth\_token(

*self*

,
token: str
)

Revoke a Kubernetes authentication token.

Arguments

token
(str)

The authentication token.

K8sdAPIManager.
get\_kubeconfig(

*self*

,
server
)

Request a Kubernetes admin config.

Arguments

server
(str)

Optional server to replace in the kubeconfig endpoint

Returns

str

The authentication token.

K8sdAPIManager.
refresh\_certs(

*self*

,
extra\_sans

,
expiration\_seconds
)

Refresh the certificates for the cluster.

Arguments

extra\_sans
(list[str])

List of extra SANs for the certificates.

expiration\_seconds
(Optional[int])

The duration of the new certificates.
