k8s¶
Kubernetes module.
- exception spicerack.k8s.KubernetesApiError[source]¶
Bases:
spicerack.exceptions.SpicerackError
Custom error class for errors interacting with the kubernetes api.
- exception spicerack.k8s.KubernetesCheckError[source]¶
Bases:
spicerack.exceptions.SpicerackCheckError
Custom error class for errors checking kubernetes resources.
- exception spicerack.k8s.KubernetesError[source]¶
Bases:
spicerack.exceptions.SpicerackError
Custom error class for errors in running the kubernetes module.
- class spicerack.k8s.Kubernetes(group: str, cluster: str, *, dry_run: bool = True)[source]¶
Bases:
object
High-level interface for interacting with the kubernetes api from spicerack.
Initialize the instance.
- Parameters
group (string) -- the cluster group we want to operate on
cluster (string) -- the cluster we're operating on
dry_run (bool) -- if true, no write operations will happen.
- get_node(name: str) spicerack.k8s.KubernetesNode [source]¶
Get an object for a kubernetes node.
- Parameters
name (string) -- the name of the node
- Returns
spicerack.kubernetes.KubernetesNode
- Raises
spicerack.kubernetes.KubernetesApiError if the node is not found on the cluster. --
- get_pod(namespace: str, name: str) spicerack.k8s.KubernetesPod [source]¶
Get an object for a kubernetes pod.
- Parameters
name (string) -- the name of the pod
namespace (string) -- the namespace the pod is in
- Returns
spicerack.kubernetes.KubernetesPod
- Raises
spicerack.kubernetes.KubernetesApiError if the pod is not found on the cluster --
- class spicerack.k8s.KubernetesApiFactory(cluster: str)[source]¶
Bases:
object
Provides kubernetes object classes easy access to the API.
Initialize the instace.
- Parameters
cluster (string) -- the cluster we're operating on
- configuration(user: str) kubernetes.client.configuration.Configuration [source]¶
Provide the configuration for a specific user.
- Parameters
user (string) -- the user to fetch the configuration for.
- Returns
the configuration for the specified user.
- Return type
kubernetes.client.Configuration
- Raises
KubernetesError if the user or the configuration are invalid --
- class spicerack.k8s.KubernetesNode(fqdn: str, api: spicerack.k8s.KubernetesApiFactory, dry_run: bool = True, init_obj: Optional[kubernetes.client.models.v1_node.V1Node] = None)[source]¶
Bases:
object
Encapsulates actions on a kubernetes node.
Initialize the instance.
- Parameters
fqdn (string) -- the fqdn of the node.
api (KubernetesApiFactory) -- the api factory we're going to use.
dry_run (bool) -- if true, no write operations will happen.
init_obj (kubernetes.client.models.v1_node.V1Node) -- if not None, this api object will be used, instead of fetching it from the api.
- cordon() None [source]¶
Makes the node unschedulable.
- Raises
KubernetesApiError if the call to the api failed --
KubernetesCheckError if the node wasn't set to unschedulable --
- drain() None [source]¶
Drains the node, analogous to kubectl drain.
- Raises
KubernetesCheckError if we can't evict all pods --
- get_pods() List[spicerack.k8s.KubernetesPod] [source]¶
Get the pods running on this node.
- is_schedulable() bool [source]¶
Checks if a node is schedulable or not.
- Returns
bool true if payloads can be scheduled on the node, false otherwise.
- class spicerack.k8s.KubernetesPod(namespace: str, name: str, api: spicerack.k8s.KubernetesApiFactory, dry_run: bool = True, init_obj: Optional[kubernetes.client.models.v1_pod.V1Pod] = None)[source]¶
Bases:
object
Encapsulates actions on a kubernetes pod.
Initialize the pod isntance.
- Parameters
namespace (string) -- the namespace where the pod is located.
name (string) -- the name of the pod
api (KubernetesApiFactory) -- the api factory we're going to use.
dry_run (bool) -- if true, no write operations will happen.
init_obj (kubernetes.client.models.v1_pod.V1Pod) -- if not None, this api object will be used, instead of fetching it from the api.
- evict() None [source]¶
Submit an eviction request to the kubernetes api for this pod.
- Raises
KubernetesApiError in case of a bad response from the server. --
KubernetesError if the pod is not evictable. --
- is_daemonset() bool [source]¶
Checks if the pod is part of a daemonset.
- Returns
bool true if it is a daemonset, false otherwise.
- is_evictable() bool [source]¶
Check if the pod can be evicted.
- Returns
bool true if this pod can be evicted, false otherwise.
- is_mirror() bool [source]¶
Check if the pod is a mirror pod.
- Returns
bool true if this is a mirror pod, false otherwise.
- is_terminated() bool [source]¶
Checks if the pod is terminated.
- Returns
bool true if the pod is not running, false otherwise.
- property controller: Optional[kubernetes.client.models.v1_owner_reference.V1OwnerReference]¶
Get the reference to the controlling object, if any.
- Returns
the reference.
- Return type
kubernetes.client.models.v1_owner_reference.V1OwnerReference
- property spec: kubernetes.client.models.v1_pod_spec.V1PodSpec¶
Acess the pod's spec.
- Returns
kubernetes.client.models.v1_pod_spec.V1PodSpec the pod spec