From 7a9f661ff53d7acc603fc6b13d78e0af1c967779 Mon Sep 17 00:00:00 2001 From: xiaojingchen Date: Mon, 18 Feb 2019 19:59:55 +0800 Subject: [PATCH 1/4] add clusterID label to tidbCluster --- .../tidbcluster/tidb_cluster_controller.go | 3 +- .../tidb_cluster_controller_test.go | 4 +- pkg/controller/tidbcluster_control.go | 50 ++++++++++++- pkg/controller/tidbcluster_control_test.go | 50 ++++++++++++- pkg/manager/meta/meta_manager.go | 8 ++ pkg/manager/meta/meta_manager_test.go | 74 ++++++++++++++++++- 6 files changed, 178 insertions(+), 11 deletions(-) diff --git a/pkg/controller/tidbcluster/tidb_cluster_controller.go b/pkg/controller/tidbcluster/tidb_cluster_controller.go index 677802af01..e0097bf6d2 100644 --- a/pkg/controller/tidbcluster/tidb_cluster_controller.go +++ b/pkg/controller/tidbcluster/tidb_cluster_controller.go @@ -89,8 +89,8 @@ func NewController( podInformer := kubeInformerFactory.Core().V1().Pods() nodeInformer := kubeInformerFactory.Core().V1().Nodes() - tcControl := controller.NewRealTidbClusterControl(cli, tcInformer.Lister(), recorder) pdControl := controller.NewDefaultPDControl() + tcControl := controller.NewRealTidbClusterControl(cli, tcInformer.Lister(), recorder, pdControl) tidbControl := controller.NewDefaultTiDBControl() setControl := controller.NewRealStatefuSetControl(kubeCli, setInformer.Lister(), recorder) svcControl := controller.NewRealServiceControl(kubeCli, svcInformer.Lister(), recorder) @@ -155,6 +155,7 @@ func NewController( pvControl, ), meta.NewMetaManager( + tcControl, pvcInformer.Lister(), pvcControl, pvInformer.Lister(), diff --git a/pkg/controller/tidbcluster/tidb_cluster_controller_test.go b/pkg/controller/tidbcluster/tidb_cluster_controller_test.go index c9a442bb0a..3b2f8c5a4f 100644 --- a/pkg/controller/tidbcluster/tidb_cluster_controller_test.go +++ b/pkg/controller/tidbcluster/tidb_cluster_controller_test.go @@ -262,8 +262,9 @@ func newFakeTidbClusterController() (*Controller, cache.Indexer, cache.Indexer) tikvUpgrader := mm.NewFakeTiKVUpgrader() tidbUpgrader := mm.NewFakeTiDBUpgrader() + tcControl := controller.NewRealTidbClusterControl(cli, tcInformer.Lister(), recorder, pdControl) tcc.control = NewDefaultTidbClusterControl( - controller.NewRealTidbClusterControl(cli, tcInformer.Lister(), recorder), + tcControl, mm.NewPDMemberManager( pdControl, setControl, @@ -312,6 +313,7 @@ func newFakeTidbClusterController() (*Controller, cache.Indexer, cache.Indexer) pvControl, ), meta.NewMetaManager( + tcControl, pvcInformer.Lister(), pvcControl, pvInformer.Lister(), diff --git a/pkg/controller/tidbcluster_control.go b/pkg/controller/tidbcluster_control.go index 960e450836..160a99b3ec 100644 --- a/pkg/controller/tidbcluster_control.go +++ b/pkg/controller/tidbcluster_control.go @@ -15,6 +15,7 @@ package controller import ( "fmt" + "strconv" "strings" "github.com/golang/glog" @@ -22,6 +23,7 @@ import ( "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned" tcinformers "github.com/pingcap/tidb-operator/pkg/client/informers/externalversions/pingcap.com/v1alpha1" listers "github.com/pingcap/tidb-operator/pkg/client/listers/pingcap.com/v1alpha1" + "github.com/pingcap/tidb-operator/pkg/label" corev1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -34,25 +36,46 @@ import ( // TidbClusterControlInterface manages TidbClusters type TidbClusterControlInterface interface { UpdateTidbCluster(*v1alpha1.TidbCluster, *v1alpha1.TidbClusterStatus, *v1alpha1.TidbClusterStatus) (*v1alpha1.TidbCluster, error) + UpdateMetaInfo(*v1alpha1.TidbCluster) (*v1alpha1.TidbCluster, error) } type realTidbClusterControl struct { - cli versioned.Interface - tcLister listers.TidbClusterLister - recorder record.EventRecorder + cli versioned.Interface + tcLister listers.TidbClusterLister + recorder record.EventRecorder + pdControl PDControlInterface } // NewRealTidbClusterControl creates a new TidbClusterControlInterface func NewRealTidbClusterControl(cli versioned.Interface, tcLister listers.TidbClusterLister, - recorder record.EventRecorder) TidbClusterControlInterface { + recorder record.EventRecorder, + pdControl PDControlInterface) TidbClusterControlInterface { return &realTidbClusterControl{ cli, tcLister, recorder, + pdControl, } } +func (rtc *realTidbClusterControl) UpdateMetaInfo(tc *v1alpha1.TidbCluster) (*v1alpha1.TidbCluster, error) { + pdClient := rtc.pdControl.GetPDClient(tc) + pdClient.GetCluster() + cluster, err := pdClient.GetCluster() + if err != nil { + return tc, fmt.Errorf("failed to get tidb cluster info from pd, TidbCluster: %s/%s, err: %v", tc.GetNamespace(), tc.GetName(), err) + } + clusterID := strconv.FormatUint(cluster.Id, 10) + labels := tc.GetLabels() + if labels == nil { + labels = map[string]string{} + } + setIfNotEmpty(labels, label.ClusterIDLabelKey, clusterID) + tc.Labels = labels + return tc, nil +} + func (rtc *realTidbClusterControl) UpdateTidbCluster(tc *v1alpha1.TidbCluster, newStatus *v1alpha1.TidbClusterStatus, oldStatus *v1alpha1.TidbClusterStatus) (*v1alpha1.TidbCluster, error) { ns := tc.GetNamespace() tcName := tc.GetName() @@ -122,6 +145,7 @@ type FakeTidbClusterControl struct { TcLister listers.TidbClusterLister TcIndexer cache.Indexer updateTidbClusterTracker requestTracker + updateMetaInfoTracker requestTracker } // NewFakeTidbClusterControl returns a FakeTidbClusterControl @@ -130,6 +154,7 @@ func NewFakeTidbClusterControl(tcInformer tcinformers.TidbClusterInformer) *Fake tcInformer.Lister(), tcInformer.Informer().GetIndexer(), requestTracker{0, nil, 0}, + requestTracker{0, nil, 0}, } } @@ -139,6 +164,12 @@ func (ssc *FakeTidbClusterControl) SetUpdateTidbClusterError(err error, after in ssc.updateTidbClusterTracker.after = after } +// SetUpdateMetaInfoError sets the error attributes of updateMetaInfoTracker +func (ssc *FakeTidbClusterControl) SetUpdateMetaInfoError(err error, after int) { + ssc.updateMetaInfoTracker.err = err + ssc.updateMetaInfoTracker.after = after +} + // UpdateTidbCluster updates the TidbCluster func (ssc *FakeTidbClusterControl) UpdateTidbCluster(tc *v1alpha1.TidbCluster, _ *v1alpha1.TidbClusterStatus, _ *v1alpha1.TidbClusterStatus) (*v1alpha1.TidbCluster, error) { defer ssc.updateTidbClusterTracker.inc() @@ -149,3 +180,14 @@ func (ssc *FakeTidbClusterControl) UpdateTidbCluster(tc *v1alpha1.TidbCluster, _ return tc, ssc.TcIndexer.Update(tc) } + +func (ssc *FakeTidbClusterControl) UpdateMetaInfo(tc *v1alpha1.TidbCluster) (*v1alpha1.TidbCluster, error) { + defer ssc.updateMetaInfoTracker.inc() + if ssc.updateMetaInfoTracker.errorReady() { + defer ssc.updateMetaInfoTracker.reset() + return tc, ssc.updateMetaInfoTracker.err + } + + tc.Labels = map[string]string{label.ClusterIDLabelKey: TestClusterID} + return tc, nil +} diff --git a/pkg/controller/tidbcluster_control_test.go b/pkg/controller/tidbcluster_control_test.go index c9a01c1db0..809acca6e7 100644 --- a/pkg/controller/tidbcluster_control_test.go +++ b/pkg/controller/tidbcluster_control_test.go @@ -15,14 +15,16 @@ package controller import ( "errors" + "fmt" "testing" - "time" . "github.com/onsi/gomega" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned/fake" listers "github.com/pingcap/tidb-operator/pkg/client/listers/pingcap.com/v1alpha1" + "github.com/pingcap/tidb-operator/pkg/label" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -37,7 +39,8 @@ func TestTidbClusterControlUpdateTidbCluster(t *testing.T) { tc := newTidbCluster() tc.Spec.PD.Replicas = int32(5) fakeClient := &fake.Clientset{} - control := NewRealTidbClusterControl(fakeClient, nil, recorder) + pdControl := NewFakePDControl() + control := NewRealTidbClusterControl(fakeClient, nil, recorder, pdControl) fakeClient.AddReactor("update", "tidbclusters", func(action core.Action) (bool, runtime.Object, error) { update := action.(core.UpdateAction) return true, update.GetObject(), nil @@ -57,7 +60,8 @@ func TestTidbClusterControlUpdateTidbClusterConflictSuccess(t *testing.T) { fakeClient := &fake.Clientset{} indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) tcLister := listers.NewTidbClusterLister(indexer) - control := NewRealTidbClusterControl(fakeClient, tcLister, recorder) + pdControl := NewFakePDControl() + control := NewRealTidbClusterControl(fakeClient, tcLister, recorder, pdControl) conflict := false fakeClient.AddReactor("update", "tidbclusters", func(action core.Action) (bool, runtime.Object, error) { update := action.(core.UpdateAction) @@ -74,6 +78,46 @@ func TestTidbClusterControlUpdateTidbClusterConflictSuccess(t *testing.T) { g.Expect(events).To(HaveLen(0)) } +func TestRealTidbClusterControlUpdateMetaInfoSuccess(t *testing.T) { + g := NewGomegaWithT(t) + recorder := record.NewFakeRecorder(10) + tc := newTidbCluster() + tc.Spec.PD.Replicas = int32(5) + fakeClient := &fake.Clientset{} + pdControl := NewFakePDControl() + control := NewRealTidbClusterControl(fakeClient, nil, recorder, pdControl) + pdClient := NewFakePDClient() + pdControl.SetPDClient(tc, pdClient) + pdClient.AddReaction(GetClusterActionType, func(action *Action) (interface{}, error) { + cluster := &metapb.Cluster{ + Id: 1234, + } + return cluster, nil + }) + tc, err := control.UpdateMetaInfo(tc) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(tc.Labels[label.ClusterIDLabelKey]).NotTo(BeNil()) + g.Expect(tc.Labels[label.ClusterIDLabelKey]).To(Equal("1234")) +} + +func TestRealTidbClusterControlUpdateMetaInfoGetClusterFailed(t *testing.T) { + g := NewGomegaWithT(t) + recorder := record.NewFakeRecorder(10) + tc := newTidbCluster() + tc.Spec.PD.Replicas = int32(5) + fakeClient := &fake.Clientset{} + pdControl := NewFakePDControl() + control := NewRealTidbClusterControl(fakeClient, nil, recorder, pdControl) + pdClient := NewFakePDClient() + pdControl.SetPDClient(tc, pdClient) + pdClient.AddReaction(GetClusterActionType, func(action *Action) (interface{}, error) { + return nil, fmt.Errorf("error to get cluster") + }) + tc, err := control.UpdateMetaInfo(tc) + g.Expect(err).To(HaveOccurred()) + g.Expect(tc.Labels[label.ClusterIDLabelKey]).To(Equal("")) +} + func TestDeepEqualExceptHeartbeatTime(t *testing.T) { g := NewGomegaWithT(t) diff --git a/pkg/manager/meta/meta_manager.go b/pkg/manager/meta/meta_manager.go index 3ec61b03c1..dd57bb0dce 100644 --- a/pkg/manager/meta/meta_manager.go +++ b/pkg/manager/meta/meta_manager.go @@ -27,6 +27,7 @@ import ( var errPVCNotFound = errors.New("PVC is not found") type metaManager struct { + tcControl controller.TidbClusterControlInterface pvcLister corelisters.PersistentVolumeClaimLister pvcControl controller.PVCControlInterface pvLister corelisters.PersistentVolumeLister @@ -37,6 +38,7 @@ type metaManager struct { // NewMetaManager returns a *metaManager func NewMetaManager( + tcControl controller.TidbClusterControlInterface, pvcLister corelisters.PersistentVolumeClaimLister, pvcControl controller.PVCControlInterface, pvLister corelisters.PersistentVolumeLister, @@ -45,6 +47,7 @@ func NewMetaManager( podControl controller.PodControlInterface, ) manager.Manager { return &metaManager{ + tcControl: tcControl, pvcLister: pvcLister, pvcControl: pvcControl, pvLister: pvLister, @@ -67,6 +70,11 @@ func (pmm *metaManager) Sync(tc *v1alpha1.TidbCluster) error { return err } + tc, err = pmm.tcControl.UpdateMetaInfo(tc) + if err != nil { + return err + } + for _, pod := range pods { // update meta info for pod _, err := pmm.podControl.UpdateMetaInfo(tc, pod) diff --git a/pkg/manager/meta/meta_manager_test.go b/pkg/manager/meta/meta_manager_test.go index 2bcc43975e..cec501a108 100644 --- a/pkg/manager/meta/meta_manager_test.go +++ b/pkg/manager/meta/meta_manager_test.go @@ -20,6 +20,8 @@ import ( . "github.com/onsi/gomega" "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" + "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned/fake" + informers "github.com/pingcap/tidb-operator/pkg/client/informers/externalversions" "github.com/pingcap/tidb-operator/pkg/controller" "github.com/pingcap/tidb-operator/pkg/label" corev1 "k8s.io/api/core/v1" @@ -39,12 +41,14 @@ func TestMetaManagerSync(t *testing.T) { pvcHasLabels bool pvcHasVolumeName bool podRefPvc bool + tcUpdateErr bool podUpdateErr bool getClusterErr bool getMemberErr bool getStoreErr bool pvcUpdateErr bool pvUpdateErr bool + tcChanged bool podChanged bool pvcChanged bool pvChanged bool @@ -72,7 +76,7 @@ func TestMetaManagerSync(t *testing.T) { pod1.Spec = newPodSpec(v1alpha1.TiDBMemberType.String(), pvc1.GetName()) } - nmm, fakePodControl, fakePVCControl, fakePVControl, podIndexer, pvcIndexer, pvIndexer := newFakeMetaManager() + nmm, fakePodControl, fakePVCControl, fakePVControl, fakeTcControl, podIndexer, pvcIndexer, pvIndexer := newFakeMetaManager() err := podIndexer.Add(pod1) g.Expect(err).NotTo(HaveOccurred()) err = pvcIndexer.Add(pvc1) @@ -80,6 +84,9 @@ func TestMetaManagerSync(t *testing.T) { err = pvIndexer.Add(pv1) g.Expect(err).NotTo(HaveOccurred()) + if test.tcUpdateErr { + fakeTcControl.SetUpdateMetaInfoError(errors.NewInternalError(fmt.Errorf("set tidbCluster labels error")), 0) + } if test.podUpdateErr { fakePodControl.SetUpdatePodError(errors.NewInternalError(fmt.Errorf("API server failed")), 0) } @@ -100,6 +107,24 @@ func TestMetaManagerSync(t *testing.T) { } err = nmm.Sync(tc) + if test.tcUpdateErr { + g.Expect(err).To(HaveOccurred()) + + g.Expect(tcMetaInfoMatchDesire(tc)).To(Equal(false)) + + pod, err := nmm.podLister.Pods(ns).Get(pod1.Name) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(podMetaInfoMatchDesire(pod)).To(Equal(false)) + + pvc, err := nmm.pvcLister.PersistentVolumeClaims(ns).Get(pvc1.Name) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(pvcMetaInfoMatchDesire(pvc)).To(Equal(false)) + + pv, err := nmm.pvLister.Get(pv1.Name) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(pvMetaInfoMatchDesire(ns, pv)).To(Equal(false)) + } + if test.podUpdateErr || test.getClusterErr || test.getMemberErr || test.getStoreErr { g.Expect(err).To(HaveOccurred()) @@ -136,6 +161,12 @@ func TestMetaManagerSync(t *testing.T) { g.Expect(pvMetaInfoMatchDesire(ns, pv)).To(Equal(false)) } + if test.tcChanged { + g.Expect(tcMetaInfoMatchDesire(tc)).To(Equal(true)) + } else { + g.Expect(tcMetaInfoMatchDesire(tc)).To(Equal(false)) + } + if test.podChanged { pod, err := nmm.podLister.Pods(ns).Get(pod1.Name) g.Expect(err).NotTo(HaveOccurred()) @@ -181,6 +212,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: true, pvcChanged: true, pvChanged: true, @@ -197,6 +229,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -213,6 +246,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: true, pvcChanged: true, pvChanged: true, @@ -229,6 +263,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: true, pvcChanged: true, pvChanged: false, @@ -245,6 +280,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: true, pvcChanged: false, pvChanged: false, @@ -261,6 +297,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -277,6 +314,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -293,6 +331,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -309,6 +348,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: true, pvcUpdateErr: false, pvUpdateErr: false, + tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -325,6 +365,7 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: true, pvUpdateErr: false, + tcChanged: true, podChanged: true, pvcChanged: false, pvChanged: false, @@ -341,10 +382,28 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: true, + tcChanged: true, podChanged: true, pvcChanged: true, pvChanged: false, }, + { + name: "tc update failed", + podHasLabels: true, + pvcHasLabels: true, + pvcHasVolumeName: true, + podRefPvc: true, + tcUpdateErr: true, + podUpdateErr: false, + getClusterErr: false, + getMemberErr: false, + getStoreErr: false, + pvcUpdateErr: false, + pvUpdateErr: false, + podChanged: false, + pvcChanged: false, + pvChanged: false, + }, } for i := range tests { @@ -357,6 +416,7 @@ func newFakeMetaManager() ( *controller.FakePodControl, *controller.FakePVCControl, *controller.FakePVControl, + *controller.FakeTidbClusterControl, cache.Indexer, cache.Indexer, cache.Indexer, @@ -372,14 +432,24 @@ func newFakeMetaManager() ( pvcControl := controller.NewFakePVCControl(pvcInformer) pvControl := controller.NewFakePVControl(pvInformer, pvcInformer) + cli := fake.NewSimpleClientset() + informerFactory := informers.NewSharedInformerFactory(cli, 0) + tcInformer := informerFactory.Pingcap().V1alpha1().TidbClusters() + tcControl := controller.NewFakeTidbClusterControl(tcInformer) + return &metaManager{ + tcControl, pvcInformer.Lister(), pvcControl, pvInformer.Lister(), pvControl, podInformer.Lister(), podControl, - }, podControl, pvcControl, pvControl, podInformer.Informer().GetIndexer(), pvcInformer.Informer().GetIndexer(), pvInformer.Informer().GetIndexer() + }, podControl, pvcControl, pvControl, tcControl, podInformer.Informer().GetIndexer(), pvcInformer.Informer().GetIndexer(), pvInformer.Informer().GetIndexer() +} + +func tcMetaInfoMatchDesire(tc *v1alpha1.TidbCluster) bool { + return tc.Labels[label.ClusterIDLabelKey] == controller.TestClusterID } func podMetaInfoMatchDesire(pod *corev1.Pod) bool { From f6c1f9b73561de888c78169f07df5cdbfa6db693 Mon Sep 17 00:00:00 2001 From: xiaojingchen Date: Mon, 18 Feb 2019 20:11:34 +0800 Subject: [PATCH 2/4] change e2e test --- tests/e2e/create.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/e2e/create.go b/tests/e2e/create.go index 0ef1c6e4e2..53c9f9d66e 100644 --- a/tests/e2e/create.go +++ b/tests/e2e/create.go @@ -500,6 +500,8 @@ func metaSynced(tc *v1alpha1.TidbCluster) (bool, error) { return false, nil } + Expect(tc.Labels[label.ClusterIDLabelKey]).To(Equal(clusterID)) + outerLoop: for _, pod := range podList.Items { podName := pod.GetName() From ff249ba03f5b4f62c1ebd076f0a278e7667b883b Mon Sep 17 00:00:00 2001 From: xiaojingchen Date: Tue, 19 Feb 2019 15:31:10 +0800 Subject: [PATCH 3/4] add clusterID field --- pkg/apis/pingcap.com/v1alpha1/tidbcluster.go | 4 +++ pkg/apis/pingcap.com/v1alpha1/types.go | 7 ++-- pkg/manager/member/pd_member_manager.go | 9 +++++ pkg/manager/member/pd_member_manager_test.go | 37 ++++++++++++++++++++ tests/e2e/create.go | 5 +++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/pkg/apis/pingcap.com/v1alpha1/tidbcluster.go b/pkg/apis/pingcap.com/v1alpha1/tidbcluster.go index dc15cf2f05..c336b05806 100644 --- a/pkg/apis/pingcap.com/v1alpha1/tidbcluster.go +++ b/pkg/apis/pingcap.com/v1alpha1/tidbcluster.go @@ -150,3 +150,7 @@ func (tc *TidbCluster) TiKVIsAvailable() bool { return true } + +func (tc *TidbCluster) GetClusterID() string { + return tc.Status.ClusterID +} diff --git a/pkg/apis/pingcap.com/v1alpha1/types.go b/pkg/apis/pingcap.com/v1alpha1/types.go index 201733374a..78cc5de6c7 100644 --- a/pkg/apis/pingcap.com/v1alpha1/types.go +++ b/pkg/apis/pingcap.com/v1alpha1/types.go @@ -98,9 +98,10 @@ type TidbClusterSpec struct { // TidbClusterStatus represents the current status of a tidb cluster. type TidbClusterStatus struct { - PD PDStatus `json:"pd,omitempty"` - TiKV TiKVStatus `json:"tikv,omitempty"` - TiDB TiDBStatus `json:"tidb,omitempty"` + ClusterID string `json:"clusterID,omitempty"` + PD PDStatus `json:"pd,omitempty"` + TiKV TiKVStatus `json:"tikv,omitempty"` + TiDB TiDBStatus `json:"tidb,omitempty"` } // PDSpec contains details of PD member diff --git a/pkg/manager/member/pd_member_manager.go b/pkg/manager/member/pd_member_manager.go index 01c6e074e7..d3039a1829 100644 --- a/pkg/manager/member/pd_member_manager.go +++ b/pkg/manager/member/pd_member_manager.go @@ -15,6 +15,7 @@ package member import ( "fmt" + "strconv" "github.com/golang/glog" "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" @@ -254,6 +255,14 @@ func (pmm *pdMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, set } pdClient := pmm.pdControl.GetPDClient(tc) + + cluster, err := pdClient.GetCluster() + if err != nil { + tc.Status.PD.Synced = false + return err + } + tc.Status.ClusterID = strconv.FormatUint(cluster.Id, 10) + healthInfo, err := pdClient.GetHealth() if err != nil { tc.Status.PD.Synced = false diff --git a/pkg/manager/member/pd_member_manager_test.go b/pkg/manager/member/pd_member_manager_test.go index 990aa45d6e..2653e13335 100644 --- a/pkg/manager/member/pd_member_manager_test.go +++ b/pkg/manager/member/pd_member_manager_test.go @@ -19,6 +19,7 @@ import ( "testing" . "github.com/onsi/gomega" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned/fake" informers "github.com/pingcap/tidb-operator/pkg/client/informers/externalversions" @@ -187,6 +188,7 @@ func TestPDMemberManagerSyncUpdate(t *testing.T) { errWhenUpdateStatefulSet bool errWhenUpdatePDService bool errWhenUpdatePDPeerService bool + errWhenGetCluster bool errWhenGetPDHealth bool statusChange func(*apps.StatefulSet) err bool @@ -214,6 +216,16 @@ func TestPDMemberManagerSyncUpdate(t *testing.T) { }) } + if test.errWhenGetCluster { + pdClient.AddReaction(controller.GetClusterActionType, func(action *controller.Action) (interface{}, error) { + return nil, fmt.Errorf("failed to get cluster info") + }) + } else { + pdClient.AddReaction(controller.GetClusterActionType, func(action *controller.Action) (interface{}, error) { + return &metapb.Cluster{Id: uint64(1)}, nil + }) + } + if test.statusChange == nil { fakeSetControl.SetStatusChange(func(set *apps.StatefulSet) { set.Status.Replicas = *set.Spec.Replicas @@ -302,6 +314,7 @@ func TestPDMemberManagerSyncUpdate(t *testing.T) { // g.Expect(int(*set.Spec.Replicas)).To(Equal(4)) }, expectTidbClusterFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) { + g.Expect(tc.Status.ClusterID).To(Equal("1")) g.Expect(tc.Status.PD.Phase).To(Equal(v1alpha1.NormalPhase)) g.Expect(*tc.Status.PD.StatefulSet.ObservedGeneration).To(Equal(int64(1))) g.Expect(len(tc.Status.PD.Members)).To(Equal(3)) @@ -388,6 +401,27 @@ func TestPDMemberManagerSyncUpdate(t *testing.T) { g.Expect(tc.Status.PD.Members).To(BeNil()) }, }, + { + name: "error when sync cluster ID", + modify: func(tc *v1alpha1.TidbCluster) { + tc.Spec.PD.Replicas = 5 + }, + errWhenUpdateStatefulSet: false, + errWhenUpdatePDService: false, + errWhenUpdatePDPeerService: false, + errWhenGetCluster: true, + errWhenGetPDHealth: false, + err: false, + expectPDServiceFn: nil, + expectPDPeerServiceFn: nil, + expectStatefulSetFn: func(g *GomegaWithT, set *apps.StatefulSet, err error) { + g.Expect(err).NotTo(HaveOccurred()) + }, + expectTidbClusterFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) { + g.Expect(tc.Status.PD.Synced).To(BeFalse()) + g.Expect(tc.Status.PD.Members).To(BeNil()) + }, + }, } for i := range tests { @@ -521,6 +555,9 @@ func TestPDMemberManagerUpgrade(t *testing.T) { pdClient.AddReaction(controller.GetHealthActionType, func(action *controller.Action) (interface{}, error) { return test.pdHealth, nil }) + pdClient.AddReaction(controller.GetClusterActionType, func(action *controller.Action) (interface{}, error) { + return &metapb.Cluster{Id: uint64(1)}, nil + }) fakeSetControl.SetStatusChange(test.statusChange) diff --git a/tests/e2e/create.go b/tests/e2e/create.go index 53c9f9d66e..075ab29a28 100644 --- a/tests/e2e/create.go +++ b/tests/e2e/create.go @@ -240,6 +240,11 @@ func pdMemberRunning(tc *v1alpha1.TidbCluster) (bool, error) { } } + if tc.Status.ClusterID == "" { + logf("tc.Status.ClusterID is nil") + return false, nil + } + _, err = kubeCli.CoreV1().Services(ns).Get(controller.PDMemberName(tcName), metav1.GetOptions{}) if err != nil { logf(err.Error()) From e08c5cedd2626e533252614315f9cea88b2c026e Mon Sep 17 00:00:00 2001 From: xiaojingchen Date: Wed, 20 Feb 2019 15:33:49 +0800 Subject: [PATCH 4/4] remove label --- .../tidbcluster/tidb_cluster_controller.go | 3 +- .../tidb_cluster_controller_test.go | 4 +- pkg/controller/tidbcluster_control.go | 50 +------------ pkg/controller/tidbcluster_control_test.go | 50 +------------ pkg/manager/meta/meta_manager.go | 8 -- pkg/manager/meta/meta_manager_test.go | 74 +------------------ tests/e2e/create.go | 2 - 7 files changed, 11 insertions(+), 180 deletions(-) diff --git a/pkg/controller/tidbcluster/tidb_cluster_controller.go b/pkg/controller/tidbcluster/tidb_cluster_controller.go index e0097bf6d2..677802af01 100644 --- a/pkg/controller/tidbcluster/tidb_cluster_controller.go +++ b/pkg/controller/tidbcluster/tidb_cluster_controller.go @@ -89,8 +89,8 @@ func NewController( podInformer := kubeInformerFactory.Core().V1().Pods() nodeInformer := kubeInformerFactory.Core().V1().Nodes() + tcControl := controller.NewRealTidbClusterControl(cli, tcInformer.Lister(), recorder) pdControl := controller.NewDefaultPDControl() - tcControl := controller.NewRealTidbClusterControl(cli, tcInformer.Lister(), recorder, pdControl) tidbControl := controller.NewDefaultTiDBControl() setControl := controller.NewRealStatefuSetControl(kubeCli, setInformer.Lister(), recorder) svcControl := controller.NewRealServiceControl(kubeCli, svcInformer.Lister(), recorder) @@ -155,7 +155,6 @@ func NewController( pvControl, ), meta.NewMetaManager( - tcControl, pvcInformer.Lister(), pvcControl, pvInformer.Lister(), diff --git a/pkg/controller/tidbcluster/tidb_cluster_controller_test.go b/pkg/controller/tidbcluster/tidb_cluster_controller_test.go index 3b2f8c5a4f..c9a442bb0a 100644 --- a/pkg/controller/tidbcluster/tidb_cluster_controller_test.go +++ b/pkg/controller/tidbcluster/tidb_cluster_controller_test.go @@ -262,9 +262,8 @@ func newFakeTidbClusterController() (*Controller, cache.Indexer, cache.Indexer) tikvUpgrader := mm.NewFakeTiKVUpgrader() tidbUpgrader := mm.NewFakeTiDBUpgrader() - tcControl := controller.NewRealTidbClusterControl(cli, tcInformer.Lister(), recorder, pdControl) tcc.control = NewDefaultTidbClusterControl( - tcControl, + controller.NewRealTidbClusterControl(cli, tcInformer.Lister(), recorder), mm.NewPDMemberManager( pdControl, setControl, @@ -313,7 +312,6 @@ func newFakeTidbClusterController() (*Controller, cache.Indexer, cache.Indexer) pvControl, ), meta.NewMetaManager( - tcControl, pvcInformer.Lister(), pvcControl, pvInformer.Lister(), diff --git a/pkg/controller/tidbcluster_control.go b/pkg/controller/tidbcluster_control.go index 160a99b3ec..960e450836 100644 --- a/pkg/controller/tidbcluster_control.go +++ b/pkg/controller/tidbcluster_control.go @@ -15,7 +15,6 @@ package controller import ( "fmt" - "strconv" "strings" "github.com/golang/glog" @@ -23,7 +22,6 @@ import ( "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned" tcinformers "github.com/pingcap/tidb-operator/pkg/client/informers/externalversions/pingcap.com/v1alpha1" listers "github.com/pingcap/tidb-operator/pkg/client/listers/pingcap.com/v1alpha1" - "github.com/pingcap/tidb-operator/pkg/label" corev1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -36,46 +34,25 @@ import ( // TidbClusterControlInterface manages TidbClusters type TidbClusterControlInterface interface { UpdateTidbCluster(*v1alpha1.TidbCluster, *v1alpha1.TidbClusterStatus, *v1alpha1.TidbClusterStatus) (*v1alpha1.TidbCluster, error) - UpdateMetaInfo(*v1alpha1.TidbCluster) (*v1alpha1.TidbCluster, error) } type realTidbClusterControl struct { - cli versioned.Interface - tcLister listers.TidbClusterLister - recorder record.EventRecorder - pdControl PDControlInterface + cli versioned.Interface + tcLister listers.TidbClusterLister + recorder record.EventRecorder } // NewRealTidbClusterControl creates a new TidbClusterControlInterface func NewRealTidbClusterControl(cli versioned.Interface, tcLister listers.TidbClusterLister, - recorder record.EventRecorder, - pdControl PDControlInterface) TidbClusterControlInterface { + recorder record.EventRecorder) TidbClusterControlInterface { return &realTidbClusterControl{ cli, tcLister, recorder, - pdControl, } } -func (rtc *realTidbClusterControl) UpdateMetaInfo(tc *v1alpha1.TidbCluster) (*v1alpha1.TidbCluster, error) { - pdClient := rtc.pdControl.GetPDClient(tc) - pdClient.GetCluster() - cluster, err := pdClient.GetCluster() - if err != nil { - return tc, fmt.Errorf("failed to get tidb cluster info from pd, TidbCluster: %s/%s, err: %v", tc.GetNamespace(), tc.GetName(), err) - } - clusterID := strconv.FormatUint(cluster.Id, 10) - labels := tc.GetLabels() - if labels == nil { - labels = map[string]string{} - } - setIfNotEmpty(labels, label.ClusterIDLabelKey, clusterID) - tc.Labels = labels - return tc, nil -} - func (rtc *realTidbClusterControl) UpdateTidbCluster(tc *v1alpha1.TidbCluster, newStatus *v1alpha1.TidbClusterStatus, oldStatus *v1alpha1.TidbClusterStatus) (*v1alpha1.TidbCluster, error) { ns := tc.GetNamespace() tcName := tc.GetName() @@ -145,7 +122,6 @@ type FakeTidbClusterControl struct { TcLister listers.TidbClusterLister TcIndexer cache.Indexer updateTidbClusterTracker requestTracker - updateMetaInfoTracker requestTracker } // NewFakeTidbClusterControl returns a FakeTidbClusterControl @@ -154,7 +130,6 @@ func NewFakeTidbClusterControl(tcInformer tcinformers.TidbClusterInformer) *Fake tcInformer.Lister(), tcInformer.Informer().GetIndexer(), requestTracker{0, nil, 0}, - requestTracker{0, nil, 0}, } } @@ -164,12 +139,6 @@ func (ssc *FakeTidbClusterControl) SetUpdateTidbClusterError(err error, after in ssc.updateTidbClusterTracker.after = after } -// SetUpdateMetaInfoError sets the error attributes of updateMetaInfoTracker -func (ssc *FakeTidbClusterControl) SetUpdateMetaInfoError(err error, after int) { - ssc.updateMetaInfoTracker.err = err - ssc.updateMetaInfoTracker.after = after -} - // UpdateTidbCluster updates the TidbCluster func (ssc *FakeTidbClusterControl) UpdateTidbCluster(tc *v1alpha1.TidbCluster, _ *v1alpha1.TidbClusterStatus, _ *v1alpha1.TidbClusterStatus) (*v1alpha1.TidbCluster, error) { defer ssc.updateTidbClusterTracker.inc() @@ -180,14 +149,3 @@ func (ssc *FakeTidbClusterControl) UpdateTidbCluster(tc *v1alpha1.TidbCluster, _ return tc, ssc.TcIndexer.Update(tc) } - -func (ssc *FakeTidbClusterControl) UpdateMetaInfo(tc *v1alpha1.TidbCluster) (*v1alpha1.TidbCluster, error) { - defer ssc.updateMetaInfoTracker.inc() - if ssc.updateMetaInfoTracker.errorReady() { - defer ssc.updateMetaInfoTracker.reset() - return tc, ssc.updateMetaInfoTracker.err - } - - tc.Labels = map[string]string{label.ClusterIDLabelKey: TestClusterID} - return tc, nil -} diff --git a/pkg/controller/tidbcluster_control_test.go b/pkg/controller/tidbcluster_control_test.go index 809acca6e7..c9a01c1db0 100644 --- a/pkg/controller/tidbcluster_control_test.go +++ b/pkg/controller/tidbcluster_control_test.go @@ -15,16 +15,14 @@ package controller import ( "errors" - "fmt" "testing" + "time" . "github.com/onsi/gomega" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned/fake" listers "github.com/pingcap/tidb-operator/pkg/client/listers/pingcap.com/v1alpha1" - "github.com/pingcap/tidb-operator/pkg/label" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -39,8 +37,7 @@ func TestTidbClusterControlUpdateTidbCluster(t *testing.T) { tc := newTidbCluster() tc.Spec.PD.Replicas = int32(5) fakeClient := &fake.Clientset{} - pdControl := NewFakePDControl() - control := NewRealTidbClusterControl(fakeClient, nil, recorder, pdControl) + control := NewRealTidbClusterControl(fakeClient, nil, recorder) fakeClient.AddReactor("update", "tidbclusters", func(action core.Action) (bool, runtime.Object, error) { update := action.(core.UpdateAction) return true, update.GetObject(), nil @@ -60,8 +57,7 @@ func TestTidbClusterControlUpdateTidbClusterConflictSuccess(t *testing.T) { fakeClient := &fake.Clientset{} indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) tcLister := listers.NewTidbClusterLister(indexer) - pdControl := NewFakePDControl() - control := NewRealTidbClusterControl(fakeClient, tcLister, recorder, pdControl) + control := NewRealTidbClusterControl(fakeClient, tcLister, recorder) conflict := false fakeClient.AddReactor("update", "tidbclusters", func(action core.Action) (bool, runtime.Object, error) { update := action.(core.UpdateAction) @@ -78,46 +74,6 @@ func TestTidbClusterControlUpdateTidbClusterConflictSuccess(t *testing.T) { g.Expect(events).To(HaveLen(0)) } -func TestRealTidbClusterControlUpdateMetaInfoSuccess(t *testing.T) { - g := NewGomegaWithT(t) - recorder := record.NewFakeRecorder(10) - tc := newTidbCluster() - tc.Spec.PD.Replicas = int32(5) - fakeClient := &fake.Clientset{} - pdControl := NewFakePDControl() - control := NewRealTidbClusterControl(fakeClient, nil, recorder, pdControl) - pdClient := NewFakePDClient() - pdControl.SetPDClient(tc, pdClient) - pdClient.AddReaction(GetClusterActionType, func(action *Action) (interface{}, error) { - cluster := &metapb.Cluster{ - Id: 1234, - } - return cluster, nil - }) - tc, err := control.UpdateMetaInfo(tc) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(tc.Labels[label.ClusterIDLabelKey]).NotTo(BeNil()) - g.Expect(tc.Labels[label.ClusterIDLabelKey]).To(Equal("1234")) -} - -func TestRealTidbClusterControlUpdateMetaInfoGetClusterFailed(t *testing.T) { - g := NewGomegaWithT(t) - recorder := record.NewFakeRecorder(10) - tc := newTidbCluster() - tc.Spec.PD.Replicas = int32(5) - fakeClient := &fake.Clientset{} - pdControl := NewFakePDControl() - control := NewRealTidbClusterControl(fakeClient, nil, recorder, pdControl) - pdClient := NewFakePDClient() - pdControl.SetPDClient(tc, pdClient) - pdClient.AddReaction(GetClusterActionType, func(action *Action) (interface{}, error) { - return nil, fmt.Errorf("error to get cluster") - }) - tc, err := control.UpdateMetaInfo(tc) - g.Expect(err).To(HaveOccurred()) - g.Expect(tc.Labels[label.ClusterIDLabelKey]).To(Equal("")) -} - func TestDeepEqualExceptHeartbeatTime(t *testing.T) { g := NewGomegaWithT(t) diff --git a/pkg/manager/meta/meta_manager.go b/pkg/manager/meta/meta_manager.go index dd57bb0dce..3ec61b03c1 100644 --- a/pkg/manager/meta/meta_manager.go +++ b/pkg/manager/meta/meta_manager.go @@ -27,7 +27,6 @@ import ( var errPVCNotFound = errors.New("PVC is not found") type metaManager struct { - tcControl controller.TidbClusterControlInterface pvcLister corelisters.PersistentVolumeClaimLister pvcControl controller.PVCControlInterface pvLister corelisters.PersistentVolumeLister @@ -38,7 +37,6 @@ type metaManager struct { // NewMetaManager returns a *metaManager func NewMetaManager( - tcControl controller.TidbClusterControlInterface, pvcLister corelisters.PersistentVolumeClaimLister, pvcControl controller.PVCControlInterface, pvLister corelisters.PersistentVolumeLister, @@ -47,7 +45,6 @@ func NewMetaManager( podControl controller.PodControlInterface, ) manager.Manager { return &metaManager{ - tcControl: tcControl, pvcLister: pvcLister, pvcControl: pvcControl, pvLister: pvLister, @@ -70,11 +67,6 @@ func (pmm *metaManager) Sync(tc *v1alpha1.TidbCluster) error { return err } - tc, err = pmm.tcControl.UpdateMetaInfo(tc) - if err != nil { - return err - } - for _, pod := range pods { // update meta info for pod _, err := pmm.podControl.UpdateMetaInfo(tc, pod) diff --git a/pkg/manager/meta/meta_manager_test.go b/pkg/manager/meta/meta_manager_test.go index cec501a108..2bcc43975e 100644 --- a/pkg/manager/meta/meta_manager_test.go +++ b/pkg/manager/meta/meta_manager_test.go @@ -20,8 +20,6 @@ import ( . "github.com/onsi/gomega" "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" - "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned/fake" - informers "github.com/pingcap/tidb-operator/pkg/client/informers/externalversions" "github.com/pingcap/tidb-operator/pkg/controller" "github.com/pingcap/tidb-operator/pkg/label" corev1 "k8s.io/api/core/v1" @@ -41,14 +39,12 @@ func TestMetaManagerSync(t *testing.T) { pvcHasLabels bool pvcHasVolumeName bool podRefPvc bool - tcUpdateErr bool podUpdateErr bool getClusterErr bool getMemberErr bool getStoreErr bool pvcUpdateErr bool pvUpdateErr bool - tcChanged bool podChanged bool pvcChanged bool pvChanged bool @@ -76,7 +72,7 @@ func TestMetaManagerSync(t *testing.T) { pod1.Spec = newPodSpec(v1alpha1.TiDBMemberType.String(), pvc1.GetName()) } - nmm, fakePodControl, fakePVCControl, fakePVControl, fakeTcControl, podIndexer, pvcIndexer, pvIndexer := newFakeMetaManager() + nmm, fakePodControl, fakePVCControl, fakePVControl, podIndexer, pvcIndexer, pvIndexer := newFakeMetaManager() err := podIndexer.Add(pod1) g.Expect(err).NotTo(HaveOccurred()) err = pvcIndexer.Add(pvc1) @@ -84,9 +80,6 @@ func TestMetaManagerSync(t *testing.T) { err = pvIndexer.Add(pv1) g.Expect(err).NotTo(HaveOccurred()) - if test.tcUpdateErr { - fakeTcControl.SetUpdateMetaInfoError(errors.NewInternalError(fmt.Errorf("set tidbCluster labels error")), 0) - } if test.podUpdateErr { fakePodControl.SetUpdatePodError(errors.NewInternalError(fmt.Errorf("API server failed")), 0) } @@ -107,24 +100,6 @@ func TestMetaManagerSync(t *testing.T) { } err = nmm.Sync(tc) - if test.tcUpdateErr { - g.Expect(err).To(HaveOccurred()) - - g.Expect(tcMetaInfoMatchDesire(tc)).To(Equal(false)) - - pod, err := nmm.podLister.Pods(ns).Get(pod1.Name) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(podMetaInfoMatchDesire(pod)).To(Equal(false)) - - pvc, err := nmm.pvcLister.PersistentVolumeClaims(ns).Get(pvc1.Name) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(pvcMetaInfoMatchDesire(pvc)).To(Equal(false)) - - pv, err := nmm.pvLister.Get(pv1.Name) - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(pvMetaInfoMatchDesire(ns, pv)).To(Equal(false)) - } - if test.podUpdateErr || test.getClusterErr || test.getMemberErr || test.getStoreErr { g.Expect(err).To(HaveOccurred()) @@ -161,12 +136,6 @@ func TestMetaManagerSync(t *testing.T) { g.Expect(pvMetaInfoMatchDesire(ns, pv)).To(Equal(false)) } - if test.tcChanged { - g.Expect(tcMetaInfoMatchDesire(tc)).To(Equal(true)) - } else { - g.Expect(tcMetaInfoMatchDesire(tc)).To(Equal(false)) - } - if test.podChanged { pod, err := nmm.podLister.Pods(ns).Get(pod1.Name) g.Expect(err).NotTo(HaveOccurred()) @@ -212,7 +181,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: true, pvcChanged: true, pvChanged: true, @@ -229,7 +197,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -246,7 +213,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: true, pvcChanged: true, pvChanged: true, @@ -263,7 +229,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: true, pvcChanged: true, pvChanged: false, @@ -280,7 +245,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: true, pvcChanged: false, pvChanged: false, @@ -297,7 +261,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -314,7 +277,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -331,7 +293,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -348,7 +309,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: true, pvcUpdateErr: false, pvUpdateErr: false, - tcChanged: true, podChanged: false, pvcChanged: false, pvChanged: false, @@ -365,7 +325,6 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: true, pvUpdateErr: false, - tcChanged: true, podChanged: true, pvcChanged: false, pvChanged: false, @@ -382,28 +341,10 @@ func TestMetaManagerSync(t *testing.T) { getStoreErr: false, pvcUpdateErr: false, pvUpdateErr: true, - tcChanged: true, podChanged: true, pvcChanged: true, pvChanged: false, }, - { - name: "tc update failed", - podHasLabels: true, - pvcHasLabels: true, - pvcHasVolumeName: true, - podRefPvc: true, - tcUpdateErr: true, - podUpdateErr: false, - getClusterErr: false, - getMemberErr: false, - getStoreErr: false, - pvcUpdateErr: false, - pvUpdateErr: false, - podChanged: false, - pvcChanged: false, - pvChanged: false, - }, } for i := range tests { @@ -416,7 +357,6 @@ func newFakeMetaManager() ( *controller.FakePodControl, *controller.FakePVCControl, *controller.FakePVControl, - *controller.FakeTidbClusterControl, cache.Indexer, cache.Indexer, cache.Indexer, @@ -432,24 +372,14 @@ func newFakeMetaManager() ( pvcControl := controller.NewFakePVCControl(pvcInformer) pvControl := controller.NewFakePVControl(pvInformer, pvcInformer) - cli := fake.NewSimpleClientset() - informerFactory := informers.NewSharedInformerFactory(cli, 0) - tcInformer := informerFactory.Pingcap().V1alpha1().TidbClusters() - tcControl := controller.NewFakeTidbClusterControl(tcInformer) - return &metaManager{ - tcControl, pvcInformer.Lister(), pvcControl, pvInformer.Lister(), pvControl, podInformer.Lister(), podControl, - }, podControl, pvcControl, pvControl, tcControl, podInformer.Informer().GetIndexer(), pvcInformer.Informer().GetIndexer(), pvInformer.Informer().GetIndexer() -} - -func tcMetaInfoMatchDesire(tc *v1alpha1.TidbCluster) bool { - return tc.Labels[label.ClusterIDLabelKey] == controller.TestClusterID + }, podControl, pvcControl, pvControl, podInformer.Informer().GetIndexer(), pvcInformer.Informer().GetIndexer(), pvInformer.Informer().GetIndexer() } func podMetaInfoMatchDesire(pod *corev1.Pod) bool { diff --git a/tests/e2e/create.go b/tests/e2e/create.go index 075ab29a28..ed091e4315 100644 --- a/tests/e2e/create.go +++ b/tests/e2e/create.go @@ -505,8 +505,6 @@ func metaSynced(tc *v1alpha1.TidbCluster) (bool, error) { return false, nil } - Expect(tc.Labels[label.ClusterIDLabelKey]).To(Equal(clusterID)) - outerLoop: for _, pod := range podList.Items { podName := pod.GetName()