Skip to content

Commit

Permalink
dm-operator/: support start a new dm cluster with dm-masters and dm-w…
Browse files Browse the repository at this point in the history
…orkers (#3146)

* support start dm-master and dm-worker in cluster
* add more column info
  • Loading branch information
lichunzhu authored Aug 26, 2020
1 parent e3fd655 commit d6edf59
Show file tree
Hide file tree
Showing 45 changed files with 6,678 additions and 75 deletions.
3 changes: 3 additions & 0 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pingcap/tidb-operator/pkg/controller/autoscaler"
"github.com/pingcap/tidb-operator/pkg/controller/backup"
"github.com/pingcap/tidb-operator/pkg/controller/backupschedule"
"github.com/pingcap/tidb-operator/pkg/controller/dmcluster"
"github.com/pingcap/tidb-operator/pkg/controller/periodicity"
"github.com/pingcap/tidb-operator/pkg/controller/restore"
"github.com/pingcap/tidb-operator/pkg/controller/tidbcluster"
Expand Down Expand Up @@ -184,6 +185,7 @@ func main() {
}

tcController := tidbcluster.NewController(kubeCli, cli, genericCli, informerFactory, kubeInformerFactory, autoFailover, pdFailoverPeriod, tikvFailoverPeriod, tidbFailoverPeriod, tiflashFailoverPeriod)
dcController := dmcluster.NewController(kubeCli, cli, genericCli, informerFactory, kubeInformerFactory, autoFailover)
backupController := backup.NewController(kubeCli, cli, informerFactory, kubeInformerFactory)
restoreController := restore.NewController(kubeCli, cli, informerFactory, kubeInformerFactory)
bsController := backupschedule.NewController(kubeCli, cli, informerFactory, kubeInformerFactory)
Expand Down Expand Up @@ -218,6 +220,7 @@ func main() {
}
klog.Infof("cache of informer factories sync successfully")

go wait.Forever(func() { dcController.Run(workers, ctx.Done()) }, waitDuration)
go wait.Forever(func() { backupController.Run(workers, ctx.Done()) }, waitDuration)
go wait.Forever(func() { restoreController.Run(workers, ctx.Done()) }, waitDuration)
go wait.Forever(func() { bsController.Run(workers, ctx.Done()) }, waitDuration)
Expand Down
118 changes: 111 additions & 7 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,19 @@ Optional: Defaults to nil</p>
</tr>
<tr>
<td>
<code>hostNetwork</code></br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Whether Hostnetwork is enabled for DM cluster Pods
Optional: Defaults to false</p>
</td>
</tr>
<tr>
<td>
<code>affinity</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#affinity-v1-core">
Expand All @@ -696,6 +709,19 @@ Kubernetes core/v1.Affinity
</tr>
<tr>
<td>
<code>priorityClassName</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>PriorityClassName of DM cluster Pods
Optional: Defaults to omitted</p>
</td>
</tr>
<tr>
<td>
<code>nodeSelector</code></br>
<em>
map[string]string
Expand Down Expand Up @@ -4119,8 +4145,8 @@ LeastRemainAvailableStoragePercent should between 5 and 90. If not set, the defa
<td>
<code>type</code></br>
<em>
<a href="#tidbclusterconditiontype">
TidbClusterConditionType
<a href="#dmclusterconditiontype">
DMClusterConditionType
</a>
</em>
</td>
Expand Down Expand Up @@ -4196,6 +4222,10 @@ string
</table>
<h3 id="dmclusterconditiontype">DMClusterConditionType</h3>
<p>
(<em>Appears on:</em>
<a href="#dmclustercondition">DMClusterCondition</a>)
</p>
<p>
<p>DMClusterConditionType represents a dm cluster condition value.</p>
</p>
<h3 id="dmclusterspec">DMClusterSpec</h3>
Expand Down Expand Up @@ -4362,6 +4392,19 @@ Optional: Defaults to nil</p>
</tr>
<tr>
<td>
<code>hostNetwork</code></br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Whether Hostnetwork is enabled for DM cluster Pods
Optional: Defaults to false</p>
</td>
</tr>
<tr>
<td>
<code>affinity</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#affinity-v1-core">
Expand All @@ -4376,6 +4419,19 @@ Kubernetes core/v1.Affinity
</tr>
<tr>
<td>
<code>priorityClassName</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>PriorityClassName of DM cluster Pods
Optional: Defaults to omitted</p>
</td>
</tr>
<tr>
<td>
<code>nodeSelector</code></br>
<em>
map[string]string
Expand Down Expand Up @@ -6386,6 +6442,19 @@ Defaults to Kubernetes default storage class.</p>
</tr>
<tr>
<td>
<code>storageSize</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>StorageSize is the request storage size for dm-master.
Defaults to &ldquo;10Gi&rdquo;.</p>
</td>
</tr>
<tr>
<td>
<code>dataSubDir</code></br>
<em>
string
Expand Down Expand Up @@ -17308,7 +17377,6 @@ string
<h3 id="tidbclusterconditiontype">TidbClusterConditionType</h3>
<p>
(<em>Appears on:</em>
<a href="#dmclustercondition">DMClusterCondition</a>,
<a href="#tidbclustercondition">TidbClusterCondition</a>)
</p>
<p>
Expand Down Expand Up @@ -18723,7 +18791,7 @@ DMSecurityConfig
<tbody>
<tr>
<td>
<code>podName</code></br>
<code>name</code></br>
<em>
string
</em>
Expand All @@ -18733,7 +18801,7 @@ string
</tr>
<tr>
<td>
<code>id</code></br>
<code>addr</code></br>
<em>
string
</em>
Expand All @@ -18743,7 +18811,7 @@ string
</tr>
<tr>
<td>
<code>state</code></br>
<code>stage</code></br>
<em>
string
</em>
Expand Down Expand Up @@ -18837,6 +18905,19 @@ string
</tr>
<tr>
<td>
<code>maxFailoverCount</code></br>
<em>
int32
</em>
</td>
<td>
<em>(Optional)</em>
<p>MaxFailoverCount limit the max replicas could be added in failover, 0 means no failover.
Optional: Defaults to 3</p>
</td>
</tr>
<tr>
<td>
<code>storageClassName</code></br>
<em>
string
Expand All @@ -18850,6 +18931,19 @@ Defaults to Kubernetes default storage class.</p>
</tr>
<tr>
<td>
<code>storageSize</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>StorageSize is the request storage size for dm-worker.
Defaults to &ldquo;10Gi&rdquo;.</p>
</td>
</tr>
<tr>
<td>
<code>dataSubDir</code></br>
<em>
string
Expand Down Expand Up @@ -18935,7 +19029,7 @@ Kubernetes apps/v1.StatefulSetStatus
</tr>
<tr>
<td>
<code>workers</code></br>
<code>members</code></br>
<em>
<a href="#workermember">
map[string]github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.WorkerMember
Expand All @@ -18945,6 +19039,16 @@ map[string]github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.WorkerMemb
<td>
</td>
</tr>
<tr>
<td>
<code>image</code></br>
<em>
string
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<hr/>
Expand Down
65 changes: 65 additions & 0 deletions examples/dm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# A Basic DM cluster

> **Note:**
>
> This setup is for test or demo purpose only and **IS NOT** applicable for critical environment. Refer to the [Documents](https://pingcap.com/docs/stable/tidb-in-kubernetes/deploy/prerequisites/) for production setup.
The following steps will create a DM cluster.

**Prerequisites**:
- Has TiDB operator `v1.2.0` or higher version installed. [Doc](https://pingcap.com/docs/stable/tidb-in-kubernetes/deploy/tidb-operator/)
- Has default `StorageClass` configured, and there are enough PVs (by default, 2 PVs are required) of that storageClass:

This could by verified by the following command:

```bash
> kubectl get storageclass
```

The output is similar to this:

```bash
NAME PROVISIONER AGE
standard (default) kubernetes.io/gce-pd 1d
gold kubernetes.io/gce-pd 1d
```

Alternatively, you could specify the storageClass explicitly by modifying `dm-cluster.yaml`.

## Install

The following commands is assumed to be executed in this directory.

Install the cluster:

```bash
> kubectl -n <namespace> apply -f ./
```

Wait for cluster Pods ready:

```bash
watch kubectl -n <namespace> get pod
```

## Explore

Explore the DM master interface:

```bash
> kubectl exec -ti -n <namespace> <cluster_name>-dm-master-0 -- /bin/sh
> /dmctl --master-addr 127.0.0.1:8261 list-member
```

## Destroy

```bash
> kubectl -n <namespace> delete -f ./
```

The PVCs used by DM cluster will not be deleted in the above process, therefore, the PVs will be not be released neither. You can delete PVCs and release the PVs by the following command:

```bash
> kubectl -n <namespace> delete pvc -l app.kubernetes.io/instance=basic,app.kubernetes.io/managed-by=tidb-operator
```

26 changes: 26 additions & 0 deletions examples/dm/dm-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: pingcap.com/v1alpha1
kind: DMCluster
metadata:
name: basic
namespace: demo
spec:
version: v2.0.0-beta.2
pvReclaimPolicy: Delete
discovery:
address: "http://basic-discovery.demo:10261"
master:
baseImage: pingcap/dm
replicas: 1
# if storageClassName is not set, the default Storage Class of the Kubernetes cluster will be used
# storageClassName: local-storage
storageSize: "1Gi"
requests: {}
config: {}
worker:
baseImage: pingcap/dm
replicas: 1
# if storageClassName is not set, the default Storage Class of the Kubernetes cluster will be used
# storageClassName: local-storage
storageSize: "1Gi"
requests: {}
config: {}
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkY
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/cadvisor v0.34.0 h1:No7G6U/TasplR9uNqyc5Jj0Bet5VSYsK5xLygOf4pUw=
github.com/google/cadvisor v0.34.0/go.mod h1:1nql6U13uTHaLYB8rLS5x9IJc2qT6Xd/Tr1sTX6NE48=
github.com/google/certificate-transparency-go v1.0.21/go.mod h1:QeJfpSbVSfYc7RgB3gJFj9cbuQMMchQxrWXz8Ruopmg=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down
1 change: 1 addition & 0 deletions hack/update-crd-groups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export GO111MODULE=on
go install github.com/pingcap/tidb-operator/cmd/to-crdgen

to-crdgen generate tidbcluster > $crd_target
to-crdgen generate dmcluster >> $crd_target
to-crdgen generate backup >> $crd_target
to-crdgen generate restore >> $crd_target
to-crdgen generate backupschedule >> $crd_target
Expand Down
Loading

0 comments on commit d6edf59

Please sign in to comment.