Skip to content

Commit 1d348c4

Browse files
authored
fix(updater): ignore deleting instances in topology policy (#6538)
1 parent c0099a5 commit 1d348c4

27 files changed

Lines changed: 248 additions & 175 deletions

cmd/runtime-gen/generators/runtime.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ func (g *$.|pub$) MinReadySeconds() int64 {
586586
}
587587
return *g.Spec.MinReadySeconds
588588
}
589+
590+
func (g *$.|pub$) SchedulePolicies() []v1alpha1.SchedulePolicy {
591+
return g.Spec.SchedulePolicies
592+
}
589593
`, t)
590594

591595
return sw.Error()

pkg/apiutil/core/v1alpha1/group.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ func MinReadySeconds[
6767
return scope.From[S](f).MinReadySeconds()
6868
}
6969

70+
func SchedulePolicies[
71+
S scope.Group[F, T],
72+
F client.Object,
73+
T runtime.Group,
74+
](f F) []v1alpha1.SchedulePolicy {
75+
return scope.From[S](f).SchedulePolicies()
76+
}
77+
7078
// IsGroupHealthyAndUpToDate is defined to check whether all replicas of the group are healthy and up to date
7179
// TODO: simplify it by a condition
7280
func IsGroupHealthyAndUpToDate[

pkg/apiutil/core/v1alpha1/instance.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"time"
1919

2020
corev1 "k8s.io/api/core/v1"
21+
"k8s.io/apimachinery/pkg/api/meta"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223

2324
"github.com/pingcap/tidb-operator/api/v2/core/v1alpha1"
@@ -29,6 +30,14 @@ import (
2930
maputil "github.com/pingcap/tidb-operator/pkg/utils/map"
3031
)
3132

33+
func Topology[
34+
S scope.Instance[F, T],
35+
F client.Object,
36+
T runtime.Instance,
37+
](f F) v1alpha1.Topology {
38+
return scope.From[S](f).GetTopology()
39+
}
40+
3241
func IsReady[
3342
S scope.Instance[F, T],
3443
F client.Object,
@@ -335,3 +344,25 @@ func WithLegacyK8sAppLabels() PVCPatch {
335344
))
336345
})
337346
}
347+
348+
// IsDeleting check whether an instance is deleting
349+
// TODO: change to use scope
350+
func IsDeleting(instance runtime.Instance) bool {
351+
if !instance.GetDeletionTimestamp().IsZero() {
352+
return true
353+
}
354+
355+
if _, ok := instance.GetAnnotations()[v1alpha1.AnnoKeyDeferDelete]; ok {
356+
return true
357+
}
358+
359+
if instance.IsOffline() {
360+
return true
361+
}
362+
363+
if meta.IsStatusConditionTrue(instance.Conditions(), v1alpha1.StoreOfflinedConditionType) {
364+
return true
365+
}
366+
367+
return false
368+
}

pkg/runtime/group.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
package runtime
1616

17-
import "sigs.k8s.io/controller-runtime/pkg/client"
17+
import (
18+
"sigs.k8s.io/controller-runtime/pkg/client"
19+
20+
"github.com/pingcap/tidb-operator/api/v2/core/v1alpha1"
21+
)
1822

1923
type Group interface {
2024
Object
@@ -43,6 +47,8 @@ type Group interface {
4347
SetTemplateClusterTLS(ca, certKeyPair string)
4448

4549
MinReadySeconds() int64
50+
51+
SchedulePolicies() []v1alpha1.SchedulePolicy
4652
}
4753

4854
type GroupT[T GroupSet] interface {

pkg/runtime/zz_generated.runtime.pd.go

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

pkg/runtime/zz_generated.runtime.replicationworker.go

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

pkg/runtime/zz_generated.runtime.scheduler.go

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

pkg/runtime/zz_generated.runtime.scheduling.go

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

pkg/runtime/zz_generated.runtime.ticdc.go

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

pkg/runtime/zz_generated.runtime.tidb.go

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

0 commit comments

Comments
 (0)