From 4d2cfd44c722fc0b89463f769eb86f522b0235df Mon Sep 17 00:00:00 2001 From: xhe Date: Tue, 25 Jul 2023 13:53:32 +0800 Subject: [PATCH] fix: support min-ready-seconds for tiproxy Signed-off-by: xhe --- pkg/manager/member/tiproxy_upgrader.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/manager/member/tiproxy_upgrader.go b/pkg/manager/member/tiproxy_upgrader.go index eeb4fa3ab6d..571fe28f5c9 100644 --- a/pkg/manager/member/tiproxy_upgrader.go +++ b/pkg/manager/member/tiproxy_upgrader.go @@ -15,6 +15,7 @@ package member import ( "fmt" + "strconv" "github.com/pingcap/advanced-statefulset/client/apis/apps/v1/helper" "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1" @@ -22,10 +23,15 @@ import ( mngerutils "github.com/pingcap/tidb-operator/pkg/manager/utils" apps "k8s.io/api/apps/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" podutil "k8s.io/kubernetes/pkg/api/v1/pod" ) +const ( + annoKeyTiProxyMinReadySeconds = "tidb.pingcap.com/tidb-min-ready-seconds" +) + type tiproxyUpgrader struct { deps *controller.Dependencies } @@ -63,6 +69,17 @@ func (u *tiproxyUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Statefu return nil } + minReadySeconds := int(newSet.Spec.MinReadySeconds) + s, ok := tc.Annotations[annoKeyTiDBMinReadySeconds] + if ok { + i, err := strconv.Atoi(s) + if err != nil { + klog.Warningf("tidbcluster: [%s/%s] annotation %s should be an integer: %v", ns, tcName, annoKeyTiDBMinReadySeconds, err) + } else { + minReadySeconds = i + } + } + mngerutils.SetUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition) podOrdinals := helper.GetPodOrdinals(*oldSet.Spec.Replicas, oldSet).List() for _i := len(podOrdinals) - 1; _i >= 0; _i-- { @@ -79,7 +96,7 @@ func (u *tiproxyUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Statefu } if revision == tc.Status.TiProxy.StatefulSet.UpdateRevision { - if !podutil.IsPodReady(pod) { + if !podutil.IsPodAvailable(pod, int32(minReadySeconds), metav1.Now()) { return controller.RequeueErrorf("tidbcluster: [%s/%s]'s upgraded tiproxy pod: [%s] is not ready", ns, tcName, podName) } continue