From 363cf383f52ef66145444f363fbb5d1beecb8f75 Mon Sep 17 00:00:00 2001 From: fgksgf Date: Tue, 7 Feb 2023 11:49:27 +0800 Subject: [PATCH 1/7] add `BootstrapSQLConfigMapName` to TiDBSpec --- docs/api-references/docs.md | 14 ++++ manifests/crd.yaml | 2 + .../crd/v1/pingcap.com_tidbclusters.yaml | 2 + .../crd/v1beta1/pingcap.com_tidbclusters.yaml | 2 + manifests/crd_v1beta1.yaml | 2 + .../pingcap/v1alpha1/openapi_generated.go | 8 +++ pkg/apis/pingcap/v1alpha1/types.go | 7 ++ .../pingcap/v1alpha1/validation/validation.go | 16 +++++ .../v1alpha1/validation/validation_test.go | 71 +++++++++++++++++++ .../pingcap/v1alpha1/zz_generated.deepcopy.go | 6 ++ 10 files changed, 130 insertions(+) diff --git a/docs/api-references/docs.md b/docs/api-references/docs.md index 695853e463..c4a4be7a7a 100644 --- a/docs/api-references/docs.md +++ b/docs/api-references/docs.md @@ -16587,6 +16587,20 @@ TiDBInitializer

Initializer is the init configurations of TiDB

+ + +bootstrapSQLFile
+ +string + + + +(Optional) +

BootstrapSQLConfigMapName is the name of the ConfigMap which contains the bootstrap SQL file with the key bootstrap-sql, +which will only be executed when a TiDB cluster bootstrap on the first time. +Only v6.6.0+ supports this feature.

+ +

TiDBStatus

