Skip to content

Commit b618aba

Browse files
authored
Fix: update status when deleting and wait for modifying volumes (#6164)
1 parent 655bb03 commit b618aba

File tree

32 files changed

+577
-165
lines changed

32 files changed

+577
-165
lines changed

api/core/v1alpha1/common_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ type CommonStatus struct {
301301
CollisionCount *int32 `json:"collisionCount,omitempty"`
302302
}
303303

304+
// StoreStatus defines the common status fields for all stores.
305+
type StoreStatus struct {
306+
// ID is the store id.
307+
ID string `json:"id,omitempty"`
308+
309+
// State is the store state.
310+
State string `json:"state,omitempty"`
311+
}
312+
304313
// GroupStatus defines the common status fields for all component groups.
305314
type GroupStatus struct {
306315
// Version is the version of all instances in the group.

api/core/v1alpha1/tiflash_types.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,5 @@ type TiFlashSpec struct {
198198

199199
type TiFlashStatus struct {
200200
CommonStatus `json:",inline"`
201-
202-
// Store ID
203-
ID string `json:"id,omitempty"`
204-
205-
// Store State
206-
State string `json:"state,omitempty"`
201+
StoreStatus `json:",inline"`
207202
}

api/core/v1alpha1/tikv_types.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,5 @@ type TiKVSpec struct {
203203

204204
type TiKVStatus struct {
205205
CommonStatus `json:",inline"`
206-
207-
// Store ID
208-
ID string `json:"id,omitempty"`
209-
210-
// Store State
211-
State string `json:"state,omitempty"`
206+
StoreStatus `json:",inline"`
212207
}

api/core/v1alpha1/zz_generated.deepcopy.go

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

manifests/crd/core.pingcap.com_tiflashes.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8447,7 +8447,7 @@ spec:
84478447
created the resource.
84488448
type: string
84498449
id:
8450-
description: Store ID
8450+
description: ID is the store id.
84518451
type: string
84528452
observedGeneration:
84538453
description: |-
@@ -8456,7 +8456,7 @@ spec:
84568456
format: int64
84578457
type: integer
84588458
state:
8459-
description: Store State
8459+
description: State is the store state.
84608460
type: string
84618461
updateRevision:
84628462
description: UpdateRevision is the revision of the Controller that

manifests/crd/core.pingcap.com_tikvs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8407,7 +8407,7 @@ spec:
84078407
created the resource.
84088408
type: string
84098409
id:
8410-
description: Store ID
8410+
description: ID is the store id.
84118411
type: string
84128412
observedGeneration:
84138413
description: |-
@@ -8416,7 +8416,7 @@ spec:
84168416
format: int64
84178417
type: integer
84188418
state:
8419-
description: Store State
8419+
description: State is the store state.
84208420
type: string
84218421
updateRevision:
84228422
description: UpdateRevision is the revision of the Controller that

manifests/tidb-operator.crds.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97425,7 +97425,7 @@ spec:
9742597425
created the resource.
9742697426
type: string
9742797427
id:
97428-
description: Store ID
97428+
description: ID is the store id.
9742997429
type: string
9743097430
observedGeneration:
9743197431
description: |-
@@ -97434,7 +97434,7 @@ spec:
9743497434
format: int64
9743597435
type: integer
9743697436
state:
97437-
description: Store State
97437+
description: State is the store state.
9743897438
type: string
9743997439
updateRevision:
9744097440
description: UpdateRevision is the revision of the Controller that
@@ -123347,7 +123347,7 @@ spec:
123347123347
created the resource.
123348123348
type: string
123349123349
id:
123350-
description: Store ID
123350+
description: ID is the store id.
123351123351
type: string
123352123352
observedGeneration:
123353123353
description: |-
@@ -123356,7 +123356,7 @@ spec:
123356123356
format: int64
123357123357
type: integer
123358123358
state:
123359-
description: Store State
123359+
description: State is the store state.
123360123360
type: string
123361123361
updateRevision:
123362123362
description: UpdateRevision is the revision of the Controller that

manifests/tidb-operator.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97425,7 +97425,7 @@ spec:
9742597425
created the resource.
9742697426
type: string
9742797427
id:
97428-
description: Store ID
97428+
description: ID is the store id.
9742997429
type: string
9743097430
observedGeneration:
9743197431
description: |-
@@ -97434,7 +97434,7 @@ spec:
9743497434
format: int64
9743597435
type: integer
9743697436
state:
97437-
description: Store State
97437+
description: State is the store state.
9743897438
type: string
9743997439
updateRevision:
9744097440
description: UpdateRevision is the revision of the Controller that
@@ -123347,7 +123347,7 @@ spec:
123347123347
created the resource.
123348123348
type: string
123349123349
id:
123350-
description: Store ID
123350+
description: ID is the store id.
123351123351
type: string
123352123352
observedGeneration:
123353123353
description: |-
@@ -123356,7 +123356,7 @@ spec:
123356123356
format: int64
123357123357
type: integer
123358123358
state:
123359-
description: Store State
123359+
description: State is the store state.
123360123360
type: string
123361123361
updateRevision:
123362123362
description: UpdateRevision is the revision of the Controller that

pkg/apiutil/core/v1alpha1/group.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/pingcap/tidb-operator/pkg/client"
2222
"github.com/pingcap/tidb-operator/pkg/runtime"
2323
"github.com/pingcap/tidb-operator/pkg/runtime/scope"
24+
"github.com/pingcap/tidb-operator/pkg/utils/compare"
2425
maputil "github.com/pingcap/tidb-operator/pkg/utils/map"
2526
)
2627

@@ -75,7 +76,7 @@ func SetStatusVersion[
7576
](f F) bool {
7677
obj := scope.From[S](f)
7778
v := obj.StatusVersion()
78-
if setIfChanged(&v, obj.Version()) {
79+
if compare.SetIfChanged(&v, obj.Version()) {
7980
obj.SetStatusVersion(v)
8081
return true
8182
}
@@ -90,10 +91,10 @@ func SetStatusReplicas[
9091
](f F, newReplicas, newReady, newUpdate, newCurrent int32) bool {
9192
obj := scope.From[S](f)
9293
replicas, ready, update, current := obj.StatusReplicas()
93-
changed := setIfChanged(&replicas, newReplicas)
94-
changed = setIfChanged(&ready, newReady) || changed
95-
changed = setIfChanged(&update, newUpdate) || changed
96-
changed = setIfChanged(&current, newCurrent) || changed
94+
changed := compare.SetIfChanged(&replicas, newReplicas)
95+
changed = compare.SetIfChanged(&ready, newReady) || changed
96+
changed = compare.SetIfChanged(&update, newUpdate) || changed
97+
changed = compare.SetIfChanged(&current, newCurrent) || changed
9798
if changed {
9899
obj.SetStatusReplicas(replicas, ready, update, current)
99100
return changed
@@ -109,9 +110,9 @@ func SetStatusRevision[
109110
](f F, newUpdate, newCurrent string, newCollisionCount int32) bool {
110111
obj := scope.From[S](f)
111112
update, current, collisionCount := obj.StatusRevision()
112-
changed := setIfChanged(&update, newUpdate)
113-
changed = setIfChanged(&current, newCurrent) || changed
114-
changed = newAndSetIfChanged(&collisionCount, newCollisionCount) || changed
113+
changed := compare.SetIfChanged(&update, newUpdate)
114+
changed = compare.SetIfChanged(&current, newCurrent) || changed
115+
changed = compare.NewAndSetIfChanged(&collisionCount, newCollisionCount) || changed
115116
if changed {
116117
obj.SetStatusRevision(update, current, collisionCount)
117118
return changed

pkg/apiutil/core/v1alpha1/object.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/pingcap/tidb-operator/pkg/client"
2323
"github.com/pingcap/tidb-operator/pkg/runtime"
2424
"github.com/pingcap/tidb-operator/pkg/runtime/scope"
25+
"github.com/pingcap/tidb-operator/pkg/utils/compare"
2526
)
2627

2728
func Cluster[
@@ -48,7 +49,7 @@ func SetStatusObservedGeneration[
4849
](f F) bool {
4950
t := scope.From[S](f)
5051
gen := t.ObservedGeneration()
51-
if setIfChanged(&gen, t.GetGeneration()) {
52+
if compare.SetIfChanged(&gen, t.GetGeneration()) {
5253
t.SetObservedGeneration(gen)
5354
return true
5455
}

0 commit comments

Comments
 (0)