diff --git a/docs/api-references/docs.md b/docs/api-references/docs.md index c1575c75be..37536c84b5 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 39e2162633..7d881192e5 100644 --- a/manifests/crd.yaml +++ b/manifests/crd.yaml @@ -19687,6 +19687,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 b40142db57..21d2f0677c 100644 --- a/manifests/crd_v1beta1.yaml +++ b/manifests/crd_v1beta1.yaml @@ -19665,6 +19665,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 d6834a98cf..6aeedb5c1d 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 7113b6c030..152bd6a10d 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"