## DBaaS 

### Prerequisites

EKS or GCP cluster

### Init Database
1. Replace central/billing configuration of tools.sql, then access into the tidb and run tools.sql on the tidb. 
2. Add A new user into databases: `insert into users(created_at, updated_at, tenant_id, first_name, last_name, email, status, invited_at, is_root, job, phone_number) values(now(), now(), 1, "Louis", "Liu", "liuzhi@pingcap.com", "active", now(), true, "", "");`

### Installing the DBaaS Chart

To install the chart, pls run:

```bash
helm install --namespace=example \
  --set cloud.aws.billingSqsID=<billingSqsID> \
  --set cloud.aws.encryptionCmkArn=<encryptionCmkArn> \
  --set cloud.aws.dbaasBillingRoleArn=<dbaasBillingRoleArn> \
  --set cloud.aws.certificateArn=<certificateArn> \
  --set cloud.aws.dbaasWebAclArn=<dbaasWebAclArn> \
  --set central.centralRoleARN=<centralRoleARN> \
  --set central.centralAwsSecretId=<centralAwsSecretId> \
  --set mysql.host=<host> \
  --set mysql.centralDB=<central db> \ 
  --set mysql.billingDB=<billing db> \ 
  --set mysql.centralDbUser=<central db user> \ 
  --set mysql.centralDbUser=<billing db user> \ 
  --set mysql.centralDbPassword=<central-password> \
  --set mysql.billingDbPassword=<billing-password> 
  central/
```

## All configuration options

The following table lists the configurable parameters of the DBaaS chart and their default values. Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
```bash
helm install --namespace=example \
  --set cloud.aws.billingSqsID=<billingSqsID> \
  --set cloud.aws.encryptionCmkArn=<encryptionCmkArn> \
  --set cloud.aws.dbaasBillingRoleArn=<dbaasBillingRoleArn> \
  --set cloud.aws.certificateArn=<certificateArn> \
  --set cloud.aws.dbaasWebAclArn=<dbaasWebAclArn> \
  --set central.centralRoleARN=<centralRoleARN> \
  --set central.centralAwsSecretId=<centralAwsSecretId> \
  --set mysql.host=<host> \
  --set mysql.centralDB=<central db> \ 
  --set mysql.billingDB=<billing db> \ 
  --set mysql.centralDbUser=<central db user> \ 
  --set mysql.centralDbUser=<billing db user> \ 
  --set mysql.centralDbPassword=<central-password> \
  --set mysql.billingDbPassword=<billing-password> 
  central/
```

| Parameter                          | Description                     | Default                             |
| -----------------------------------| --------------------------------|------------------------------------ |
| `cloud.aws.billingSqsID`           | aws billing sqs id              |                                     |
| `cloud.aws.encryptionCmkArn`       | Central Aws Secret Id           |                                     |
| `cloud.aws.dbaasBillingRoleArn`    | DBaaS Billing Role Arn          |                                     |
| `cloud.aws.certificateArn`         | Certificate Arn                 |                                     |
| `cloud.aws.dbaasWebAclArn`         | DBaaS Web Acl Arn               |                                     |
| `central.centralRoleARN`           | Central Role ARN                |                                     |
| `central.centralAwsSecretId`       | Central Aws Secret Id           |                                     |
| `image.centralImage`               | central server image            | 385595570414.dkr.ecr.us-west-2.amazonaws.com/dbaas/xufei4/dbaas-central-server:4ef21e21                                  |
| `image.billingImage`               | billing server image            | 385595570414.dkr.ecr.us-west-2.amazonaws.com/dbaas/xufei4/dbaas-billing:4ef21e21                                  |
| `mysql.host`                       | tidb server address             | db-tidb.nightly                     |
| `mysql.centralDB`                  | central database name           | centraltest                         |
| `mysql.billingDB`                  | billing database name           | billingtest                         |
| `mysql.centralDbUser`              | central database user           | centraltest                         |
| `mysql.billingDbUser`              | billing database user           | billingtest                         |
| `mysql.centralDbPassword`          | central database password       | centraltest                         |
| `mysql.billingDbPassword`          | billing database password       | billingtest                         |


### Create DnsEntry
1. fetching alb address using `kubectl -n <ns> get ingress central-ingress`
2. rewrite the following dnsentry yaml and apply it
```yaml
apiVersion: dns.gardener.cloud/v1alpha1
kind: DNSEntry
metadata:
  name: central
  namespace: <namespace>
spec:
  dnsName: us-west-2.<namespace>.shared.aws.tidbcloud.com
  targets:
  - <alb-address>
  ttl: 120
```