diff --git a/docs/api-references/docs.md b/docs/api-references/docs.md index f1cad339202..e6275d3b2dc 100644 --- a/docs/api-references/docs.md +++ b/docs/api-references/docs.md @@ -9592,6 +9592,16 @@ MemberPhase
generation
+
+int64
+
+statefulSet
@@ -11174,6 +11184,16 @@ MemberPhase
generation
+
+int64
+
+statefulSet
@@ -12389,6 +12409,16 @@ MemberPhase
generation
+
+int64
+
+statefulSet
@@ -13812,6 +13842,16 @@ MemberPhase
generation
+
+int64
+
+statefulSet
@@ -16630,6 +16670,16 @@ MemberPhase
generation
+
+int64
+
+statefulSet
@@ -18012,6 +18062,16 @@ MemberPhase
generation
+
+int64
+
+statefulSet
@@ -22725,6 +22785,16 @@ MemberPhase
generation
+
+int64
+
+bootStrapped
bool
@@ -23738,6 +23808,16 @@ MemberPhase
generation
+
+int64
+
+members
@@ -27283,6 +27363,16 @@ MemberPhase
generation
+
+int64
+
+statefulSet
diff --git a/manifests/crd.yaml b/manifests/crd.yaml
index 4bad64b9564..e444bcf37f1 100644
--- a/manifests/crd.yaml
+++ b/manifests/crd.yaml
@@ -15440,6 +15440,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
leader:
@@ -15646,6 +15649,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
members:
@@ -44033,6 +44039,9 @@ spec:
type: object
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
leader:
@@ -44251,6 +44260,9 @@ spec:
type: object
nullable: true
type: array
+ generation:
+ format: int64
+ type: integer
image:
type: string
members:
@@ -44392,6 +44404,9 @@ spec:
type: object
nullable: true
type: array
+ generation:
+ format: int64
+ type: integer
members:
items:
properties:
@@ -44552,6 +44567,9 @@ spec:
type: object
nullable: true
type: array
+ generation:
+ format: int64
+ type: integer
phase:
type: string
statefulSet:
@@ -44695,6 +44713,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
members:
@@ -44875,6 +44896,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
peerStores:
@@ -45134,6 +45158,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
peerStores:
@@ -45357,6 +45384,9 @@ spec:
type: object
nullable: true
type: array
+ generation:
+ format: int64
+ type: integer
members:
additionalProperties:
properties:
diff --git a/manifests/crd/v1/pingcap.com_dmclusters.yaml b/manifests/crd/v1/pingcap.com_dmclusters.yaml
index 0982133f0d6..0216754b4bb 100644
--- a/manifests/crd/v1/pingcap.com_dmclusters.yaml
+++ b/manifests/crd/v1/pingcap.com_dmclusters.yaml
@@ -8591,6 +8591,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
leader:
@@ -8797,6 +8800,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
members:
diff --git a/manifests/crd/v1/pingcap.com_tidbclusters.yaml b/manifests/crd/v1/pingcap.com_tidbclusters.yaml
index adf7a3551c2..be1d0eac62f 100644
--- a/manifests/crd/v1/pingcap.com_tidbclusters.yaml
+++ b/manifests/crd/v1/pingcap.com_tidbclusters.yaml
@@ -24979,6 +24979,9 @@ spec:
type: object
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
leader:
@@ -25197,6 +25200,9 @@ spec:
type: object
nullable: true
type: array
+ generation:
+ format: int64
+ type: integer
image:
type: string
members:
@@ -25338,6 +25344,9 @@ spec:
type: object
nullable: true
type: array
+ generation:
+ format: int64
+ type: integer
members:
items:
properties:
@@ -25498,6 +25507,9 @@ spec:
type: object
nullable: true
type: array
+ generation:
+ format: int64
+ type: integer
phase:
type: string
statefulSet:
@@ -25641,6 +25653,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
members:
@@ -25821,6 +25836,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
peerStores:
@@ -26080,6 +26098,9 @@ spec:
type: string
type: object
type: object
+ generation:
+ format: int64
+ type: integer
image:
type: string
peerStores:
@@ -26303,6 +26324,9 @@ spec:
type: object
nullable: true
type: array
+ generation:
+ format: int64
+ type: integer
members:
additionalProperties:
properties:
diff --git a/pkg/apis/pingcap/v1alpha1/component_status.go b/pkg/apis/pingcap/v1alpha1/component_status.go
index 1d1cbc94923..f7190c77e81 100644
--- a/pkg/apis/pingcap/v1alpha1/component_status.go
+++ b/pkg/apis/pingcap/v1alpha1/component_status.go
@@ -58,6 +58,8 @@ type ComponentStatus interface {
//
// Not supported for tidb and pump
SetSynced(bool)
+ // SetGeneration sets the generation of the component.
+ SetGeneration(generation int64)
// SetPhase sets the phase of the component.
SetPhase(phase MemberPhase)
// SetVolumes sets the `status.volumes`
@@ -173,6 +175,9 @@ func (s *PDStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *PDStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *PDStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -223,6 +228,9 @@ func (s *PDMSStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *PDMSStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *PDMSStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -271,6 +279,9 @@ func (s *TiKVStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *TiKVStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *TiKVStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -322,6 +333,9 @@ func (s *TiDBStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *TiDBStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *TiDBStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -373,6 +387,9 @@ func (s *PumpStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *PumpStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *PumpStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -424,6 +441,9 @@ func (s *TiFlashStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *TiFlashStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *TiFlashStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -475,6 +495,9 @@ func (s *TiCDCStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *TiCDCStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *TiCDCStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -526,6 +549,9 @@ func (s *MasterStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *MasterStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *MasterStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -577,6 +603,9 @@ func (s *WorkerStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *WorkerStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *WorkerStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
@@ -628,6 +657,9 @@ func (s *TiProxyStatus) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&conditions, conditionType)
s.Conditions = conditions
}
+func (s *TiProxyStatus) SetGeneration(generation int64) {
+ s.Generation = generation
+}
func (s *TiProxyStatus) SetPhase(phase MemberPhase) {
s.Phase = phase
}
diff --git a/pkg/apis/pingcap/v1alpha1/types.go b/pkg/apis/pingcap/v1alpha1/types.go
index f4063a56015..d2e5bbbf900 100644
--- a/pkg/apis/pingcap/v1alpha1/types.go
+++ b/pkg/apis/pingcap/v1alpha1/types.go
@@ -1472,6 +1472,7 @@ type PDStatus struct {
// +optional
Synced bool `json:"synced"`
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
// Members contains PDs in current TidbCluster
Members map[string]PDMember `json:"members,omitempty"`
@@ -1497,6 +1498,7 @@ type PDMSStatus struct {
// +optional
Synced bool `json:"synced"`
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
// Volumes contains the status of all volumes.
Volumes map[StorageVolumeName]*StorageVolumeStatus `json:"volumes,omitempty"`
@@ -1551,6 +1553,7 @@ type UnjoinedMember struct {
// TiDBStatus is TiDB status
type TiDBStatus struct {
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Members map[string]TiDBMember `json:"members,omitempty"`
FailureMembers map[string]TiDBFailureMember `json:"failureMembers,omitempty"`
@@ -1656,6 +1659,7 @@ const (
type TiKVStatus struct {
Synced bool `json:"synced,omitempty"`
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
BootStrapped bool `json:"bootStrapped,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Stores map[string]TiKVStore `json:"stores,omitempty"` // key: store id
@@ -1679,6 +1683,7 @@ type TiKVStatus struct {
type TiFlashStatus struct {
Synced bool `json:"synced,omitempty"`
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Stores map[string]TiKVStore `json:"stores,omitempty"`
PeerStores map[string]TiKVStore `json:"peerStores,omitempty"`
@@ -1711,6 +1716,7 @@ type TiProxyMember struct {
type TiProxyStatus struct {
Synced bool `json:"synced,omitempty"`
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
Members map[string]TiProxyMember `json:"members,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Volumes map[StorageVolumeName]*StorageVolumeStatus `json:"volumes,omitempty"`
@@ -1724,6 +1730,7 @@ type TiProxyStatus struct {
type TiCDCStatus struct {
Synced bool `json:"synced,omitempty"`
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Captures map[string]TiCDCCapture `json:"captures,omitempty"`
// Volumes contains the status of all volumes.
@@ -1789,6 +1796,7 @@ type PumpNodeStatus struct {
// PumpStatus is Pump status
type PumpStatus struct {
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Members []*PumpNodeStatus `json:"members,omitempty"`
// Volumes contains the status of all volumes.
@@ -3173,6 +3181,7 @@ const (
type MasterStatus struct {
Synced bool `json:"synced,omitempty"`
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Members map[string]MasterMember `json:"members,omitempty"`
Leader MasterMember `json:"leader,omitempty"`
@@ -3214,6 +3223,7 @@ type MasterFailureMember struct {
type WorkerStatus struct {
Synced bool `json:"synced,omitempty"`
Phase MemberPhase `json:"phase,omitempty"`
+ Generation int64 `json:"generation,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Members map[string]WorkerMember `json:"members,omitempty"`
FailureMembers map[string]WorkerFailureMember `json:"failureMembers,omitempty"`
diff --git a/pkg/manager/member/dm_master_member_manager.go b/pkg/manager/member/dm_master_member_manager.go
index d881deb45af..f92e364e8c0 100644
--- a/pkg/manager/member/dm_master_member_manager.go
+++ b/pkg/manager/member/dm_master_member_manager.go
@@ -212,6 +212,7 @@ func (m *masterMemberManager) syncMasterStatefulSetForDMCluster(dc *v1alpha1.DMC
// Force update takes precedence over scaling because force upgrade won't take effect when cluster gets stuck at scaling
if !dc.Status.Master.Synced && NeedForceUpgrade(dc.Annotations) {
+ dc.Status.Master.Generation = dc.Generation
dc.Status.Master.Phase = v1alpha1.UpgradePhase
mngerutils.SetUpgradePartition(newMasterSet, 0)
errSTS := mngerutils.UpdateStatefulSet(m.deps.StatefulSetControl, dc, newMasterSet, oldMasterSet)
@@ -292,6 +293,7 @@ func (m *masterMemberManager) syncDMClusterStatus(dc *v1alpha1.DMCluster, set *a
return err
}
+ dc.Status.Master.Generation = dc.Generation
// Scaling takes precedence over upgrading.
if dc.MasterStsDesiredReplicas() != *set.Spec.Replicas {
dc.Status.Master.Phase = v1alpha1.ScalePhase
diff --git a/pkg/manager/member/dm_master_upgrader.go b/pkg/manager/member/dm_master_upgrader.go
index 6be5544aa41..3270eef5b27 100644
--- a/pkg/manager/member/dm_master_upgrader.go
+++ b/pkg/manager/member/dm_master_upgrader.go
@@ -57,6 +57,7 @@ func (u *masterUpgrader) gracefulUpgrade(dc *v1alpha1.DMCluster, oldSet *apps.St
return nil
}
+ dc.Status.Master.Generation = dc.Generation
dc.Status.Master.Phase = v1alpha1.UpgradePhase
if !templateEqual(newSet, oldSet) {
return nil
@@ -136,6 +137,7 @@ func (u *fakeMasterUpgrader) Upgrade(dc *v1alpha1.DMCluster, _ *apps.StatefulSet
if !dc.Status.Master.Synced {
return fmt.Errorf("dmcluster: dm-master status sync failed,can not to be upgraded")
}
+ dc.Status.Master.Generation = dc.Generation
dc.Status.Master.Phase = v1alpha1.UpgradePhase
return nil
}
diff --git a/pkg/manager/member/dm_worker_member_manager.go b/pkg/manager/member/dm_worker_member_manager.go
index 221cc7ec329..aa133033612 100644
--- a/pkg/manager/member/dm_worker_member_manager.go
+++ b/pkg/manager/member/dm_worker_member_manager.go
@@ -250,6 +250,7 @@ func (m *workerMemberManager) syncDMClusterStatus(dc *v1alpha1.DMCluster, set *a
if err != nil {
return err
}
+ dc.Status.Worker.Generation = dc.Generation
if upgrading {
dc.Status.Worker.Phase = v1alpha1.UpgradePhase
} else if dc.WorkerStsDesiredReplicas() != *set.Spec.Replicas {
diff --git a/pkg/manager/member/pd_member_manager.go b/pkg/manager/member/pd_member_manager.go
index f4d14d9fe6f..ba1370fb0fb 100644
--- a/pkg/manager/member/pd_member_manager.go
+++ b/pkg/manager/member/pd_member_manager.go
@@ -233,6 +233,7 @@ func (m *pdMemberManager) syncPDStatefulSetForTidbCluster(tc *v1alpha1.TidbClust
onlyOnePD := *oldPDSet.Spec.Replicas < 2 && len(tc.Status.PD.PeerMembers) == 0 // it's acceptable to use old record about peer members
if forceUpgradeAnnoSet || onlyOnePD {
+ tc.Status.PD.Generation = tc.Generation
tc.Status.PD.Phase = v1alpha1.UpgradePhase
mngerutils.SetUpgradePartition(newPDSet, 0)
errSTS := mngerutils.UpdateStatefulSet(m.deps.StatefulSetControl, tc, newPDSet, oldPDSet)
@@ -330,6 +331,8 @@ func (m *pdMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, set *a
return err
}
+ tc.Status.PD.Generation = tc.Generation
+
// Scaling takes precedence over upgrading.
if tc.PDStsDesiredReplicas() != *set.Spec.Replicas {
tc.Status.PD.Phase = v1alpha1.ScalePhase
diff --git a/pkg/manager/member/pd_member_manager_test.go b/pkg/manager/member/pd_member_manager_test.go
index 149b1b92d49..a05c04a1d09 100644
--- a/pkg/manager/member/pd_member_manager_test.go
+++ b/pkg/manager/member/pd_member_manager_test.go
@@ -949,9 +949,10 @@ func newTidbClusterForPD() *v1alpha1.TidbCluster {
APIVersion: "pingcap.com/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
- Name: "test",
- Namespace: corev1.NamespaceDefault,
- UID: types.UID("test"),
+ Name: "test",
+ Namespace: corev1.NamespaceDefault,
+ UID: types.UID("test"),
+ Generation: 10,
},
Spec: v1alpha1.TidbClusterSpec{
PD: &v1alpha1.PDSpec{
diff --git a/pkg/manager/member/pd_ms_member_manager.go b/pkg/manager/member/pd_ms_member_manager.go
index 7ad6189cbdb..4ac1f23d523 100644
--- a/pkg/manager/member/pd_ms_member_manager.go
+++ b/pkg/manager/member/pd_ms_member_manager.go
@@ -345,6 +345,8 @@ func (m *pdMSMemberManager) syncStatus(tc *v1alpha1.TidbCluster, sts *apps.State
return err
}
+ tc.Status.PDMS[curService].Generation = tc.Generation
+
// Scaling takes precedence over upgrading.
if tc.PDMSStsDesiredReplicas(curService) != *sts.Spec.Replicas {
tc.Status.PDMS[curService].Phase = v1alpha1.ScalePhase
diff --git a/pkg/manager/member/pd_upgrader.go b/pkg/manager/member/pd_upgrader.go
index a7327f25053..f92781204f1 100644
--- a/pkg/manager/member/pd_upgrader.go
+++ b/pkg/manager/member/pd_upgrader.go
@@ -64,6 +64,7 @@ func (u *pdUpgrader) gracefulUpgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Stat
return nil
}
+ tc.Status.PD.Generation = tc.Generation
tc.Status.PD.Phase = v1alpha1.UpgradePhase
if !templateEqual(newSet, oldSet) {
return nil
@@ -234,6 +235,7 @@ func (u *fakePDUpgrader) Upgrade(tc *v1alpha1.TidbCluster, _ *apps.StatefulSet,
if !tc.Status.PD.Synced {
return fmt.Errorf("tidbcluster: pd status sync failed, can not to be upgraded")
}
+ tc.Status.PD.Generation = tc.Generation
tc.Status.PD.Phase = v1alpha1.UpgradePhase
return nil
}
diff --git a/pkg/manager/member/pump_member_manager.go b/pkg/manager/member/pump_member_manager.go
index abe686afc03..60b266a5301 100644
--- a/pkg/manager/member/pump_member_manager.go
+++ b/pkg/manager/member/pump_member_manager.go
@@ -200,6 +200,7 @@ func (m *pumpMemberManager) syncTiDBClusterStatus(tc *v1alpha1.TidbCluster, set
return err
}
+ tc.Status.Pump.Generation = tc.Generation
if upgrading {
tc.Status.Pump.Phase = v1alpha1.UpgradePhase
} else {
diff --git a/pkg/manager/member/ticdc_member_manager.go b/pkg/manager/member/ticdc_member_manager.go
index 3c29259fedf..8a7e8226262 100644
--- a/pkg/manager/member/ticdc_member_manager.go
+++ b/pkg/manager/member/ticdc_member_manager.go
@@ -242,6 +242,7 @@ func (m *ticdcMemberManager) syncTiCDCStatus(tc *v1alpha1.TidbCluster, sts *apps
tc.Status.TiCDC.Synced = false
return err
}
+ tc.Status.TiCDC.Generation = tc.Generation
if upgrading {
tc.Status.TiCDC.Phase = v1alpha1.UpgradePhase
} else {
diff --git a/pkg/manager/member/ticdc_upgrader.go b/pkg/manager/member/ticdc_upgrader.go
index 3515792568c..1a6d942ed64 100644
--- a/pkg/manager/member/ticdc_upgrader.go
+++ b/pkg/manager/member/ticdc_upgrader.go
@@ -66,6 +66,7 @@ func (u *ticdcUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.StatefulS
return nil
}
+ tc.Status.TiCDC.Generation = tc.Generation
tc.Status.TiCDC.Phase = v1alpha1.UpgradePhase
if !templateEqual(newSet, oldSet) {
return nil
diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go
index 5780fc78e4b..5a189f52a2c 100644
--- a/pkg/manager/member/tidb_member_manager.go
+++ b/pkg/manager/member/tidb_member_manager.go
@@ -1147,6 +1147,8 @@ func (m *tidbMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, set
return err
}
+ tc.Status.TiDB.Generation = tc.Generation
+
if tc.TiDBStsDesiredReplicas() != *set.Spec.Replicas {
tc.Status.TiDB.Phase = v1alpha1.ScalePhase
} else if upgrading && tc.Status.TiKV.Phase != v1alpha1.UpgradePhase &&
diff --git a/pkg/manager/member/tidb_member_manager_test.go b/pkg/manager/member/tidb_member_manager_test.go
index 316071bc2ee..566c6cdb41c 100644
--- a/pkg/manager/member/tidb_member_manager_test.go
+++ b/pkg/manager/member/tidb_member_manager_test.go
@@ -404,6 +404,7 @@ func TestTiDBMemberManagerSyncTidbClusterStatus(t *testing.T) {
}
if test.updateSts != nil {
test.updateSts(set)
+ tc.Generation = tc.Generation + 1
}
pmm, _, tidbControl, _ := newFakeTiDBMemberManager()
@@ -449,6 +450,7 @@ func TestTiDBMemberManagerSyncTidbClusterStatus(t *testing.T) {
tcExpectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) {
g.Expect(tc.Status.TiDB.StatefulSet.Replicas).To(Equal(int32(3)))
g.Expect(tc.Status.TiDB.Phase).To(Equal(v1alpha1.UpgradePhase))
+ g.Expect(tc.Status.TiDB.Generation).To(Equal(tc.Generation))
},
},
{
@@ -464,6 +466,7 @@ func TestTiDBMemberManagerSyncTidbClusterStatus(t *testing.T) {
tcExpectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) {
g.Expect(tc.Status.TiDB.StatefulSet.Replicas).To(Equal(int32(3)))
g.Expect(tc.Status.TiDB.Phase).To(Equal(v1alpha1.NormalPhase))
+ g.Expect(tc.Status.TiDB.Generation).To(Equal(tc.Generation))
},
},
{
@@ -479,6 +482,7 @@ func TestTiDBMemberManagerSyncTidbClusterStatus(t *testing.T) {
tcExpectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) {
g.Expect(tc.Status.TiDB.StatefulSet.Replicas).To(Equal(int32(3)))
g.Expect(tc.Status.TiDB.Phase).To(Equal(v1alpha1.NormalPhase))
+ g.Expect(tc.Status.TiDB.Generation).To(Equal(tc.Generation))
},
},
{
@@ -492,6 +496,7 @@ func TestTiDBMemberManagerSyncTidbClusterStatus(t *testing.T) {
tcExpectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) {
g.Expect(tc.Status.TiDB.StatefulSet.Replicas).To(Equal(int32(3)))
g.Expect(tc.Status.TiDB.Phase).To(Equal(v1alpha1.NormalPhase))
+ g.Expect(tc.Status.TiDB.Generation).To(Equal(tc.Generation))
},
},
{
diff --git a/pkg/manager/member/tidb_upgrader.go b/pkg/manager/member/tidb_upgrader.go
index 685b6f3cb4a..04682091a17 100644
--- a/pkg/manager/member/tidb_upgrader.go
+++ b/pkg/manager/member/tidb_upgrader.go
@@ -75,6 +75,7 @@ func (u *tidbUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.StatefulSe
return nil
}
+ tc.Status.TiDB.Generation = tc.Generation
tc.Status.TiDB.Phase = v1alpha1.UpgradePhase
if !templateEqual(newSet, oldSet) {
return nil
@@ -148,6 +149,7 @@ func NewFakeTiDBUpgrader() Upgrader {
}
func (u *fakeTiDBUpgrader) Upgrade(tc *v1alpha1.TidbCluster, _ *apps.StatefulSet, _ *apps.StatefulSet) error {
+ tc.Status.TiDB.Generation = tc.Generation
tc.Status.TiDB.Phase = v1alpha1.UpgradePhase
return nil
}
diff --git a/pkg/manager/member/tiflash_member_manager.go b/pkg/manager/member/tiflash_member_manager.go
index c9bcf5451bd..6a6bd122561 100644
--- a/pkg/manager/member/tiflash_member_manager.go
+++ b/pkg/manager/member/tiflash_member_manager.go
@@ -743,6 +743,7 @@ func (m *tiflashMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, s
if err != nil {
return err
}
+ tc.Status.TiFlash.Generation = tc.Generation
if tc.TiFlashStsDesiredReplicas() != *set.Spec.Replicas {
tc.Status.TiFlash.Phase = v1alpha1.ScalePhase
} else if upgrading {
diff --git a/pkg/manager/member/tiflash_upgrader.go b/pkg/manager/member/tiflash_upgrader.go
index 2799be82629..bedfc388a25 100644
--- a/pkg/manager/member/tiflash_upgrader.go
+++ b/pkg/manager/member/tiflash_upgrader.go
@@ -75,6 +75,7 @@ func (u *tiflashUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Statefu
return fmt.Errorf("cluster: [%s/%s]'s TiFlash status is not synced, can not upgrade", ns, tcName)
}
+ tc.Status.TiFlash.Generation = tc.Generation
tc.Status.TiFlash.Phase = v1alpha1.UpgradePhase
if !templateEqual(newSet, oldSet) {
return nil
diff --git a/pkg/manager/member/tikv_member_manager.go b/pkg/manager/member/tikv_member_manager.go
index 5da033d984b..e3251db4929 100644
--- a/pkg/manager/member/tikv_member_manager.go
+++ b/pkg/manager/member/tikv_member_manager.go
@@ -834,6 +834,8 @@ func (m *tikvMemberManager) syncTiKVClusterStatus(tc *v1alpha1.TidbCluster, set
}
}
+ tc.Status.TiKV.Generation = tc.Generation
+
// Scaling takes precedence over upgrading.
if tc.TiKVStsDesiredReplicas() != *set.Spec.Replicas {
tc.Status.TiKV.Phase = v1alpha1.ScalePhase
diff --git a/pkg/manager/member/tikv_upgrader.go b/pkg/manager/member/tikv_upgrader.go
index bf2fe58538f..37e2b180ed7 100644
--- a/pkg/manager/member/tikv_upgrader.go
+++ b/pkg/manager/member/tikv_upgrader.go
@@ -91,6 +91,7 @@ func (u *tikvUpgrader) Upgrade(meta metav1.Object, oldSet *apps.StatefulSet, new
// NOTE: If `TiKVStatus.Synced`` is false, it's acceptable to use old record about peer stores
if *oldSet.Spec.Replicas < 2 && len(tc.Status.TiKV.PeerStores) == 0 {
klog.Infof("TiKV statefulset replicas are less than 2, skip evicting region leader for tc %s/%s", ns, tcName)
+ status.Generation = tc.Generation
status.Phase = v1alpha1.UpgradePhase
mngerutils.SetUpgradePartition(newSet, 0)
return nil
@@ -100,6 +101,7 @@ func (u *tikvUpgrader) Upgrade(meta metav1.Object, oldSet *apps.StatefulSet, new
return fmt.Errorf("cluster: [%s/%s]'s tikv status sync failed, can not to be upgraded", ns, tcName)
}
+ status.Generation = tc.Generation
status.Phase = v1alpha1.UpgradePhase
if !templateEqual(newSet, oldSet) {
return nil
@@ -575,6 +577,7 @@ func NewFakeTiKVUpgrader() TiKVUpgrader {
func (u *fakeTiKVUpgrader) Upgrade(meta metav1.Object, _ *apps.StatefulSet, _ *apps.StatefulSet) error {
tc := meta.(*v1alpha1.TidbCluster)
+ tc.Status.TiKV.Generation = tc.Generation
tc.Status.TiKV.Phase = v1alpha1.UpgradePhase
return nil
}
diff --git a/pkg/manager/member/tiproxy_member_manager.go b/pkg/manager/member/tiproxy_member_manager.go
index 44ae5788154..f33ef44bc9a 100644
--- a/pkg/manager/member/tiproxy_member_manager.go
+++ b/pkg/manager/member/tiproxy_member_manager.go
@@ -288,6 +288,7 @@ func (m *tiproxyMemberManager) syncStatus(tc *v1alpha1.TidbCluster, sts *apps.St
tc.Status.TiProxy.Synced = false
return err
}
+ tc.Status.TiProxy.Generation = tc.Generation
if tc.Spec.TiProxy.Replicas != *sts.Spec.Replicas {
tc.Status.TiProxy.Phase = v1alpha1.ScalePhase
} else if upgrading {
diff --git a/pkg/manager/member/tiproxy_upgrader.go b/pkg/manager/member/tiproxy_upgrader.go
index 85a3322e125..af82a1102df 100644
--- a/pkg/manager/member/tiproxy_upgrader.go
+++ b/pkg/manager/member/tiproxy_upgrader.go
@@ -60,6 +60,7 @@ func (u *tiproxyUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Statefu
return nil
}
+ tc.Status.TiProxy.Generation = tc.Generation
tc.Status.TiProxy.Phase = v1alpha1.UpgradePhase
if !templateEqual(newSet, oldSet) {
return nil
diff --git a/pkg/manager/suspender/suspender.go b/pkg/manager/suspender/suspender.go
index 045928d874e..3697e738b2d 100644
--- a/pkg/manager/suspender/suspender.go
+++ b/pkg/manager/suspender/suspender.go
@@ -194,6 +194,7 @@ func (s *suspender) begin(ctx *suspendComponentCtx) error {
phase := v1alpha1.SuspendPhase
klog.Infof("begin to suspend component %s and transfer phase from %s to %s",
ctx.ComponentID(), status.GetPhase(), phase)
+ ctx.status.SetGeneration(ctx.cluster.GetGeneration())
ctx.status.SetPhase(phase)
return nil
}
@@ -203,6 +204,7 @@ func (s *suspender) end(ctx *suspendComponentCtx) error {
phase := v1alpha1.NormalPhase
klog.Infof("end to suspend component %s and transfer phase from %s to %s",
ctx.ComponentID(), status.GetPhase(), phase)
+ ctx.status.SetGeneration(ctx.cluster.GetGeneration())
ctx.status.SetPhase(phase)
return nil
}