@@ -17,13 +17,13 @@ import (
1717 "fmt"
1818 "testing"
1919
20+ . "github.com/onsi/gomega"
21+ "github.com/pingcap/kvproto/pkg/pdpb"
2022 "github.com/pingcap/tidb-operator/pkg/apis/label"
2123 "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
2224 "github.com/pingcap/tidb-operator/pkg/controller"
2325 mngerutils "github.com/pingcap/tidb-operator/pkg/manager/utils"
2426 "github.com/pingcap/tidb-operator/pkg/pdapi"
25-
26- . "github.com/onsi/gomega"
2727 apps "k8s.io/api/apps/v1"
2828 corev1 "k8s.io/api/core/v1"
2929 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -51,6 +51,7 @@ func TestPDUpgraderUpgrade(t *testing.T) {
5151 upgrader , pdControl , _ , podInformer := newPDUpgrader ()
5252 tc := newTidbClusterForPDUpgrader ()
5353 pdClient := controller .NewFakePDClient (pdControl , tc )
54+ etcdClient := controller .NewFakeEtcdClient (pdControl , tc )
5455
5556 if test .changeFn != nil {
5657 test .changeFn (tc )
@@ -95,6 +96,30 @@ func TestPDUpgraderUpgrade(t *testing.T) {
9596 return healthInfo , nil
9697 })
9798
99+ pdClient .AddReaction (pdapi .GetMembersActionType , func (action * pdapi.Action ) (interface {}, error ) {
100+ membersInfo := & pdapi.MembersInfo {
101+ Members : []* pdpb.Member {
102+ {
103+ Name : PdPodName (upgradeTcName , 0 ),
104+ MemberId : 111 ,
105+ PeerUrls : []string {"http://upgrader-pd-0:2380" },
106+ },
107+ {
108+ Name : PdPodName (upgradeTcName , 1 ),
109+ MemberId : 222 ,
110+ PeerUrls : []string {"http://upgrader-pd-1:2380" },
111+ },
112+ },
113+ }
114+ return membersInfo , nil
115+ })
116+
117+ pdClient .GetMembers ()
118+
119+ etcdClient .AddReaction (pdapi .EtcdUpdateMemberActionType , func (action * pdapi.Action ) (interface {}, error ) {
120+ return nil , nil
121+ })
122+
98123 err := upgrader .Upgrade (tc , oldSet , newSet )
99124 test .errExpectFn (g , err )
100125 test .expectFn (g , tc , newSet )
@@ -314,12 +339,41 @@ func TestPDUpgraderUpgrade(t *testing.T) {
314339 g .Expect (newSet .Spec .UpdateStrategy .RollingUpdate .Partition ).To (Equal (pointer .Int32Ptr (1 )))
315340 },
316341 },
342+ {
343+ name : "upgrade from non-tls to tls" ,
344+ changeFn : func (tc * v1alpha1.TidbCluster ) {
345+ tc .Status .PD .Synced = true
346+ tc .Spec = v1alpha1.TidbClusterSpec {
347+ PD : & v1alpha1.PDSpec {
348+ ComponentSpec : v1alpha1.ComponentSpec {
349+ Image : "pingcap/pd:v3.1.0" ,
350+ },
351+ },
352+ TiDB : & v1alpha1.TiDBSpec {
353+ TLSClient : & v1alpha1.TiDBTLSClient {
354+ Enabled : true ,
355+ },
356+ },
357+ TiKV : & v1alpha1.TiKVSpec {},
358+ TLSCluster : & v1alpha1.TLSCluster {Enabled : true },
359+ }
360+ },
361+ changePods : nil ,
362+ changeOldSet : nil ,
363+ transferLeaderErr : false ,
364+ errExpectFn : func (g * GomegaWithT , err error ) {
365+ g .Expect (err ).NotTo (HaveOccurred ())
366+ },
367+ expectFn : func (g * GomegaWithT , tc * v1alpha1.TidbCluster , newSet * apps.StatefulSet ) {
368+ g .Expect (tc .Status .PD .Phase ).To (Equal (v1alpha1 .UpgradePhase ))
369+ g .Expect (newSet .Spec .UpdateStrategy .RollingUpdate .Partition ).To (Equal (pointer .Int32Ptr (1 )))
370+ },
371+ },
317372 }
318373
319374 for i := range tests {
320375 testFn (& tests [i ])
321376 }
322-
323377}
324378
325379func TestChoosePDToTransferFromMembers (t * testing.T ) {
@@ -447,6 +501,16 @@ func TestChoosePDToTransferFromMembers(t *testing.T) {
447501
448502func newPDUpgrader () (Upgrader , * pdapi.FakePDControl , * controller.FakePodControl , podinformers.PodInformer ) {
449503 fakeDeps := controller .NewFakeDependencies ()
504+
505+ informer := fakeDeps .KubeInformerFactory
506+ informer .Core ().V1 ().Secrets ().Informer ().GetIndexer ().Add (& corev1.Secret {
507+ ObjectMeta : metav1.ObjectMeta {
508+ Name : "upgrader-cluster-client-secret" ,
509+ Namespace : corev1 .NamespaceDefault ,
510+ },
511+ })
512+ fakeDeps .PDControl = pdapi .NewFakePDControl (informer .Core ().V1 ().Secrets ().Lister ())
513+
450514 pdUpgrader := & pdUpgrader {deps : fakeDeps }
451515 pdControl := fakeDeps .PDControl .(* pdapi.FakePDControl )
452516 podControl := fakeDeps .PodControl .(* controller.FakePodControl )
0 commit comments