Skip to content

Commit 5c7e1a4

Browse files
authored
ticdc: support graceful upgrade TiCDC pods (#4647)
1 parent c59fdf4 commit 5c7e1a4

File tree

14 files changed

+114
-22
lines changed

14 files changed

+114
-22
lines changed

docs/api-references/docs.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14521,6 +14521,22 @@ string
1452114521
Defaults to Kubernetes default storage class.</p>
1452214522
</td>
1452314523
</tr>
14524+
<tr>
14525+
<td>
14526+
<code>gracefulShutdownTimeout</code></br>
14527+
<em>
14528+
<a href="https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
14529+
Kubernetes meta/v1.Duration
14530+
</a>
14531+
</em>
14532+
</td>
14533+
<td>
14534+
<em>(Optional)</em>
14535+
<p>GracefulShutdownTimeout is the timeout of gracefully shutdown a TiCDC pod.
14536+
Encoded in the format of Go Duration.
14537+
Defaults to 10m</p>
14538+
</td>
14539+
</tr>
1452414540
</tbody>
1452514541
</table>
1452614542
<h3 id="ticdcstatus">TiCDCStatus</h3>

manifests/crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21443,6 +21443,8 @@ spec:
2144321443
type: object
2144421444
type: object
2144521445
type: array
21446+
gracefulShutdownTimeout:
21447+
type: string
2144621448
hostNetwork:
2144721449
type: boolean
2144821450
image:

manifests/crd/v1/pingcap.com_tidbclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9134,6 +9134,8 @@ spec:
91349134
type: object
91359135
type: object
91369136
type: array
9137+
gracefulShutdownTimeout:
9138+
type: string
91379139
hostNetwork:
91389140
type: boolean
91399141
image:

manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9122,6 +9122,8 @@ spec:
91229122
type: object
91239123
type: object
91249124
type: array
9125+
gracefulShutdownTimeout:
9126+
type: string
91259127
hostNetwork:
91269128
type: boolean
91279129
image:

manifests/crd_v1beta1.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21429,6 +21429,8 @@ spec:
2142921429
type: object
2143021430
type: object
2143121431
type: array
21432+
gracefulShutdownTimeout:
21433+
type: string
2143221434
hostNetwork:
2143321435
type: boolean
2143421436
image:

pkg/apis/pingcap/v1alpha1/openapi_generated.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/pingcap/v1alpha1/tidbcluster.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const (
3838
defaultEnablePVReclaim = false
3939
// defaultEvictLeaderTimeout is the timeout limit of evict leader
4040
defaultEvictLeaderTimeout = 1500 * time.Minute
41+
// defaultTiCDCGracefulShutdownTimeout is the timeout limit of graceful
42+
// shutdown a TiCDC pod.
43+
defaultTiCDCGracefulShutdownTimeout = 10 * time.Minute
4144
)
4245

4346
var (
@@ -194,6 +197,14 @@ func (tc *TidbCluster) TiFlashVersion() string {
194197
return "latest"
195198
}
196199

200+
func (tc *TidbCluster) TiFlashContainerPrivilege() *bool {
201+
if tc.Spec.TiFlash == nil || tc.Spec.TiFlash.Privileged == nil {
202+
pri := false
203+
return &pri
204+
}
205+
return tc.Spec.TiFlash.Privileged
206+
}
207+
197208
// TiCDCImage return the image used by TiCDC.
198209
//
199210
// If TiCDC isn't specified, return empty string.
@@ -219,12 +230,13 @@ func (tc *TidbCluster) TiCDCImage() string {
219230
return image
220231
}
221232

222-
func (tc *TidbCluster) TiFlashContainerPrivilege() *bool {
223-
if tc.Spec.TiFlash == nil || tc.Spec.TiFlash.Privileged == nil {
224-
pri := false
225-
return &pri
233+
// TiCDCGracefulShutdownTimeout returns the timeout of gracefully shutdown
234+
// a TiCDC pod.
235+
func (tc *TidbCluster) TiCDCGracefulShutdownTimeout() time.Duration {
236+
if tc.Spec.TiCDC != nil && tc.Spec.TiCDC.GracefulShutdownTimeout != nil {
237+
return tc.Spec.TiCDC.GracefulShutdownTimeout.Duration
226238
}
227-
return tc.Spec.TiFlash.Privileged
239+
return defaultTiCDCGracefulShutdownTimeout
228240
}
229241

230242
// TiDBImage return the image used by TiDB.

pkg/apis/pingcap/v1alpha1/tidbcluster_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package v1alpha1
1515

1616
import (
1717
"testing"
18+
"time"
1819

1920
. "github.com/onsi/gomega"
2021
apps "k8s.io/api/apps/v1"
@@ -672,6 +673,19 @@ func TestPDVersion(t *testing.T) {
672673
}
673674
}
674675

676+
func TestTiCDCGracefulShutdownTimeout(t *testing.T) {
677+
g := NewGomegaWithT(t)
678+
679+
tc := newTidbCluster()
680+
g.Expect(tc.TiCDCGracefulShutdownTimeout()).To(Equal(defaultTiCDCGracefulShutdownTimeout))
681+
682+
tc.Spec.TiCDC = &TiCDCSpec{GracefulShutdownTimeout: nil}
683+
g.Expect(tc.TiCDCGracefulShutdownTimeout()).To(Equal(defaultTiCDCGracefulShutdownTimeout))
684+
685+
tc.Spec.TiCDC = &TiCDCSpec{GracefulShutdownTimeout: &metav1.Duration{Duration: time.Minute}}
686+
g.Expect(tc.TiCDCGracefulShutdownTimeout()).To(Equal(time.Minute))
687+
}
688+
675689
func TestComponentFunc(t *testing.T) {
676690
t.Run("ComponentIsNormal", func(t *testing.T) {
677691
g := NewGomegaWithT(t)

pkg/apis/pingcap/v1alpha1/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,12 @@ type TiCDCSpec struct {
680680
// Defaults to Kubernetes default storage class.
681681
// +optional
682682
StorageClassName *string `json:"storageClassName,omitempty"`
683+
684+
// GracefulShutdownTimeout is the timeout of gracefully shutdown a TiCDC pod.
685+
// Encoded in the format of Go Duration.
686+
// Defaults to 10m
687+
// +optional
688+
GracefulShutdownTimeout *metav1.Duration `json:"gracefulShutdownTimeout,omitempty"`
683689
}
684690

685691
// TiCDCConfig is the configuration of tidbcdc

pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)