Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojingchen committed Oct 18, 2018
1 parent 5429058 commit c0c361a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 35 deletions.
28 changes: 2 additions & 26 deletions pkg/manager/member/pd_upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func (pu *pdUpgrader) gracefulUpgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Sta

revision, exist := pod.Labels[apps.ControllerRevisionHashLabelKey]
if !exist {
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd pod: [%s] have not label: %s", ns, tcName, podName, apps.ControllerRevisionHashLabelKey)
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd pod: [%s] has not label: %s", ns, tcName, podName, apps.ControllerRevisionHashLabelKey)
}

if revision == tc.Status.PD.StatefulSet.UpdateRevision {
if member, exist := tc.Status.PD.Members[podName]; !exist || !member.Health {
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd upgraded pod: [%s] are not ready", ns, tcName, podName)
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd upgraded pod: [%s] is not ready", ns, tcName, podName)
}
continue
}
Expand Down Expand Up @@ -147,30 +147,6 @@ func (pu *pdUpgrader) upgradePDPod(tc *v1alpha1.TidbCluster, ordinal int32, newS
return nil
}

func (pu *pdUpgrader) pdStatefulSetIsUpgrading(set *apps.StatefulSet, tc *v1alpha1.TidbCluster) (bool, error) {
if statefulSetIsUpgrading(set) {
return true, nil
}
selector, err := label.New().Cluster(tc.GetName()).PD().Selector()
if err != nil {
return false, err
}
pdPods, err := pu.podLister.Pods(tc.GetNamespace()).List(selector)
if err != nil {
return false, err
}
for _, pod := range pdPods {
revisionHash, exist := pod.Labels[apps.ControllerRevisionHashLabelKey]
if !exist {
return false, nil
}
if revisionHash != tc.Status.PD.StatefulSet.UpdateRevision {
return true, nil
}
}
return false, nil
}

func (pu *pdUpgrader) transferPDLeaderTo(tc *v1alpha1.TidbCluster, targetName string) error {
return pu.pdControl.GetPDClient(tc).TransferPDLeader(targetName)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/member/pd_upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestPDUpgraderUpgrade(t *testing.T) {
changePods: nil,
transferLeaderErr: false,
errExpectFn: func(g *GomegaWithT, err error) {
g.Expect(err.Error()).To(Equal(fmt.Sprintf("tidbcluster: [default/upgrader]'s pd upgraded pod: [%s] are not ready", pdPodName(upgradeTcName, 2))))
g.Expect(err.Error()).To(Equal(fmt.Sprintf("tidbcluster: [default/upgrader]'s pd upgraded pod: [%s] is not ready", pdPodName(upgradeTcName, 2))))
},
expectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster, newSet *apps.StatefulSet) {
g.Expect(tc.Status.PD.Phase).To(Equal(v1alpha1.UpgradePhase))
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/member/tidb_upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (tdu *tidbUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Stateful
}
revision, exist := pod.Labels[apps.ControllerRevisionHashLabelKey]
if !exist {
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s tidb pod: [%s] have not label: %s", ns, tcName, podName, apps.ControllerRevisionHashLabelKey)
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s tidb pod: [%s] has not label: %s", ns, tcName, podName, apps.ControllerRevisionHashLabelKey)
}

if revision == tc.Status.TiDB.StatefulSet.UpdateRevision {
Expand Down
14 changes: 7 additions & 7 deletions pkg/manager/member/tikv_upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,26 @@ func (tku *tikvUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Stateful
setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition)
for i := tc.Status.TiKV.StatefulSet.Replicas - 1; i >= 0; i-- {
store := tku.getStoreByOrdinal(tc, i)
if store == nil {
continue
}
podName := tikvPodName(tcName, i)
pod, err := tku.podLister.Pods(ns).Get(podName)
if err != nil {
return err
}
revision, exist := pod.Labels[apps.ControllerRevisionHashLabelKey]
if !exist {
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s tikv pod: [%s] have not label: %s", ns, tcName, podName, apps.ControllerRevisionHashLabelKey)
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s tikv pod: [%s] has not label: %s", ns, tcName, podName, apps.ControllerRevisionHashLabelKey)
}

if store == nil {
continue
}
if revision == tc.Status.TiKV.StatefulSet.UpdateRevision {

if pod.Status.Phase != corev1.PodRunning {
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s upgraded tikv pods are not all running", ns, tcName)
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s upgraded tikv pod: [%s] is not running", ns, tcName, podName)
}
if store.State != v1alpha1.TiKVStateUp {
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s upgraded tikv are not all ready", ns, tcName)
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s upgraded tikv pod: [%s] is not all ready", ns, tcName, podName)
}
err := tku.endEvictLeader(tc, i)
if err != nil {
Expand Down Expand Up @@ -137,7 +137,7 @@ func (tku *tikvUpgrader) upgradeTiKVPod(tc *v1alpha1.TidbCluster, ordinal int32,
}
}

return controller.RequeueErrorf("tidbcluster: [%s/%s] have not find store status of tikv pod: [%s]", ns, tcName, upgradePodName)
return controller.RequeueErrorf("tidbcluster: [%s/%s] has no store status found for tikv pod: [%s]", ns, tcName, upgradePodName)
}

func (tku *tikvUpgrader) readyToUpgrade(upgradePod *corev1.Pod, store v1alpha1.TiKVStore) bool {
Expand Down

0 comments on commit c0c361a

Please sign in to comment.