Kubernetes

  • Canonical Kubernetes
Channel Revision Published Runs on
latest/edge 190 Yesterday
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
latest/edge 189 Yesterday
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
1.32/candidate 179 19 Dec 2024
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
1.32/candidate 180 19 Dec 2024
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
1.32/beta 180 19 Dec 2024
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
1.32/beta 179 19 Dec 2024
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
1.31/candidate 142 11 Dec 2024
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
1.31/candidate 141 27 Nov 2024
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
1.30/beta 65 23 May 2024
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04
juju deploy k8s --channel edge
Show information

Platform:

Ubuntu
24.04 22.04 20.04

charms.k8s.v0.k8sd_api_manager

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.


class K8sdAPIManagerError

Description

Base exception for K8sd API Manager errors. None

class K8sdConnectionError

Description

Raised when there is a connection error. None

class InvalidResponseError

Description

Raised when the response is invalid or unexpected. None

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 , values )

Validate the error_code field.

Arguments

v (int)

The value of the error_code field to validate.

values (dict)

The values dictionary.

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 (str)
The actual token string.

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 ClusterComponent

Represents a component in the k8sd cluster.

Attributes

name (str)
Name of the component.
status (str)
Current status of the component.

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.
components (List[ClusterComponent])
List of components in the cluster.

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 (Optional[ClusterMetadata])
Metadata containing the cluster status. Can be None if the status is not available.

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

str

The generated join token if successful.

K8sdAPIManager. join_cluster( self , name: str , address: str , token: str )

Join a node to the k8s cluster.

Arguments

name (str)

Name of the node.

address (str)

address to which k8sd should be bound

token (str)

The join token for this node.

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. enable_component( self , name: str , enable: bool )

Enable or disable a k8s component.

Arguments

name (str)

Name of the component.

enable (bool)

True to enable, False to disable the component.

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 )

Description

Check if k8sd is ready. None

K8sdAPIManager. bootstrap_k8s_snap( self , name: str , address: str )

Bootstrap the k8s cluster.

Arguments

name (str)

name of the node

address (str)

address to which k8sd should be bound

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

str

The authentication token.