diff --git a/manifests/crd.yaml b/manifests/crd.yaml index d9962e0c38..a73fba1049 100644 --- a/manifests/crd.yaml +++ b/manifests/crd.yaml @@ -24698,6 +24698,8 @@ spec: type: string binlogEnabled: type: boolean + bootstrapSQLFile: + type: string config: x-kubernetes-preserve-unknown-fields: true configUpdateStrategy: diff --git a/manifests/crd/v1/pingcap.com_tidbclusters.yaml b/manifests/crd/v1/pingcap.com_tidbclusters.yaml index d1258fc32d..4deaa712d7 100644 --- a/manifests/crd/v1/pingcap.com_tidbclusters.yaml +++ b/manifests/crd/v1/pingcap.com_tidbclusters.yaml @@ -11443,6 +11443,8 @@ spec: type: string binlogEnabled: type: boolean + bootstrapSQLFile: + type: string config: x-kubernetes-preserve-unknown-fields: true configUpdateStrategy: diff --git a/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml b/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml index f73148298d..1c57dd33ab 100644 --- a/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml +++ b/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml @@ -11428,6 +11428,8 @@ spec: type: string binlogEnabled: type: boolean + bootstrapSQLFile: + type: string config: x-kubernetes-preserve-unknown-fields: true configUpdateStrategy: diff --git a/manifests/crd_v1beta1.yaml b/manifests/crd_v1beta1.yaml index 539abaab91..b0e0e84269 100644 --- a/manifests/crd_v1beta1.yaml +++ b/manifests/crd_v1beta1.yaml @@ -24678,6 +24678,8 @@ spec: type: string binlogEnabled: type: boolean + bootstrapSQLFile: + type: string config: x-kubernetes-preserve-unknown-fields: true configUpdateStrategy: diff --git a/pkg/apis/pingcap/v1alpha1/openapi_generated.go b/pkg/apis/pingcap/v1alpha1/openapi_generated.go index 63cd9d6f04..52525f742a 100644 --- a/pkg/apis/pingcap/v1alpha1/openapi_generated.go +++ b/pkg/apis/pingcap/v1alpha1/openapi_generated.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated // Copyright PingCAP, Inc. @@ -8674,6 +8675,13 @@ func schema_pkg_apis_pingcap_v1alpha1_TiDBSpec(ref common.ReferenceCallback) com Ref: ref("github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiDBInitializer"), }, }, + "bootstrapSQLFile": { + SchemaProps: spec.SchemaProps{ + Description: "BootstrapSQLConfigMapName is the name of the ConfigMap which contains the bootstrap SQL file with the key `bootstrap-sql`, which will only be executed when a TiDB cluster bootstrap on the first time. Only v6.6.0+ supports this feature.", + Type: []string{"string"}, + Format: "", + }, + }, }, Required: []string{"replicas"}, }, diff --git a/pkg/apis/pingcap/v1alpha1/types.go b/pkg/apis/pingcap/v1alpha1/types.go index 87a7680744..63bc97dd7f 100644 --- a/pkg/apis/pingcap/v1alpha1/types.go +++ b/pkg/apis/pingcap/v1alpha1/types.go @@ -907,6 +907,13 @@ type TiDBSpec struct { // // +optional Initializer *TiDBInitializer `json:"initializer,omitempty"` + + // BootstrapSQLConfigMapName is the name of the ConfigMap which contains the bootstrap SQL file with the key `bootstrap-sql`, + // which will only be executed when a TiDB cluster bootstrap on the first time. + // Only v6.6.0+ supports this feature. + // +immutable + // +optional + BootstrapSQLConfigMapName *string `json:"bootstrapSQLFile,omitempty"` } type TiDBInitializer struct { diff --git a/pkg/apis/pingcap/v1alpha1/validation/validation.go b/pkg/apis/pingcap/v1alpha1/validation/validation.go index 666b4370f5..e7094b8b70 100644 --- a/pkg/apis/pingcap/v1alpha1/validation/validation.go +++ b/pkg/apis/pingcap/v1alpha1/validation/validation.go @@ -536,6 +536,7 @@ func ValidateUpdateTidbCluster(old, tc *v1alpha1.TidbCluster) field.ErrorList { "The instance must not be mutate or set value other than the cluster name")) } allErrs = append(allErrs, validateUpdatePDConfig(old.Spec.PD, tc.Spec.PD, field.NewPath("spec.pd.config"))...) + allErrs = append(allErrs, disallowMutateBootstrapSQLConfigMapName(old.Spec.TiDB, tc.Spec.TiDB, field.NewPath("spec.tidb.bootstrapSQLConfigMapName"))...) allErrs = append(allErrs, disallowUsingLegacyAPIInNewCluster(old, tc)...) return allErrs @@ -643,6 +644,21 @@ func validateUpdatePDConfig(oldPdSpec, pdSpec *v1alpha1.PDSpec, path *field.Path return allErrs } +func disallowMutateBootstrapSQLConfigMapName(old, new *v1alpha1.TiDBSpec, p *field.Path) field.ErrorList { + allErrs := field.ErrorList{} + if old == nil || new == nil { + return allErrs + } + + bootstrapSQLSpecified := old.BootstrapSQLConfigMapName != nil && new.BootstrapSQLConfigMapName != nil + if (bootstrapSQLSpecified && *old.BootstrapSQLConfigMapName != *new.BootstrapSQLConfigMapName) || + !bootstrapSQLSpecified && old.BootstrapSQLConfigMapName != new.BootstrapSQLConfigMapName { + return append(allErrs, field.Invalid(p, new.BootstrapSQLConfigMapName, "bootstrapSQLConfigMapName is immutable")) + } + + return allErrs +} + func validateDeleteSlots(annotations map[string]string, key string, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} if annotations != nil { diff --git a/pkg/apis/pingcap/v1alpha1/validation/validation_test.go b/pkg/apis/pingcap/v1alpha1/validation/validation_test.go index a40b6d5df1..5de9f822eb 100644 --- a/pkg/apis/pingcap/v1alpha1/validation/validation_test.go +++ b/pkg/apis/pingcap/v1alpha1/validation/validation_test.go @@ -749,3 +749,74 @@ func TestValidatePDSpec(t *testing.T) { }) } } + +func Test_disallowMutateBootstrapSQLConfigMapName(t *testing.T) { + g := NewGomegaWithT(t) + tests := []struct { + name string + old *v1alpha1.TiDBSpec + new *v1alpha1.TiDBSpec + wantError bool + }{ + { + name: "no change, both nil", + old: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: nil, + }, + new: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: nil, + }, + wantError: false, + }, + { + name: "no change, both non-nil", + old: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: pointer.StringPtr("old"), + }, + new: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: pointer.StringPtr("old"), + }, + wantError: false, + }, + { + name: "mutate from non-nil to nil", + old: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: pointer.StringPtr("old"), + }, + new: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: nil, + }, + wantError: true, + }, + { + name: "mutate from nil to non-nil", + old: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: nil, + }, + new: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: pointer.StringPtr("new"), + }, + wantError: true, + }, + { + name: "mutate from non-nil to non-nil", + old: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: pointer.StringPtr("old"), + }, + new: &v1alpha1.TiDBSpec{ + BootstrapSQLConfigMapName: pointer.StringPtr("new"), + }, + wantError: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + errs := disallowMutateBootstrapSQLConfigMapName(tt.old, tt.new, field.NewPath("spec.tidb.bootstrapSQLConfigMapName")) + if tt.wantError { + g.Expect(len(errs)).NotTo(Equal(0)) + } else { + g.Expect(len(errs)).To(Equal(0)) + } + }) + } +} diff --git a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go index 863a464595..2f7268f271 100644 --- a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated // Copyright PingCAP, Inc. @@ -5953,6 +5954,11 @@ func (in *TiDBSpec) DeepCopyInto(out *TiDBSpec) { *out = new(TiDBInitializer) **out = **in } + if in.BootstrapSQLConfigMapName != nil { + in, out := &in.BootstrapSQLConfigMapName, &out.BootstrapSQLConfigMapName + *out = new(string) + **out = **in + } return } From 08b4f42ab429ceb71b70949ae07bf068b1e0ad75 Mon Sep 17 00:00:00 2001 From: fgksgf Date: Tue, 7 Feb 2023 12:10:20 +0800 Subject: [PATCH 2/7] support bootstrap sql --- pkg/apis/pingcap/v1alpha1/tidbcluster.go | 19 +++++++++++++++++++ pkg/manager/member/constants/constants.go | 3 +++ .../member/startscript/v1/render_script.go | 12 ++++++++---- pkg/manager/member/startscript/v1/template.go | 14 ++++++++++---- .../startscript/v2/tidb_start_script.go | 5 +++++ pkg/manager/member/tidb_member_manager.go | 16 ++++++++++++++++ pkg/util/util.go | 4 ++++ 7 files changed, 65 insertions(+), 8 deletions(-) diff --git a/pkg/apis/pingcap/v1alpha1/tidbcluster.go b/pkg/apis/pingcap/v1alpha1/tidbcluster.go index e19578154c..952cf580e9 100644 --- a/pkg/apis/pingcap/v1alpha1/tidbcluster.go +++ b/pkg/apis/pingcap/v1alpha1/tidbcluster.go @@ -19,6 +19,7 @@ import ( "strings" "time" + "github.com/Masterminds/semver" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/types" @@ -55,6 +56,10 @@ var ( ResourceRequirements: corev1.ResourceRequirements{}, } defaultHelperSpec = HelperSpec{} + + // The first version that supports `-initialize-sql-file` option for first bootstrap is v6.6.0 + // https://github.com/pingcap/tidb/pull/35625 + tidbEqualOrGreaterThanV660, _ = semver.NewConstraint(">= v6.6.0-0") ) // PDImage return the image used by PD. @@ -949,6 +954,20 @@ func (tc *TidbCluster) IsTiDBBinlogEnabled() bool { return *binlogEnabled } +func (tidb *TiDBSpec) IsBootstrapSQLEnabled() bool { + if tidb.Version == nil { + return false + } + + v, err := semver.NewVersion(*tidb.Version) + if err != nil { + klog.Errorf("parse tidb version %s failed, err: %v", *tidb.Version, err) + return false + } + + return tidbEqualOrGreaterThanV660.Check(v) && tidb.BootstrapSQLConfigMapName != nil && *tidb.BootstrapSQLConfigMapName != "" +} + func (tidb *TiDBSpec) IsTLSClientEnabled() bool { return tidb.TLSClient != nil && tidb.TLSClient.Enabled } diff --git a/pkg/manager/member/constants/constants.go b/pkg/manager/member/constants/constants.go index 1df08d0d69..f602452f02 100644 --- a/pkg/manager/member/constants/constants.go +++ b/pkg/manager/member/constants/constants.go @@ -25,4 +25,7 @@ const ( // TiCDCCertPath is the path for ticdc cert in container TiCDCCertPath = "/var/lib/ticdc-tls" + + // BootstrapSQLFile is the path for bootstrap sql file. + BootstrapSQLFile = "/etc/tidb-bootstrap/bootstrap.sql" ) diff --git a/pkg/manager/member/startscript/v1/render_script.go b/pkg/manager/member/startscript/v1/render_script.go index c91cc2eae3..539f2aa690 100644 --- a/pkg/manager/member/startscript/v1/render_script.go +++ b/pkg/manager/member/startscript/v1/render_script.go @@ -79,11 +79,15 @@ func RenderTiDBStartScript(tc *v1alpha1.TidbCluster) (string, error) { AcrossK8s: tc.AcrossK8s(), ClusterDomain: tc.Spec.ClusterDomain, }, - EnablePlugin: len(plugins) > 0, - PluginDirectory: "/plugins", - PluginList: strings.Join(plugins, ","), + EnablePlugin: len(plugins) > 0, + PluginDirectory: "/plugins", + PluginList: strings.Join(plugins, ","), + EnableBootstrapSQL: false, + } + if tc.Spec.TiDB != nil { + model.EnableBootstrapSQL = tc.Spec.TiDB.IsBootstrapSQLEnabled() + model.BootstrapSQLFile = constants.BootstrapSQLFile } - model.Path = "${CLUSTER_NAME}-pd:2379" if tc.AcrossK8s() { model.Path = "${CLUSTER_NAME}-pd:2379" // get pd addr from discovery in startup script diff --git a/pkg/manager/member/startscript/v1/template.go b/pkg/manager/member/startscript/v1/template.go index 2ae6defa56..4df0144ce0 100644 --- a/pkg/manager/member/startscript/v1/template.go +++ b/pkg/manager/member/startscript/v1/template.go @@ -97,6 +97,10 @@ fi ARGS="${ARGS} --plugin-dir {{ .PluginDirectory }} --plugin-load {{ .PluginList }} " {{- end }} +{{- if .EnableBootstrapSQL }} +ARGS="${ARGS} --initialize-sql-file={{ .BootstrapSQLFile }}" +{{- end }} + echo "start tidb-server ..." echo "/tidb-server ${ARGS}" exec /tidb-server ${ARGS} @@ -105,10 +109,12 @@ exec /tidb-server ${ARGS} type TidbStartScriptModel struct { CommonModel - EnablePlugin bool - PluginDirectory string - PluginList string - Path string + EnablePlugin bool + PluginDirectory string + PluginList string + Path string + EnableBootstrapSQL bool + BootstrapSQLFile string } // pdStartScriptTpl is the pd start script diff --git a/pkg/manager/member/startscript/v2/tidb_start_script.go b/pkg/manager/member/startscript/v2/tidb_start_script.go index b64c1ec13e..67426aba1e 100644 --- a/pkg/manager/member/startscript/v2/tidb_start_script.go +++ b/pkg/manager/member/startscript/v2/tidb_start_script.go @@ -18,6 +18,8 @@ import ( "strings" "text/template" + "github.com/pingcap/tidb-operator/pkg/manager/member/constants" + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1" "github.com/pingcap/tidb-operator/pkg/controller" ) @@ -58,6 +60,9 @@ func RenderTiDBStartScript(tc *v1alpha1.TidbCluster) (string, error) { if tc.IsTiDBBinlogEnabled() { extraArgs = append(extraArgs, "--enable-binlog=true") } + if tc.Spec.TiDB != nil && tc.Spec.TiDB.IsBootstrapSQLEnabled() { + extraArgs = append(extraArgs, fmt.Sprintf("--initialize-sql-file=%s", constants.BootstrapSQLFile)) + } if plugins := tc.Spec.TiDB.Plugins; len(plugins) > 0 { extraArgs = append(extraArgs, "--plugin-dir=/plugins") extraArgs = append(extraArgs, fmt.Sprintf("--plugin-load=%s", strings.Join(plugins, ","))) diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go index 71136bf50d..6d98259357 100644 --- a/pkg/manager/member/tidb_member_manager.go +++ b/pkg/manager/member/tidb_member_manager.go @@ -762,6 +762,22 @@ func getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap) }, }) } + if tc.Spec.TiDB != nil && tc.Spec.TiDB.IsBootstrapSQLEnabled() { + volMounts = append(volMounts, corev1.VolumeMount{ + Name: "tidb-bootstrap-sql", ReadOnly: true, MountPath: "/etc/tidb-bootstrap", + }) + + vols = append(vols, corev1.Volume{ + Name: "tidb-bootstrap-sql", VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: *tc.Spec.TiDB.BootstrapSQLConfigMapName, + }, + Items: []corev1.KeyToPath{{Key: "bootstrap-sql", Path: "bootstrap.sql"}}, + }, + }, + }) + } if tc.IsTLSClusterEnabled() { vols = append(vols, corev1.Volume{ Name: "tidb-tls", VolumeSource: corev1.VolumeSource{ diff --git a/pkg/util/util.go b/pkg/util/util.go index 39e765fb7b..49560cd8da 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -205,6 +205,10 @@ func TiDBAuthTokenJWKSSecretName(tcName string) string { return fmt.Sprintf("%s-tidb-auth-token-jwks-secret", tcName) } +func TiDBBootstrapSQLConfigMapName(tcName string) string { + return fmt.Sprintf("%s-tidb-bootstrap-sql", tcName) +} + // SortEnvByName implements sort.Interface to sort env list by name. type SortEnvByName []corev1.EnvVar From 5c184b28a745d52ea83ef31d9a7d53b9b642061c Mon Sep 17 00:00:00 2001 From: fgksgf Date: Wed, 8 Feb 2023 16:07:28 +0800 Subject: [PATCH 3/7] polish --- docs/api-references/docs.md | 3 ++- manifests/crd.yaml | 2 +- manifests/crd/v1/pingcap.com_tidbclusters.yaml | 2 +- manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml | 2 +- manifests/crd_v1beta1.yaml | 2 +- pkg/apis/pingcap/v1alpha1/openapi_generated.go | 4 ++-- pkg/apis/pingcap/v1alpha1/tidbcluster.go | 6 ++++-- pkg/apis/pingcap/v1alpha1/types.go | 4 ++-- pkg/util/util.go | 4 ---- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/docs/api-references/docs.md b/docs/api-references/docs.md index c4a4be7a7a..88a46fce3e 100644 --- a/docs/api-references/docs.md +++ b/docs/api-references/docs.md @@ -16589,7 +16589,7 @@ TiDBInitializer -bootstrapSQLFile
+bootstrapSQLConfigMapName
string @@ -16598,6 +16598,7 @@ string (Optional)

