crate.operator.operations module

class crate.operator.operations.AfterClusterUpdateSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)

Bases: StateBasedSubHandler

Parameters:
async handle(namespace, name, body, old, status, logger, **kwargs)
Parameters:
class crate.operator.operations.BeforeClusterUpdateSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)

Bases: StateBasedSubHandler

Parameters:
async handle(namespace, name, body, old, status, logger, **kwargs)
Parameters:
class crate.operator.operations.RestartSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)

Bases: StateBasedSubHandler

Parameters:
async handle(namespace, name, old, logger, patch, status, action, **kwargs)
Parameters:
class crate.operator.operations.RestoreUserJWTAuthSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)

Bases: StateBasedSubHandler

Parameters:
async handle(namespace, name, logger, **kwargs)

Restore the admin user’s JWT properties. Use crash here because the system user is not allowed to ALTER any other users.

Parameters:
  • namespace (str) – The Kubernetes namespace of the CrateDB cluster.

  • name (str) – The CrateDB custom resource name defining the CrateDB cluster.

  • logger (Logger) – the logger on which we’re logging

  • kwargs (Any)

class crate.operator.operations.StartClusterSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)

Bases: StateBasedSubHandler

Parameters:
async handle(namespace, name, spec, old, diff, logger, **kwargs)
Parameters:
class crate.operator.operations.SuspendClusterSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)

Bases: StateBasedSubHandler

Parameters:
async handle(namespace, name, spec, old, diff, logger, **kwargs)
Parameters:
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.are_traefik_resources_present(namespace, name)

Check if both IngressRouteTCP resources exist for this cluster.

Parameters:
  • namespace (str) – Namespace to check.

  • name (str) – Name of the CrateDB cluster.

Return type:

bool

async crate.operator.operations.check_all_data_nodes_gone(core, namespace, name, old)
Parameters:
  • 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.

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:
  • 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.

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.

Parameters:
  • name (str)

  • namespace (str)

  • apps (AppsV1Api)

async crate.operator.operations.delete_lb_service(core, namespace, name)
Parameters:
  • core (CoreV1Api)

  • namespace (str)

  • name (str)

async crate.operator.operations.ensure_cronjob_reenabled(namespace, name, logger, status)
Parameters:
crate.operator.operations.get_crash_pod_name(spec, name)

Returns the pod name where crash commands should be run.

Parameters:
  • spec (dict) – The CrateDB custom resource definition.

  • name (str) – The CrateDB custom resource name defining the CrateDB cluster.

Return type:

str

crate.operator.operations.get_crash_scheme(spec)

Return the host scheme for running crash commands.

Parameters:

spec (dict) – The CrateDB custom resource definition.

Return type:

str

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.

Parameters:
  • core (CoreV1Api)

  • namespace (str)

  • name (str)

Return type:

V1Service

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.

Parameters:

nodes (Dict[str, Any]) – The spec.nodes from a CrateDB custom resource.

Return type:

List[str]

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.

Parameters:
  • core (CoreV1Api) – An instance of the Kubernetes Core V1 API.

  • namespace (str) – The Kubernetes namespace where to look up the CrateDB cluster.

  • name (str) – The CrateDB custom resource name defining the CrateDB cluster.

Return type:

Tuple[Tuple[str], Tuple[str]]

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.

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.

Return type:

List[Dict[str, str]]

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 the name for a data node spec. Used to determine which StatefulSet to of the cluster should be “restarted”.

Return type:

List[Dict[str, str]]

async crate.operator.operations.get_pvcs_in_namespace(core, namespace, name, node_name)
Parameters:
  • core (CoreV1Api)

  • namespace (str)

  • name (str)

  • node_name (str)

Return type:

List[Dict[str, str]]

crate.operator.operations.get_sql_exporter_collectors(sql_exporter_config)
Return type:

list

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.

Parameters:
  • nodes (Dict[str, Any]) – The spec.nodes from a CrateDB custom resource.

  • type (str) – Optionally get only the number of data or master nodes.

Return type:

int

async crate.operator.operations.is_lb_service_present(core, namespace, name)
Parameters:
  • core (CoreV1Api)

  • namespace (str)

  • name (str)

Return type:

bool

async crate.operator.operations.is_lb_service_ready(core, namespace, name)
Parameters:
  • core (CoreV1Api)

  • namespace (str)

  • name (str)

Return type:

bool

async crate.operator.operations.is_namespace_terminating(namespace_name)

Determines if the namespace identified by the given name is terminating or not.

Parameters:

namespace_name (str) – The Kubernetes namespace name to look up.

Return type:

bool

async crate.operator.operations.is_service_present(core, namespace, name)

Check if the main data service (crate-<name>) exists.

Parameters:
  • core (CoreV1Api) – Kubernetes CoreV1Api client.

  • namespace (str) – Namespace to check.

  • name (str) – Name of the CrateDB cluster.

Return type:

bool

async crate.operator.operations.restart_cluster(core, namespace, name, old, logger, patch, status, action)

Perform a rolling restart of the CrateDB cluster name in namespace.

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:

None

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.

Parameters:
  • namespace (str) – The Kubernetes namespace for the CrateDB cluster.

  • name (str) – The name for the backup-metrics deployment to update.

  • replicas (int) – The new number of replicas.

async crate.operator.operations.set_cronjob_delay(patch)
async crate.operator.operations.set_user_jwt(cursor, namespace, name, username, logger)

Set JWT auth properties for a given username

Parameters:
  • cursor (Cursor) – A database cursor object to the CrateDB cluster where the user should be added.

  • namespace (str) – The Kubernetes namespace of the CrateDB cluster.

  • name (str) – The CrateDB custom resource name defining the CrateDB cluster.

  • username (str) – The name of the user the JWT properties should be set for.

  • logger (Logger) – Logger for operation tracking.

Return type:

None

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 given data_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.suspend_or_start_grand_central(apps, namespace, name, suspend)
Parameters:
  • apps (AppsV1Api)

  • namespace (str)

  • name (str)

  • suspend (bool)

async crate.operator.operations.update_deployment_replicas(apps, namespace, name, 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.

  • name (Optional[str]) – The name for the Kubernetes Deployment to update.

  • replicas (Optional[int]) – The new number of replicas for the Deployment.

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])