crate.operator.operations module¶
- class crate.operator.operations.AfterClusterUpdateSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False)¶
Bases:
StateBasedSubHandler
- class crate.operator.operations.BeforeClusterUpdateSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False)¶
Bases:
StateBasedSubHandler
- class crate.operator.operations.RestartSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False)¶
Bases:
StateBasedSubHandler
- class crate.operator.operations.StartClusterSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False)¶
Bases:
StateBasedSubHandler
- class crate.operator.operations.SuspendClusterSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False)¶
Bases:
StateBasedSubHandler
- crate.operator.operations.add_sql_exporter_collectors_to_configmap(config_map, collectors)¶
- Parameters
config_map (
V1ConfigMap
) –collectors (
list
) –
- Return type
V1ConfigMap
- async crate.operator.operations.check_all_data_nodes_gone(core, namespace, name, old)¶
- Parameters
- Raises
A
kopf.TemporaryError
when nodes are still available
- async crate.operator.operations.check_all_data_nodes_present(connection_factory, old_replicas, new_replicas, node_prefix, logger)¶
- Parameters
connection_factory – A callable that allows the operator to connect to the database. We regularly need to reconnect to ensure the connection wasn’t closed because it was opened to a CrateDB node that was shut down since the connection was opened.
old_replicas (
int
) – The number of replicas in a StatefulSet before scaling.new_replicas (
int
) – The number of replicas in a StatefulSet after scaling.node_prefix (
str
) – The prefix of the node names in CrateDB.logger (
Logger
) –
- Raises
A
kopf.TemporaryError
when nodes are missing
- async crate.operator.operations.check_backup_metrics_pod_gone(core, namespace, name)¶
- Parameters
- Raises
A
kopf.TemporaryError
when node is still present.
- async crate.operator.operations.check_cluster_healthy(name, namespace, apps, conn_factory, logger)¶
This looks for all the StatefulSets for this cluster and makes sure that the number of nodes in all the STS matches what CrateDB has in the sys.nodes table.
If we have specific master/hot/cold node types configured these would be separate StatefulSets.
- async crate.operator.operations.delete_lb_service(core, namespace, name)¶
- async crate.operator.operations.ensure_cronjob_reenabled(namespace, name, logger, status)¶
- async crate.operator.operations.get_cratedb_resource(namespace, name)¶
Return the CrateDB custom resource.
- async crate.operator.operations.get_lb_service(core, namespace, name)¶
Returns true if the load balancer service related to a StatefulSet exists. Returns false otherwise.
- crate.operator.operations.get_master_nodes_names(nodes)¶
Return the list of nodes service as master nodes in a CrateDB cluster.
The function takes the
spec.nodes
from a CrateDB custom resource and checks if it defines explicit master nodes or not. Based on that, it will return the list of node names.
- async crate.operator.operations.get_namespace_resource(namespace_name)¶
Return the namespace for the given name.
- Parameters
namespace_name (
str
) – The Kubernetes namespace name to look up.- Return type
V1Namespace
- async crate.operator.operations.get_pods_in_cluster(core, namespace, name)¶
Return a two-tuple with two tuples, the first containing all pod IDs, the second the corresponding pod names within the cluster.
- async crate.operator.operations.get_pods_in_deployment(core, namespace, name)¶
Return a list of all pod IDs and names belonging to a given Deployment.
- async crate.operator.operations.get_pods_in_statefulset(core, namespace, name, node_name)¶
Return a list of all pod IDs and names belonging to a given StatefulSet.
- Parameters
core (
CoreV1Api
) – An instance of the Kubernetes Core V1 API.namespace (
str
) – The Kubernetes namespace where to look up CrateDB cluster.name (
str
) – The CrateDB custom resource name defining the CrateDB cluster.node_name (
str
) – Either"master"
for dedicated master nodes, or thename
for a data node spec. Used to determine which StatefulSet to of the cluster should be “restarted”.
- Return type
- async crate.operator.operations.get_pvcs_in_namespace(core, namespace, name, node_name)¶
- crate.operator.operations.get_total_nodes_count(nodes, type='all')¶
Calculate the total number nodes a CrateDB cluster should have on startup.
When starting CrateDB it’s important to know the expected number of nodes in a cluster. The function takes the
spec.nodes
from the CrateDB custom resource and sums up all desired replicas for all nodes defined therein.
- async crate.operator.operations.is_lb_service_present(core, namespace, name)¶
- async crate.operator.operations.is_lb_service_ready(core, namespace, name)¶
- async crate.operator.operations.is_namespace_terminating(namespace_name)¶
Determines if the namespace identified by the given name is terminating or not.
- async crate.operator.operations.restart_cluster(core, namespace, name, old, logger, patch, status, action)¶
Perform a rolling restart of the CrateDB cluster
name
innamespace
.One node at a time, this function will terminate first the master nodes and then the data nodes in the cluster. After triggering a pod’s termination, the operator will wait for that pod to be terminated and gone. It will then wait for the cluster to have the desired number of nodes again and for the cluster to be in a
GREEN
state, before terminating the next pod.- Parameters
core (
CoreV1Api
) – An instance of the Kubernetes Core V1 API.namespace (
str
) – The Kubernetes namespace where to look up CrateDB cluster.name (
str
) – The CrateDB custom resource name defining the CrateDB cluster.old (
Body
) – The old resource body.logger (
Logger
) –patch (
Patch
) –status (
Status
) –action (
WebhookAction
) –
- Return type
- async crate.operator.operations.scale_backup_metrics_deployment(namespace, name, replicas)¶
Update the number of replicas of a backup-metrics deployment in the given namespace.
- async crate.operator.operations.set_cronjob_delay(patch)¶
- async crate.operator.operations.suspend_or_start_cluster(apps, core, namespace, name, old, data_diff_items, scale_backup_metrics, logger)¶
Suspend or scale a cluster
name
back up, according to the givendata_diff_items
.- Parameters
apps (
AppsV1Api
) – An instance of the Kubernetes Apps V1 API.core (
CoreV1Api
) – An instance of the Kubernetes Core V1 API.namespace (
str
) – The Kubernetes namespace for the CrateDB cluster.name (
str
) – The CrateDB custom resource name defining the CrateDB cluster.old (
Body
) – The old resource body.data_diff_items (
Diff
) – A list of changes made to the individual data node specifications.scale_backup_metrics (
bool
) – Indicates whether backup metrics Deployment should be suspended/started as well. This is usually not the case for volume expansion operations.logger (
Logger
) –
- async crate.operator.operations.update_deployment_replicas(apps, namespace, name, replicas)¶
Call the Kubernetes API and update the number of replicas.
- async crate.operator.operations.update_statefulset_replicas(apps, namespace, sts_name, statefulset, replicas)¶
Call the Kubernetes API and update the number of replicas.
- Parameters
apps (
AppsV1Api
) – An instance of the Kubernetes Apps V1 API.namespace (
Optional
[str
]) – The Kubernetes namespace for the CrateDB cluster.sts_name (
Optional
[str
]) – The name for the Kubernetes StatefulSet to update.replicas (
Optional
[int
]) – The new number of replicas for the StatefulSet.statefulset (
Optional
[V1StatefulSet
]) –