> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/cennso-db/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-operator.md).

# Cennso Database Operator

The Cennso Database Operator is represented by the `DBOperator` Custom Resource (CR) and defines:

- Location where a database operator should be deployed, such as the name of the Core Cluster and a Kubernetes namespace
- Optionally, the Kubernetes [Storage Classes](https://kubernetes.io/docs/concepts/storage/storage-classes/) for the [Persistent Volumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/) requested by the database instances

The sections below provide information about configuration parameters that you can specify in the `DBOperator` CR. For more information on how to configure and deploy the database operator, see the [Deploy Cennso Database](https://docs.cennso.com/cennso/cennso-db/latest/deployment-guides/cennso-database.md) and [Cennso Database Operator Custom Resource Definition](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-db/xdboperator_definition.md) documents.

## Kubernetes cluster secret reference

To deploy the Cennso Database Operator to a Core Cluster, you must specify the reference to the [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/) so this cluster can be accessible. You can do this using the following configuration parameters:

```yaml
spec:
  connectionSecretRef:
    name: {CORE-CLUSTER-NAME}
    namespace: {CORE-CLUSTER-SECRET-NAMESPACE}
```

Set **spec.connectionSecretRef.name** to the name of the Core Cluster where the Cennso Database Operator should be installed. The **spec.connectionSecretRef.namespace** configuration parameter defines the Kubernetes Namespace on the Management Cluster where the Kubernetes secret to access this Core Cluster is stored.

## Image and chart configuration

You can use the following configuration parameters to specify the versions of the container image along with the secret to pull the image and Helm chart of the Cennso Database Operator:

```yaml
spec:
  image:
    repository: {DATABASE-OPERATOR-IMAGE-REPOSITORY}
    tag: {DATABASE-OPERATOR-IMAGE-TAG}
  imagePullSecretRef:
    name: {SECRET-NAME}
  chart:
    registry: {CHART-REGISTRY-NAME}
    name: {DATABASE-OPERATOR-CHART-NAME}
    version: {DATABASE-OPERATOR-CHART-VERSION}
```

## Scheduling and placement configuration

`DBOperator` custom resource allows you to configure the Cennso Database Operator scheduling and placement settings according to your needs.

To control where the Cennso Database Operator Pods run and how they’re distributed across nodes, use the following configuration options:

- [**spec.nodeSelector**](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/)
- [**spec.tolerations**](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/)

In addition, you should specify the **spec.operatorNamespace** configuration option which controls the Kubernetes namespace name where the Cennso Database Operator should be deployed in the Core Cluster.

## Namespaces for the database clusters

By default, the database operator is configured to operate a MySQL cluster which is located in the same Kubernetes namespace. You can change this behaviour, or specify multiple Kubernetes namespaces where the database clusters are deployed and managed by the database operator. To do this, use the following configuration option:

```yaml
spec:
  watchNamespaces:
    - cluster-1-namespace
    - cluster-2-namespace
    - cluster-3-namespace
```

## Storage configuration

The optional storage configuration section allows you to define the storage classes that the Cennso Database Operator creates on the Core Cluster for the MySQL instance volumes:

```yaml
spec:
  storage:
    classes:
      - nodePath: /opt/local-path-provisioner/mysql-cluster-datadir
        name: mysql-data-storage
```

Each entry becomes a `StorageClass` backed by the [local-path-provisioner](https://github.com/rancher/local-path-provisioner), which creates the volumes under **spec.storage.classes[].nodePath** on the node where a MySQL instance is scheduled. A `DBInstance` refers to the class by name in **spec.storage.className**, as described in the [Storage configuration](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-instance.md#storage-configuration) section of the Cennso Database Instance document.

The local-path-provisioner only creates volumes under the paths listed in the `nodePathMap` of its `local-path-config` ConfigMap on the Core Cluster. The **spec.storage.classes[].nodePath** must be listed there for every node where a MySQL instance can run. Otherwise, the Persistent Volume Claims stay `Pending` and the provisioner reports `config doesn't contain path`. The storage classes set the path pattern of the provisioner to the namespace and the name of the Persistent Volume Claim. Each volume is therefore created in the `{NODE-PATH}/{NAMESPACE}/{PVC-NAME}` directory on the node. The provisioner creates this directory, so you do not need to create it in advance.

The storage classes use the `Retain` reclaim policy. When you delete a Persistent Volume Claim, its Persistent Volume and the data on the node are kept until you remove them manually. A new Persistent Volume Claim with the same name in the same namespace uses the same directory, so remove the directory first to start with empty data. The `StorageClass` resources are also kept when the `DBOperator` CR is deleted, because the volumes of the MySQL instances still refer to them.

You can omit **spec.storage** when the `DBInstance` uses a storage class that already exists on the Core Cluster.

## Resources configuration

`DBOperator` custom resource allows you to configure the [resources](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) for the Cennso Database Operator using the following configuration options:

```yaml
spec:
  resources:
    requests:
      cpu: 1
      memory: 512Mi
    limits:
      cpu: 1
      memory: 512Mi
```

## Graceful upgrade

> **Deprecated:** The **spec.replicationSyncWaitTimeOnUpgrade** configuration option will be removed in the next release of the Cennso Database extension. Use the **spec.binaryDonor** field of the `DBInstance` Custom Resource instead, so that a restarted database instance can catch up with the primary from the exposed binary logs. For more information, see [Enable `binary-donor`](https://docs.cennso.com/cennso/cennso-db/latest/deployment-guides/binary-donor.md).

The instances within a database cluster may need some time to synchronise the state during the upgrade procedure. You can control the length of this time period using the following configuration option:

```yaml
spec:
  replicationSyncWaitTimeOnUpgrade: 5
```

When the value of this configuration option is not zero, the database operator does not restart the database instances immediately one after another during the upgrade procedure. Instead, it waits for the given period of time before the restart of each next database instance after the first one is restarted and gets up and running.
