Skip to content

Commit

Permalink
Add CDC Controller (#2362)
Browse files Browse the repository at this point in the history
  • Loading branch information
weekface authored May 20, 2020
1 parent 3e1b7f9 commit 25ed92f
Show file tree
Hide file tree
Showing 14 changed files with 633 additions and 3 deletions.
84 changes: 84 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8071,6 +8071,76 @@ Same for other components.</p>
</tr>
</tbody>
</table>
<h3 id="ticdcconfig">TiCDCConfig</h3>
<p>
(<em>Appears on:</em>
<a href="#ticdcspec">TiCDCSpec</a>)
</p>
<p>
<p>TiCDCConfig is the configuration of tidbcdc</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>timezone</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Time zone of TiCDC
Optional: Defaults to UTC</p>
</td>
</tr>
<tr>
<td>
<code>gcTTL</code></br>
<em>
int32
</em>
</td>
<td>
<em>(Optional)</em>
<p>CDC GC safepoint TTL duration, specified in seconds
Optional: Defaults to 86400</p>
</td>
</tr>
<tr>
<td>
<code>logLevel</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>LogLevel is the log level
Optional: Defaults to info</p>
</td>
</tr>
<tr>
<td>
<code>logFile</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>LogFile is the log file
Optional: Defaults to /dev/stderr</p>
</td>
</tr>
</tbody>
</table>
<h3 id="ticdcspec">TiCDCSpec</h3>
<p>
(<em>Appears on:</em>
Expand Down Expand Up @@ -8151,6 +8221,20 @@ string
<p>Base image of the component, image tag is now allowed during validation</p>
</td>
</tr>
<tr>
<td>
<code>config</code></br>
<em>
<a href="#ticdcconfig">
TiCDCConfig
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Config is the Configuration of tidbcdc servers</p>
</td>
</tr>
</tbody>
</table>
<h3 id="tidbaccessconfig">TiDBAccessConfig</h3>
Expand Down
12 changes: 12 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,18 @@ spec:
type: object
baseImage:
type: string
config:
properties:
gcTTL:
format: int32
type: integer
logFile:
type: string
logLevel:
type: string
timezone:
type: string
type: object
configUpdateStrategy:
type: string
env:
Expand Down
50 changes: 49 additions & 1 deletion pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions pkg/apis/pingcap/v1alpha1/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ func (tc *TidbCluster) TiFlashImage() string {
return image
}

func (tc *TidbCluster) TiCDCImage() string {
image := tc.Spec.TiCDC.Image
baseImage := tc.Spec.TiCDC.BaseImage
// base image takes higher priority
if baseImage != "" {
version := tc.Spec.TiCDC.Version
if version == nil {
version = &tc.Spec.Version
}
image = fmt.Sprintf("%s:%s", baseImage, *version)
}
return image
}

func (tc *TidbCluster) TiFlashContainerPrivilege() *bool {
if tc.Spec.TiFlash.Privileged == nil {
pri := false
Expand Down Expand Up @@ -336,6 +350,14 @@ func (tc *TidbCluster) TiFlashStsDesiredReplicas() int32 {
return tc.Spec.TiFlash.Replicas + int32(len(tc.Status.TiFlash.FailureStores))
}

func (tc *TidbCluster) TiCDCDeployDesiredReplicas() int32 {
if tc.Spec.TiCDC == nil {
return 0
}

return tc.Spec.TiCDC.Replicas
}

func (tc *TidbCluster) TiFlashStsActualReplicas() int32 {
stsStatus := tc.Status.TiFlash.StatefulSet
if stsStatus == nil {
Expand Down Expand Up @@ -523,3 +545,35 @@ func (tc *TidbCluster) SkipTLSWhenConnectTiDB() bool {
_, ok := tc.Annotations[label.AnnSkipTLSWhenConnectTiDB]
return ok
}

func (tc *TidbCluster) TiCDCTimezone() string {
if tc.Spec.TiCDC != nil && tc.Spec.TiCDC.Config != nil && tc.Spec.TiCDC.Config.Timezone != nil {
return *tc.Spec.TiCDC.Config.Timezone
}

return tc.Timezone()
}

func (tc *TidbCluster) TiCDCGCTTL() int32 {
if tc.Spec.TiCDC != nil && tc.Spec.TiCDC.Config != nil && tc.Spec.TiCDC.Config.GCTTL != nil {
return *tc.Spec.TiCDC.Config.GCTTL
}

return 86400
}

func (tc *TidbCluster) TiCDCLogFile() string {
if tc.Spec.TiCDC != nil && tc.Spec.TiCDC.Config != nil && tc.Spec.TiCDC.Config.LogFile != nil {
return *tc.Spec.TiCDC.Config.LogFile
}

return "/dev/stderr"
}

func (tc *TidbCluster) TiCDCLogLevel() string {
if tc.Spec.TiCDC != nil && tc.Spec.TiCDC.Config != nil && tc.Spec.TiCDC.Config.LogLevel != nil {
return *tc.Spec.TiCDC.Config.LogLevel
}

return "info"
}
5 changes: 5 additions & 0 deletions pkg/apis/pingcap/v1alpha1/tidbcluster_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ func (tc *TidbCluster) BaseTiFlashSpec() ComponentAccessor {
return &componentAccessorImpl{&tc.Spec, &tc.Spec.TiFlash.ComponentSpec}
}

// BaseTiCDCSpec returns the base spec of TiCDC servers
func (tc *TidbCluster) BaseTiCDCSpec() ComponentAccessor {
return &componentAccessorImpl{&tc.Spec, &tc.Spec.TiCDC.ComponentSpec}
}

// BasePDSpec returns the base spec of PD servers
func (tc *TidbCluster) BasePDSpec() ComponentAccessor {
return &componentAccessorImpl{&tc.Spec, &tc.Spec.PD.ComponentSpec}
Expand Down
30 changes: 30 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
TiKVMemberType MemberType = "tikv"
// TiFlashMemberType is tiflash container type
TiFlashMemberType MemberType = "tiflash"
// TiCDCMemberType is ticdc container type
TiCDCMemberType MemberType = "ticdc"
// SlowLogTailerMemberType is tidb log tailer container type
SlowLogTailerMemberType MemberType = "slowlog"
// UnknownMemberType is unknown container type
Expand Down Expand Up @@ -398,6 +400,34 @@ type TiCDCSpec struct {
// +kubebuilder:default=pingcap/ticdc
// +optional
BaseImage string `json:"baseImage"`

// Config is the Configuration of tidbcdc servers
// +optional
Config *TiCDCConfig `json:"config,omitempty"`
}

// TiCDCConfig is the configuration of tidbcdc
// +k8s:openapi-gen=true
type TiCDCConfig struct {
// Time zone of TiCDC
// Optional: Defaults to UTC
// +optional
Timezone *string `json:"timezone,omitempty"`

// CDC GC safepoint TTL duration, specified in seconds
// Optional: Defaults to 86400
// +optional
GCTTL *int32 `json:"gcTTL,omitempty"`

// LogLevel is the log level
// Optional: Defaults to info
// +optional
LogLevel *string `json:"logLevel,omitempty"`

// LogFile is the log file
// Optional: Defaults to /dev/stderr
// +optional
LogFile *string `json:"logFile,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down
41 changes: 41 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/controller/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,21 @@ func TiFlashMemberName(clusterName string) string {
return fmt.Sprintf("%s-tiflash", clusterName)
}

// TiCDCMemberName returns ticdc member name
func TiCDCMemberName(clusterName string) string {
return fmt.Sprintf("%s-ticdc", clusterName)
}

// TiFlashPeerMemberName returns tiflash peer service name
func TiFlashPeerMemberName(clusterName string) string {
return fmt.Sprintf("%s-tiflash-peer", clusterName)
}

// TiCDCPeerMemberName returns ticdc peer service name
func TiCDCPeerMemberName(clusterName string) string {
return fmt.Sprintf("%s-ticdc-peer", clusterName)
}

// TiDBMemberName returns tidb member name
func TiDBMemberName(clusterName string) string {
return fmt.Sprintf("%s-tidb", clusterName)
Expand Down
Loading

0 comments on commit 25ed92f

Please sign in to comment.