From 054aeaea9bad948dd2e64fb4740741819a44332b Mon Sep 17 00:00:00 2001
From: oliviachenairbnb <118773906+oliviachenairbnb@users.noreply.github.com>
Date: Sun, 25 Jun 2023 20:57:21 -0700
Subject: [PATCH] make pd start timeout configurable (#5071)
---
docs/api-references/docs.md | 11 +++++++++++
manifests/crd.yaml | 3 +++
manifests/crd/v1/pingcap.com_tidbclusters.yaml | 3 +++
manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml | 2 ++
manifests/crd_v1beta1.yaml | 2 ++
pkg/apis/pingcap/v1alpha1/openapi_generated.go | 7 +++++++
pkg/apis/pingcap/v1alpha1/types.go | 4 ++++
pkg/manager/member/startscript/v1/render_script.go | 5 +++--
pkg/manager/member/startscript/v1/template.go | 3 ++-
pkg/manager/member/startscript/v1/template_test.go | 4 +++-
pkg/manager/member/startscript/v2/pd_start_script.go | 5 ++++-
.../member/startscript/v2/pd_start_script_test.go | 4 +++-
12 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/docs/api-references/docs.md b/docs/api-references/docs.md
index 789440c5fb..b152206c56 100644
--- a/docs/api-references/docs.md
+++ b/docs/api-references/docs.md
@@ -11528,6 +11528,17 @@ string
Start up script version
+
+
+startTimeout
+
+int
+
+ |
+
+ Timeout threshold when pd get started
+ |
+
PDStatus
diff --git a/manifests/crd.yaml b/manifests/crd.yaml
index 36c7bd0582..591d9f992d 100644
--- a/manifests/crd.yaml
+++ b/manifests/crd.yaml
@@ -19683,6 +19683,9 @@ spec:
type: object
serviceAccount:
type: string
+ startTimeout:
+ default: 30
+ type: integer
startUpScriptVersion:
enum:
- ""
diff --git a/manifests/crd/v1/pingcap.com_tidbclusters.yaml b/manifests/crd/v1/pingcap.com_tidbclusters.yaml
index 8249bfe174..e0ae7bf647 100644
--- a/manifests/crd/v1/pingcap.com_tidbclusters.yaml
+++ b/manifests/crd/v1/pingcap.com_tidbclusters.yaml
@@ -5065,6 +5065,9 @@ spec:
type: object
serviceAccount:
type: string
+ startTimeout:
+ default: 30
+ type: integer
startUpScriptVersion:
enum:
- ""
diff --git a/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml b/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml
index 0deacc7d5c..4ea649196c 100644
--- a/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml
+++ b/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml
@@ -5059,6 +5059,8 @@ spec:
type: object
serviceAccount:
type: string
+ startTimeout:
+ type: integer
startUpScriptVersion:
enum:
- ""
diff --git a/manifests/crd_v1beta1.yaml b/manifests/crd_v1beta1.yaml
index 5e571d724b..56a5de17c1 100644
--- a/manifests/crd_v1beta1.yaml
+++ b/manifests/crd_v1beta1.yaml
@@ -19661,6 +19661,8 @@ spec:
type: object
serviceAccount:
type: string
+ startTimeout:
+ type: integer
startUpScriptVersion:
enum:
- ""
diff --git a/pkg/apis/pingcap/v1alpha1/openapi_generated.go b/pkg/apis/pingcap/v1alpha1/openapi_generated.go
index 67a2b3410f..5834ca8ceb 100644
--- a/pkg/apis/pingcap/v1alpha1/openapi_generated.go
+++ b/pkg/apis/pingcap/v1alpha1/openapi_generated.go
@@ -6177,6 +6177,13 @@ func schema_pkg_apis_pingcap_v1alpha1_PDSpec(ref common.ReferenceCallback) commo
Format: "",
},
},
+ "startTimeout": {
+ SchemaProps: spec.SchemaProps{
+ Description: "Timeout threshold when pd get started",
+ Type: []string{"integer"},
+ Format: "int32",
+ },
+ },
},
Required: []string{"replicas"},
},
diff --git a/pkg/apis/pingcap/v1alpha1/types.go b/pkg/apis/pingcap/v1alpha1/types.go
index 6004f0f794..3a17ad77dc 100644
--- a/pkg/apis/pingcap/v1alpha1/types.go
+++ b/pkg/apis/pingcap/v1alpha1/types.go
@@ -514,6 +514,10 @@ type PDSpec struct {
// +optional
// +kubebuilder:validation:Enum:="";"v1"
StartUpScriptVersion string `json:"startUpScriptVersion,omitempty"`
+
+ // Timeout threshold when pd get started
+ // +kubebuilder:default=30
+ StartTimeout int `json:"startTimeout,omitempty"`
}
// TiKVSpec contains details of TiKV members
diff --git a/pkg/manager/member/startscript/v1/render_script.go b/pkg/manager/member/startscript/v1/render_script.go
index 163be33eb8..fdb2844df0 100644
--- a/pkg/manager/member/startscript/v1/render_script.go
+++ b/pkg/manager/member/startscript/v1/render_script.go
@@ -63,8 +63,9 @@ func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {
AcrossK8s: tc.AcrossK8s(),
ClusterDomain: tc.Spec.ClusterDomain,
},
- Scheme: tc.Scheme(),
- DataDir: filepath.Join(constants.PDDataVolumeMountPath, tc.Spec.PD.DataSubDir),
+ Scheme: tc.Scheme(),
+ DataDir: filepath.Join(constants.PDDataVolumeMountPath, tc.Spec.PD.DataSubDir),
+ PDStartTimeout: tc.Spec.PD.StartTimeout,
}
if tc.Spec.PD.StartUpScriptVersion == "v1" {
model.CheckDomainScript = checkDNSV1
diff --git a/pkg/manager/member/startscript/v1/template.go b/pkg/manager/member/startscript/v1/template.go
index 568b31664c..634120409d 100644
--- a/pkg/manager/member/startscript/v1/template.go
+++ b/pkg/manager/member/startscript/v1/template.go
@@ -155,7 +155,7 @@ encoded_domain_url=` + "`" + `echo ${domain}:2380 | base64 | tr "\n" " " | sed "
`
elapseTime=0
period=1
-threshold=30
+threshold={{ .PDStartTimeout }}
while true; do
sleep ${period}
elapseTime=$(( elapseTime+period ))
@@ -245,6 +245,7 @@ type PDStartScriptModel struct {
Scheme string
DataDir string
CheckDomainScript string
+ PDStartTimeout int
}
var tikvStartScriptTplText = `#!/bin/sh
diff --git a/pkg/manager/member/startscript/v1/template_test.go b/pkg/manager/member/startscript/v1/template_test.go
index 6fb0edce73..8a7281070e 100644
--- a/pkg/manager/member/startscript/v1/template_test.go
+++ b/pkg/manager/member/startscript/v1/template_test.go
@@ -1227,7 +1227,9 @@ exec /pd-server ${ARGS}
tc := &v1alpha1.TidbCluster{
Spec: v1alpha1.TidbClusterSpec{
- PD: &v1alpha1.PDSpec{},
+ PD: &v1alpha1.PDSpec{
+ StartTimeout: 30,
+ },
},
}
tc.Name = "test-pd"
diff --git a/pkg/manager/member/startscript/v2/pd_start_script.go b/pkg/manager/member/startscript/v2/pd_start_script.go
index 23459e6493..7fdbb9c865 100644
--- a/pkg/manager/member/startscript/v2/pd_start_script.go
+++ b/pkg/manager/member/startscript/v2/pd_start_script.go
@@ -35,6 +35,7 @@ type PDStartScriptModel struct {
AdvertiseClientURL string
DiscoveryAddr string
ExtraArgs string
+ PDStartTimeout int
}
// RenderPDStartScript renders PD start script from TidbCluster
@@ -66,6 +67,8 @@ func RenderPDStartScript(tc *v1alpha1.TidbCluster) (string, error) {
m.DiscoveryAddr = fmt.Sprintf("%s-discovery.%s:10261", tcName, tcNS)
+ m.PDStartTimeout = tc.Spec.PD.StartTimeout
+
return renderTemplateFunc(pdStartScriptTpl, m)
}
@@ -80,7 +83,7 @@ PD_DOMAIN={{ .PDDomain }}
elapseTime=0
period=1
-threshold=30
+threshold={{ .PDStartTimeout }}
while true; do
sleep ${period}
elapseTime=$(( elapseTime+period ))
diff --git a/pkg/manager/member/startscript/v2/pd_start_script_test.go b/pkg/manager/member/startscript/v2/pd_start_script_test.go
index fc0b838348..f9666b47de 100644
--- a/pkg/manager/member/startscript/v2/pd_start_script_test.go
+++ b/pkg/manager/member/startscript/v2/pd_start_script_test.go
@@ -543,7 +543,9 @@ exec /pd-server ${ARGS}
tc := &v1alpha1.TidbCluster{
Spec: v1alpha1.TidbClusterSpec{
- PD: &v1alpha1.PDSpec{},
+ PD: &v1alpha1.PDSpec{
+ StartTimeout: 30,
+ },
},
}
tc.Name = "start-script-test"