Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dm-operator/: support start a new dm cluster with dm-masters and dm-workers #3146

Merged
merged 40 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
08a8ae4
add dmclusters CRD
lichunzhu Aug 5, 2020
5cb82ac
resolve conflicts
lichunzhu Aug 5, 2020
bcf58ea
Merge branch 'master' into defineDMSpec
lichunzhu Aug 5, 2020
55a6365
address comment
lichunzhu Aug 6, 2020
0aae8c0
Merge branch 'master' into defineDMSpec
lichunzhu Aug 6, 2020
f146be1
address comments
lichunzhu Aug 6, 2020
94c427b
Merge branch 'defineDMSpec' of https://github.com/lichunzhu/tidb-oper…
lichunzhu Aug 6, 2020
4f10a51
delete monitor ref
lichunzhu Aug 6, 2020
a020492
generate dmcluster client
lichunzhu Aug 6, 2020
3edfaa2
address comments
lichunzhu Aug 6, 2020
74aca39
Merge branch 'master' into defineDMSpec
lichunzhu Aug 7, 2020
2c1bec5
address comment
lichunzhu Aug 7, 2020
fbe26f3
tmp commit
lichunzhu Aug 7, 2020
d85a9fc
resolve conflict
lichunzhu Aug 7, 2020
a9da15f
merge master
lichunzhu Aug 11, 2020
ba0f518
remove dm package
lichunzhu Aug 12, 2020
7a51c07
fix bugs
lichunzhu Aug 12, 2020
3ec6c86
fix bug
lichunzhu Aug 12, 2020
8122c71
support start dm-master and dm-worker in cluster
lichunzhu Aug 18, 2020
a38bb0e
fix some bugs
lichunzhu Aug 19, 2020
1e7efd8
merge master branch and resolve conflicts
lichunzhu Aug 19, 2020
850035c
fix ut
lichunzhu Aug 20, 2020
cd3f5b4
fix dm-master start
lichunzhu Aug 24, 2020
f4a641d
fix dm-worker start bug
lichunzhu Aug 24, 2020
5a51cbe
Merge branch 'master' of https://github.com/pingcap/tidb-operator int…
lichunzhu Aug 25, 2020
be4fd5e
add more column info
lichunzhu Aug 25, 2020
1e4f2ac
Merge branch 'master' of https://github.com/pingcap/tidb-operator int…
lichunzhu Aug 25, 2020
daf81f7
Merge branch 'master' into supportStartDMCluster
lichunzhu Aug 25, 2020
f7c70bd
fix ut
lichunzhu Aug 25, 2020
08f4695
fix verify
lichunzhu Aug 25, 2020
e2249f9
fix verify again
lichunzhu Aug 25, 2020
161b862
address comments
lichunzhu Aug 25, 2020
35a69d3
Merge branch 'master' into supportStartDMCluster
lichunzhu Aug 25, 2020
d3da808
regenerate code
lichunzhu Aug 25, 2020
8e52fbb
address comments
lichunzhu Aug 25, 2020
cefe7b8
Merge branch 'master' into supportStartDMCluster
lichunzhu Aug 25, 2020
f1b6029
fix import cycle problem
lichunzhu Aug 26, 2020
7726669
Merge branch 'supportStartDMCluster' of https://github.com/lichunzhu/…
lichunzhu Aug 26, 2020
84a6309
fix check
lichunzhu Aug 26, 2020
5ab015d
address comments
lichunzhu Aug 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 -n <namespace> port-forward svc/basic-dm-master 8261:8261
> dmctl --master-addr 127.0.0.1:8261 list-member
lichunzhu marked this conversation as resolved.
Show resolved Hide resolved
```

## 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