BootstrapSQLConfigMapName is the name of the ConfigMap which contains the bootstrap SQL file with the key bootstrap-sql, which will only be executed when a TiDB cluster bootstrap on the first time. +The field should be set ONLY when create a TC, since it only take effect on the first time bootstrap. Only v6.6.0+ supports this feature.

diff --git a/manifests/crd.yaml b/manifests/crd.yaml index a73fba1049..4af67bd7da 100644 --- a/manifests/crd.yaml +++ b/manifests/crd.yaml @@ -24698,7 +24698,7 @@ spec: type: string binlogEnabled: type: boolean - bootstrapSQLFile: + bootstrapSQLConfigMapName: type: string config: x-kubernetes-preserve-unknown-fields: true diff --git a/manifests/crd/v1/pingcap.com_tidbclusters.yaml b/manifests/crd/v1/pingcap.com_tidbclusters.yaml index 4deaa712d7..66a8b8df0a 100644 --- a/manifests/crd/v1/pingcap.com_tidbclusters.yaml +++ b/manifests/crd/v1/pingcap.com_tidbclusters.yaml @@ -11443,7 +11443,7 @@ spec: type: string binlogEnabled: type: boolean - bootstrapSQLFile: + bootstrapSQLConfigMapName: type: string config: x-kubernetes-preserve-unknown-fields: true diff --git a/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml b/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml index 1c57dd33ab..b1168e573b 100644 --- a/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml +++ b/manifests/crd/v1beta1/pingcap.com_tidbclusters.yaml @@ -11428,7 +11428,7 @@ spec: type: string binlogEnabled: type: boolean - bootstrapSQLFile: + bootstrapSQLConfigMapName: type: string config: x-kubernetes-preserve-unknown-fields: true diff --git a/manifests/crd_v1beta1.yaml b/manifests/crd_v1beta1.yaml index b0e0e84269..620e47e584 100644 --- a/manifests/crd_v1beta1.yaml +++ b/manifests/crd_v1beta1.yaml @@ -24678,7 +24678,7 @@ spec: type: string binlogEnabled: type: boolean - bootstrapSQLFile: + bootstrapSQLConfigMapName: type: string config: x-kubernetes-preserve-unknown-fields: true diff --git a/pkg/apis/pingcap/v1alpha1/openapi_generated.go b/pkg/apis/pingcap/v1alpha1/openapi_generated.go index 52525f742a..28eaaf0ae9 100644 --- a/pkg/apis/pingcap/v1alpha1/openapi_generated.go +++ b/pkg/apis/pingcap/v1alpha1/openapi_generated.go @@ -8675,9 +8675,9 @@ func schema_pkg_apis_pingcap_v1alpha1_TiDBSpec(ref common.ReferenceCallback) com Ref: ref("github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiDBInitializer"), }, }, - "bootstrapSQLFile": { + "bootstrapSQLConfigMapName": { SchemaProps: spec.SchemaProps{ - Description: "BootstrapSQLConfigMapName is the name of the ConfigMap which contains the bootstrap SQL file with the key `bootstrap-sql`, which will only be executed when a TiDB cluster bootstrap on the first time. Only v6.6.0+ supports this feature.", + Description: "BootstrapSQLConfigMapName is the name of the ConfigMap which contains the bootstrap SQL file with the key `bootstrap-sql`, which will only be executed when a TiDB cluster bootstrap on the first time. The field should be set ONLY when create a TC, since it only take effect on the first time bootstrap. Only v6.6.0+ supports this feature.", Type: []string{"string"}, Format: "", }, diff --git a/pkg/apis/pingcap/v1alpha1/tidbcluster.go b/pkg/apis/pingcap/v1alpha1/tidbcluster.go index 952cf580e9..eba141e4db 100644 --- a/pkg/apis/pingcap/v1alpha1/tidbcluster.go +++ b/pkg/apis/pingcap/v1alpha1/tidbcluster.go @@ -955,7 +955,7 @@ func (tc *TidbCluster) IsTiDBBinlogEnabled() bool { } func (tidb *TiDBSpec) IsBootstrapSQLEnabled() bool { - if tidb.Version == nil { + if tidb.Version == nil || tidb.BootstrapSQLConfigMapName == nil { return false } @@ -965,7 +965,9 @@ func (tidb *TiDBSpec) IsBootstrapSQLEnabled() bool { return false } - return tidbEqualOrGreaterThanV660.Check(v) && tidb.BootstrapSQLConfigMapName != nil && *tidb.BootstrapSQLConfigMapName != "" + ret := tidbEqualOrGreaterThanV660.Check(v) && *tidb.BootstrapSQLConfigMapName != "" + klog.Info("tidb bootstrap sql enabled: ", ret) + return ret } func (tidb *TiDBSpec) IsTLSClientEnabled() bool { diff --git a/pkg/apis/pingcap/v1alpha1/types.go b/pkg/apis/pingcap/v1alpha1/types.go index 63bc97dd7f..ecdbd7f146 100644 --- a/pkg/apis/pingcap/v1alpha1/types.go +++ b/pkg/apis/pingcap/v1alpha1/types.go @@ -910,10 +910,10 @@ type TiDBSpec struct { // BootstrapSQLConfigMapName is the name of the ConfigMap which contains the bootstrap SQL file with the key `bootstrap-sql`, // which will only be executed when a TiDB cluster bootstrap on the first time. + // The field should be set ONLY when create a TC, since it only take effect on the first time bootstrap. // Only v6.6.0+ supports this feature. - // +immutable // +optional - BootstrapSQLConfigMapName *string `json:"bootstrapSQLFile,omitempty"` + BootstrapSQLConfigMapName *string `json:"bootstrapSQLConfigMapName,omitempty"` } type TiDBInitializer struct { diff --git a/pkg/util/util.go b/pkg/util/util.go index 49560cd8da..39e765fb7b 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -205,10 +205,6 @@ func TiDBAuthTokenJWKSSecretName(tcName string) string { return fmt.Sprintf("%s-tidb-auth-token-jwks-secret", tcName) } -func TiDBBootstrapSQLConfigMapName(tcName string) string { - return fmt.Sprintf("%s-tidb-bootstrap-sql", tcName) -} - // SortEnvByName implements sort.Interface to sort env list by name. type SortEnvByName []corev1.EnvVar From 583dd572f7e7b0f8c60153e504c9e54142fa26f6 Mon Sep 17 00:00:00 2001 From: fgksgf Date: Wed, 8 Feb 2023 16:28:45 +0800 Subject: [PATCH 4/7] fix ci --- pkg/apis/pingcap/v1alpha1/openapi_generated.go | 1 - pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go | 1 - 2 files changed, 2 deletions(-) diff --git a/pkg/apis/pingcap/v1alpha1/openapi_generated.go b/pkg/apis/pingcap/v1alpha1/openapi_generated.go index 28eaaf0ae9..1c4012a025 100644 --- a/pkg/apis/pingcap/v1alpha1/openapi_generated.go +++ b/pkg/apis/pingcap/v1alpha1/openapi_generated.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated // Copyright PingCAP, Inc. diff --git a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go index 2f7268f271..1b42259a81 100644 --- a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated // Copyright PingCAP, Inc. From e2e22645ac1d44e575db720996664d54a87b8d7e Mon Sep 17 00:00:00 2001 From: fgksgf Date: Wed, 8 Feb 2023 17:06:40 +0800 Subject: [PATCH 5/7] address review comments --- pkg/apis/pingcap/v1alpha1/tidbcluster.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pkg/apis/pingcap/v1alpha1/tidbcluster.go b/pkg/apis/pingcap/v1alpha1/tidbcluster.go index eba141e4db..eb5f857ec2 100644 --- a/pkg/apis/pingcap/v1alpha1/tidbcluster.go +++ b/pkg/apis/pingcap/v1alpha1/tidbcluster.go @@ -19,7 +19,6 @@ import ( "strings" "time" - "github.com/Masterminds/semver" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/types" @@ -56,10 +55,6 @@ var ( ResourceRequirements: corev1.ResourceRequirements{}, } defaultHelperSpec = HelperSpec{} - - // The first version that supports `-initialize-sql-file` option for first bootstrap is v6.6.0 - // https://github.com/pingcap/tidb/pull/35625 - tidbEqualOrGreaterThanV660, _ = semver.NewConstraint(">= v6.6.0-0") ) // PDImage return the image used by PD. @@ -955,19 +950,12 @@ func (tc *TidbCluster) IsTiDBBinlogEnabled() bool { } func (tidb *TiDBSpec) IsBootstrapSQLEnabled() bool { - if tidb.Version == nil || tidb.BootstrapSQLConfigMapName == nil { - return false - } - - v, err := semver.NewVersion(*tidb.Version) - if err != nil { - klog.Errorf("parse tidb version %s failed, err: %v", *tidb.Version, err) - return false + if tidb.BootstrapSQLConfigMapName != nil && *tidb.BootstrapSQLConfigMapName != "" { + klog.Info("tidb bootstrap sql is enabled") + return true } - ret := tidbEqualOrGreaterThanV660.Check(v) && *tidb.BootstrapSQLConfigMapName != "" - klog.Info("tidb bootstrap sql enabled: ", ret) - return ret + return false } func (tidb *TiDBSpec) IsTLSClientEnabled() bool { From 959177f56e65138a9a0e735f7e7fbc8622679da3 Mon Sep 17 00:00:00 2001 From: fgksgf Date: Mon, 13 Feb 2023 12:54:35 +0800 Subject: [PATCH 6/7] address review comments --- pkg/apis/pingcap/v1alpha1/tidbcluster.go | 1 - pkg/apis/pingcap/v1alpha1/validation/validation.go | 4 +++- .../pingcap/v1alpha1/validation/validation_test.go | 2 +- pkg/manager/member/constants/constants.go | 3 --- pkg/manager/member/startscript/v1/render_script.go | 11 +++-------- pkg/manager/member/startscript/v1/template.go | 14 ++++---------- .../member/startscript/v2/tidb_start_script.go | 5 ----- pkg/manager/member/tidb_member_manager.go | 10 ++++++++-- 8 files changed, 19 insertions(+), 31 deletions(-) diff --git a/pkg/apis/pingcap/v1alpha1/tidbcluster.go b/pkg/apis/pingcap/v1alpha1/tidbcluster.go index eb5f857ec2..feceda7580 100644 --- a/pkg/apis/pingcap/v1alpha1/tidbcluster.go +++ b/pkg/apis/pingcap/v1alpha1/tidbcluster.go @@ -951,7 +951,6 @@ func (tc *TidbCluster) IsTiDBBinlogEnabled() bool { func (tidb *TiDBSpec) IsBootstrapSQLEnabled() bool { if tidb.BootstrapSQLConfigMapName != nil && *tidb.BootstrapSQLConfigMapName != "" { - klog.Info("tidb bootstrap sql is enabled") return true } diff --git a/pkg/apis/pingcap/v1alpha1/validation/validation.go b/pkg/apis/pingcap/v1alpha1/validation/validation.go index e7094b8b70..59d55432af 100644 --- a/pkg/apis/pingcap/v1alpha1/validation/validation.go +++ b/pkg/apis/pingcap/v1alpha1/validation/validation.go @@ -644,6 +644,8 @@ func validateUpdatePDConfig(oldPdSpec, pdSpec *v1alpha1.PDSpec, path *field.Path return allErrs } +// disallowMutateBootstrapSQLConfigMapName checks if user mutate the bootstrapSQLConfigMapName field. +// Only allow to update bootstrapSQLConfigMapName from non-nil to nil. func disallowMutateBootstrapSQLConfigMapName(old, new *v1alpha1.TiDBSpec, p *field.Path) field.ErrorList { allErrs := field.ErrorList{} if old == nil || new == nil { @@ -652,7 +654,7 @@ func disallowMutateBootstrapSQLConfigMapName(old, new *v1alpha1.TiDBSpec, p *fie bootstrapSQLSpecified := old.BootstrapSQLConfigMapName != nil && new.BootstrapSQLConfigMapName != nil if (bootstrapSQLSpecified && *old.BootstrapSQLConfigMapName != *new.BootstrapSQLConfigMapName) || - !bootstrapSQLSpecified && old.BootstrapSQLConfigMapName != new.BootstrapSQLConfigMapName { + (!bootstrapSQLSpecified && new.BootstrapSQLConfigMapName != nil) { return append(allErrs, field.Invalid(p, new.BootstrapSQLConfigMapName, "bootstrapSQLConfigMapName is immutable")) } diff --git a/pkg/apis/pingcap/v1alpha1/validation/validation_test.go b/pkg/apis/pingcap/v1alpha1/validation/validation_test.go index 5de9f822eb..318a0ada5c 100644 --- a/pkg/apis/pingcap/v1alpha1/validation/validation_test.go +++ b/pkg/apis/pingcap/v1alpha1/validation/validation_test.go @@ -786,7 +786,7 @@ func Test_disallowMutateBootstrapSQLConfigMapName(t *testing.T) { new: &v1alpha1.TiDBSpec{ BootstrapSQLConfigMapName: nil, }, - wantError: true, + wantError: false, }, { name: "mutate from nil to non-nil", diff --git a/pkg/manager/member/constants/constants.go b/pkg/manager/member/constants/constants.go index f602452f02..1df08d0d69 100644 --- a/pkg/manager/member/constants/constants.go +++ b/pkg/manager/member/constants/constants.go @@ -25,7 +25,4 @@ const ( // TiCDCCertPath is the path for ticdc cert in container TiCDCCertPath = "/var/lib/ticdc-tls" - - // BootstrapSQLFile is the path for bootstrap sql file. - BootstrapSQLFile = "/etc/tidb-bootstrap/bootstrap.sql" ) diff --git a/pkg/manager/member/startscript/v1/render_script.go b/pkg/manager/member/startscript/v1/render_script.go index 539f2aa690..1d3ae15e30 100644 --- a/pkg/manager/member/startscript/v1/render_script.go +++ b/pkg/manager/member/startscript/v1/render_script.go @@ -79,14 +79,9 @@ func RenderTiDBStartScript(tc *v1alpha1.TidbCluster) (string, error) { AcrossK8s: tc.AcrossK8s(), ClusterDomain: tc.Spec.ClusterDomain, }, - EnablePlugin: len(plugins) > 0, - PluginDirectory: "/plugins", - PluginList: strings.Join(plugins, ","), - EnableBootstrapSQL: false, - } - if tc.Spec.TiDB != nil { - model.EnableBootstrapSQL = tc.Spec.TiDB.IsBootstrapSQLEnabled() - model.BootstrapSQLFile = constants.BootstrapSQLFile + EnablePlugin: len(plugins) > 0, + PluginDirectory: "/plugins", + PluginList: strings.Join(plugins, ","), } model.Path = "${CLUSTER_NAME}-pd:2379" if tc.AcrossK8s() { diff --git a/pkg/manager/member/startscript/v1/template.go b/pkg/manager/member/startscript/v1/template.go index 4df0144ce0..2ae6defa56 100644 --- a/pkg/manager/member/startscript/v1/template.go +++ b/pkg/manager/member/startscript/v1/template.go @@ -97,10 +97,6 @@ fi ARGS="${ARGS} --plugin-dir {{ .PluginDirectory }} --plugin-load {{ .PluginList }} " {{- end }} -{{- if .EnableBootstrapSQL }} -ARGS="${ARGS} --initialize-sql-file={{ .BootstrapSQLFile }}" -{{- end }} - echo "start tidb-server ..." echo "/tidb-server ${ARGS}" exec /tidb-server ${ARGS} @@ -109,12 +105,10 @@ exec /tidb-server ${ARGS} type TidbStartScriptModel struct { CommonModel - EnablePlugin bool - PluginDirectory string - PluginList string - Path string - EnableBootstrapSQL bool - BootstrapSQLFile string + EnablePlugin bool + PluginDirectory string + PluginList string + Path string } // pdStartScriptTpl is the pd start script diff --git a/pkg/manager/member/startscript/v2/tidb_start_script.go b/pkg/manager/member/startscript/v2/tidb_start_script.go index 67426aba1e..b64c1ec13e 100644 --- a/pkg/manager/member/startscript/v2/tidb_start_script.go +++ b/pkg/manager/member/startscript/v2/tidb_start_script.go @@ -18,8 +18,6 @@ import ( "strings" "text/template" - "github.com/pingcap/tidb-operator/pkg/manager/member/constants" - "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1" "github.com/pingcap/tidb-operator/pkg/controller" ) @@ -60,9 +58,6 @@ func RenderTiDBStartScript(tc *v1alpha1.TidbCluster) (string, error) { if tc.IsTiDBBinlogEnabled() { extraArgs = append(extraArgs, "--enable-binlog=true") } - if tc.Spec.TiDB != nil && tc.Spec.TiDB.IsBootstrapSQLEnabled() { - extraArgs = append(extraArgs, fmt.Sprintf("--initialize-sql-file=%s", constants.BootstrapSQLFile)) - } if plugins := tc.Spec.TiDB.Plugins; len(plugins) > 0 { extraArgs = append(extraArgs, "--plugin-dir=/plugins") extraArgs = append(extraArgs, fmt.Sprintf("--plugin-load=%s", strings.Join(plugins, ","))) diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go index 6d98259357..d13affa643 100644 --- a/pkg/manager/member/tidb_member_manager.go +++ b/pkg/manager/member/tidb_member_manager.go @@ -73,6 +73,9 @@ const ( // tidb DC label Name tidbDCLabel = "zone" + + bootstrapSQLFilePath = "/etc/tidb-bootstrap" + bootstrapSQLFileName = "bootstrap.sql" ) var ( @@ -574,6 +577,9 @@ func getTiDBConfigMap(tc *v1alpha1.TidbCluster) (*corev1.ConfigMap, error) { config.Set("security.ssl-cert", path.Join(serverCertPath, corev1.TLSCertKey)) config.Set("security.ssl-key", path.Join(serverCertPath, corev1.TLSPrivateKeyKey)) } + if tc.Spec.TiDB.IsBootstrapSQLEnabled() { + config.Set("initialize-sql-file", path.Join(bootstrapSQLFilePath, bootstrapSQLFileName)) + } confText, err := config.MarshalTOML() if err != nil { return nil, err @@ -764,7 +770,7 @@ func getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap) } if tc.Spec.TiDB != nil && tc.Spec.TiDB.IsBootstrapSQLEnabled() { volMounts = append(volMounts, corev1.VolumeMount{ - Name: "tidb-bootstrap-sql", ReadOnly: true, MountPath: "/etc/tidb-bootstrap", + Name: "tidb-bootstrap-sql", ReadOnly: true, MountPath: bootstrapSQLFilePath, }) vols = append(vols, corev1.Volume{ @@ -773,7 +779,7 @@ func getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap) LocalObjectReference: corev1.LocalObjectReference{ Name: *tc.Spec.TiDB.BootstrapSQLConfigMapName, }, - Items: []corev1.KeyToPath{{Key: "bootstrap-sql", Path: "bootstrap.sql"}}, + Items: []corev1.KeyToPath{{Key: "bootstrap-sql", Path: bootstrapSQLFileName}}, }, }, }) From 46076849c12a710992ac3876108d5f9f9dd6cb4f Mon Sep 17 00:00:00 2001 From: fgksgf Date: Wed, 15 Feb 2023 15:01:58 +0800 Subject: [PATCH 7/7] turn up the timeout in e2e --- tests/e2e/tidbcluster/across-kubernetes.go | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/e2e/tidbcluster/across-kubernetes.go b/tests/e2e/tidbcluster/across-kubernetes.go index ca670331ab..fb9a1e0ed1 100644 --- a/tests/e2e/tidbcluster/across-kubernetes.go +++ b/tests/e2e/tidbcluster/across-kubernetes.go @@ -155,7 +155,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { MustCreateXK8sTCWithComponentsReady(genericCli, oa, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, false) ginkgo.By("Check deploy status of all clusters") - err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 3*time.Minute) + err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status") }) @@ -203,7 +203,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { framework.ExpectNoError(genericCli.Delete(context.TODO(), tc2), "failed to delete cluster 2") ginkgo.By("Check status of tc1") - err = oa.WaitForTidbClusterReady(tc1, 2*time.Minute, 30*time.Second) + err = oa.WaitForTidbClusterReady(tc1, 25*time.Minute, 30*time.Second) framework.ExpectNoError(err, "timeout to wait for tc1 to be healthy") // connectable test @@ -222,7 +222,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { MustCreateXK8sTCWithComponentsReady(genericCli, oa, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, false) ginkgo.By("Check status over all clusters") - err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 3*time.Minute) + err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status") }) @@ -243,7 +243,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { return nil }) framework.ExpectNoError(err, "failed to update cluster domain of cluster-1 %s/%s", tc1.Namespace, tc1.Name) - err = oa.WaitForTidbClusterReady(tc1, 30*time.Minute, 30*time.Second) + err = oa.WaitForTidbClusterReady(tc1, 25*time.Minute, 30*time.Second) framework.ExpectNoError(err, "failed to wait for cluster-1 ready: %s/%s", tc1.Namespace, tc1.Name) localHost, localPort, cancel, err := portforward.ForwardOnePort(fw, tc1.Namespace, fmt.Sprintf("svc/%s-pd", tc1.Name), 2379) @@ -276,7 +276,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { MustCreateXK8sTCWithComponentsReady(genericCli, oa, []*v1alpha1.TidbCluster{tc2, tc3}, false) ginkgo.By("Deploy status of all clusters") - err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 3*time.Minute) + err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status") }) @@ -317,7 +317,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { framework.ExpectEqual(foundSecretName, true) ginkgo.By("Check deploy status over all clusters") - err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 3*time.Minute) + err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status") ginkgo.By("Connecting to tidb server to verify the connection is TLS enabled") @@ -340,7 +340,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { MustCreateXK8sTCWithComponentsReady(genericCli, oa, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, false) ginkgo.By("Check deploy status of all clusters") - err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 3*time.Minute) + err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status") }) @@ -417,7 +417,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { MustCreateXK8sTCWithComponentsReady(genericCli, oa, []*v1alpha1.TidbCluster{tc1, tc2}, false) ginkgo.By("Check deploy status of all clusters") - err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 3*time.Minute) + err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status") }) @@ -439,7 +439,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { MustCreateXK8sTCWithComponentsReady(genericCli, oa, []*v1alpha1.TidbCluster{tc1, tc2}, true) ginkgo.By("Check deploy status of all clusters") - err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 3*time.Minute) + err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status") }) } @@ -581,11 +581,11 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { framework.ExpectNoError(err, "waiting namespsace %q to be deleted", ns2) ginkgo.By("Check status of other clusters") - err = oa.WaitForTidbClusterReady(tc1, 10*time.Minute, 30*time.Second) + err = oa.WaitForTidbClusterReady(tc1, 25*time.Minute, 30*time.Second) framework.ExpectNoError(err, "%q cluster not healthy after cluster %q fail", tcName1, tcName2) - err = oa.WaitForTidbClusterReady(tc3, 10*time.Minute, 30*time.Second) + err = oa.WaitForTidbClusterReady(tc3, 25*time.Minute, 30*time.Second) framework.ExpectNoError(err, "%q cluster not healthy after cluster %q fail", tcName3, tcName2) - err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc3}, 5*time.Second, 3*time.Minute) + err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc3}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status after cluster %q fail", tcName2) ginkgo.By("Check functionality of other clusters by querying tidb") @@ -634,7 +634,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { tc2.Spec.TLSCluster = &v1alpha1.TLSCluster{Enabled: true} err = genericCli.Create(context.TODO(), tc2) framework.ExpectNoError(err, "create TidbCluster %q", tc2.Name) - err = oa.WaitForTidbClusterReady(tc2, 5*time.Minute, 10*time.Second) + err = oa.WaitForTidbClusterReady(tc2, 25*time.Minute, 10*time.Second) framework.ExpectError(err, "%q should not be able to join %q as pd fails", tcName2, tcName1) ginkgo.By("Recover PD in cluster-1") @@ -648,9 +648,9 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { framework.ExpectNoError(err, "deleting sts of pd for %q", tcName1) ginkgo.By("Join cluster-2 into cluster-1 when pd running normally") - err = oa.WaitForTidbClusterReady(tc2, 10*time.Minute, 30*time.Second) + err = oa.WaitForTidbClusterReady(tc2, 25*time.Minute, 30*time.Second) framework.ExpectNoError(err, "waiting for %q ready", tcName2) - err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 3*time.Minute) + err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "%q failed to join into %q", tcName2, tcName1) }) }) @@ -699,7 +699,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { MustCreateXK8sTCWithComponentsReady(genericCli, oa, []*v1alpha1.TidbCluster{tc1, tc2}, false) ginkgo.By("Check deploy status of all clusters") - err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 3*time.Minute) + err := CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2}, 5*time.Second, 10*time.Minute) framework.ExpectNoError(err, "failed to check status") }) @@ -730,7 +730,7 @@ var _ = ginkgo.Describe("[Across Kubernetes]", func() { utiltc.MustWaitForComponentPhase(cli, tc, v1alpha1.PDMemberType, v1alpha1.UpgradePhase, 3*time.Minute, time.Second*3) ginkgo.By("Wait for cluster is ready") - err = oa.WaitForTidbClusterReady(tc, 15*time.Minute, 10*time.Second) + err = oa.WaitForTidbClusterReady(tc, 25*time.Minute, 10*time.Second) framework.ExpectNoError(err, "failed to wait for TidbCluster %s/%s components ready", ns, tc.Name) ginkgo.By("Check status of components not changed") @@ -841,7 +841,7 @@ func MustCreateXK8sTCWithComponentsReady(cli ctrlCli.Client, oa *tests.OperatorA // for faster cluster creation, checking status after creating all clusters. for _, tc := range tidbclusters { - err := oa.WaitForTidbClusterReady(tc, 15*time.Minute, 10*time.Second) + err := oa.WaitForTidbClusterReady(tc, 25*time.Minute, 10*time.Second) framework.ExpectNoError(err, "failed to wait for TidbCluster %s/%s components ready", tc.Namespace, tc.Name) } }