Skip to content

Commit 70fe231

Browse files
authored
ms: use PDMSName as the transfer primary param (#6294)
1 parent 13709c5 commit 70fe231

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

pkg/controller/pd_control.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func NewFakePDClientForMember(pdControl *pdapi.FakePDControl, tc *v1alpha1.TidbC
133133

134134
// NewFakePDMSClient creates a fake pdmsclient that is set as the pdms client
135135
func NewFakePDMSClient(pdControl *pdapi.FakePDControl, tc *v1alpha1.TidbCluster, curService string) *pdapi.FakePDMSClient {
136-
pdmsClient := pdapi.NewFakePDMSClient()
136+
pdmsClient := pdapi.NewFakePDMSClient(tc.Spec.ClusterDomain)
137137
if tc.Spec.Cluster != nil {
138138
pdControl.SetPDMSClientWithClusterDomain(pdapi.Namespace(tc.Spec.Cluster.Namespace), tc.Spec.Cluster.Name, tc.Spec.Cluster.ClusterDomain, curService, pdmsClient)
139139
}

pkg/manager/member/pd_ms_upgrader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ func choosePDMSToTransferFromMembers(tc *v1alpha1.TidbCluster, newSet *apps.Stat
194194
// just using pods index for now. TODO: add healthy checker for pdms.
195195
// find the maximum ordinal which is larger than ordinal
196196
if len(list) > int(ordinal)+1 {
197-
targetName = PDMSPodName(tcName, list[len(list)-1], controller.PDMSTrimName(newSet.Name))
197+
targetName = PDMSName(tcName, list[len(list)-1], tc.Namespace, tc.Spec.ClusterDomain, tc.Spec.AcrossK8s, controller.PDMSTrimName(newSet.Name))
198198
}
199199

200200
if targetName == "" && ordinal != 0 {
201201
// find the minimum ordinal which is less than ordinal
202-
targetName = PDMSPodName(tcName, list[0], controller.PDMSTrimName(newSet.Name))
202+
targetName = PDMSName(tcName, list[0], tc.Namespace, tc.Spec.ClusterDomain, tc.Spec.AcrossK8s, controller.PDMSTrimName(newSet.Name))
203203
}
204204

205205
klog.Infof("Tidbcluster: [%s/%s]' pdms upgrader: choose pdms to transfer primary from members, targetName: %s", ns, tcName, targetName)

pkg/manager/member/pd_ms_upgrader_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ func newTidbClusterForPDMSUpgrader() *v1alpha1.TidbCluster {
307307
StorageClassName: pointer.StringPtr("my-storage-class"),
308308
},
309309
},
310+
ClusterDomain: "cluster.local",
310311
},
311312
Status: v1alpha1.TidbClusterStatus{
312313
PDMS: map[string]*v1alpha1.PDMSStatus{

pkg/manager/member/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func PdName(tcName string, ordinal int32, namespace string, clusterDomain string
162162
// See the start script of PDMS in pkg/manager/member/startscript/v2.renderPDMSStartScript
163163
func PDMSName(tcName string, ordinal int32, namespace, clusterDomain string, acrossK8s bool, component string) string {
164164
if len(clusterDomain) > 0 {
165-
return fmt.Sprintf("%s.%s-%s-peer.%s.svc.%s", PDMSPodName(tcName, ordinal, component), component, tcName, namespace, clusterDomain)
165+
return fmt.Sprintf("%s.%s-%s-peer.%s.svc.%s", PDMSPodName(tcName, ordinal, component), tcName, component, namespace, clusterDomain)
166166
}
167167

168168
// clusterDomain is not set

pkg/pdapi/fake_pdapi.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package pdapi
1515

1616
import (
1717
"fmt"
18+
"strings"
1819

1920
"github.com/pingcap/kvproto/pkg/metapb"
2021
"github.com/pingcap/kvproto/pkg/pdpb"
@@ -316,10 +317,11 @@ func (c *FakePDClient) GetReady() (bool, error) {
316317
// FakePDMSClient implements a fake version of PDMSClient.
317318
type FakePDMSClient struct {
318319
reactions map[ActionType]Reaction
320+
domain string
319321
}
320322

321-
func NewFakePDMSClient() *FakePDMSClient {
322-
return &FakePDMSClient{reactions: map[ActionType]Reaction{}}
323+
func NewFakePDMSClient(domain string) *FakePDMSClient {
324+
return &FakePDMSClient{reactions: map[ActionType]Reaction{}, domain: domain}
323325
}
324326

325327
func (c *FakePDMSClient) AddReaction(actionType ActionType, reaction Reaction) {
@@ -346,6 +348,9 @@ func (c *FakePDMSClient) GetHealth() error {
346348

347349
func (c *FakePDMSClient) TransferPrimary(newPrimary string) error {
348350
action := &Action{Name: newPrimary}
351+
if len(c.domain) > 0 && !strings.Contains(newPrimary, c.domain) {
352+
return fmt.Errorf("new primary %s does not contain domain %s", newPrimary, c.domain)
353+
}
349354
_, err := c.fakeAPI(PDMSTransferPrimaryActionType, action)
350355
return err
351356
}

0 commit comments

Comments
 (0)