Skip to content

Commit

Permalink
cherry pick pingcap#2587 to release-1.1
Browse files Browse the repository at this point in the history
Signed-off-by: sre-bot <sre-bot@pingcap.com>
  • Loading branch information
PengJi authored and sre-bot committed Jun 10, 2020
1 parent b88761b commit d99193b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/controller/tidbcluster/tidb_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func NewController(
tikvFailover,
tikvScaler,
tikvUpgrader,
recorder,
),
mm.NewTiDBMemberManager(
setControl,
Expand Down
1 change: 1 addition & 0 deletions pkg/manager/member/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
const (
unHealthEventReason = "Unhealthy"
unHealthEventMsgPattern = "%s pod[%s] is unhealthy, msg:%s"
FailedSetStoreLabels = "FailedSetStoreLabels"
)

// Failover implements the logic for pd/tikv/tidb's failover and recovery.
Expand Down
10 changes: 8 additions & 2 deletions pkg/manager/member/tikv_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
v1 "k8s.io/client-go/listers/apps/v1"
corelisters "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
"k8s.io/utils/pointer"
)
Expand All @@ -62,6 +63,7 @@ type tikvMemberManager struct {
tikvFailover Failover
tikvScaler Scaler
tikvUpgrader Upgrader
recorder record.EventRecorder
tikvStatefulSetIsUpgradingFn func(corelisters.PodLister, pdapi.PDControlInterface, *apps.StatefulSet, *v1alpha1.TidbCluster) (bool, error)
}

Expand All @@ -78,7 +80,8 @@ func NewTiKVMemberManager(
autoFailover bool,
tikvFailover Failover,
tikvScaler Scaler,
tikvUpgrader Upgrader) manager.Manager {
tikvUpgrader Upgrader,
recorder record.EventRecorder) manager.Manager {
kvmm := tikvMemberManager{
pdControl: pdControl,
podLister: podLister,
Expand All @@ -92,6 +95,7 @@ func NewTiKVMemberManager(
tikvFailover: tikvFailover,
tikvScaler: tikvScaler,
tikvUpgrader: tikvUpgrader,
recorder: recorder,
}
kvmm.tikvStatefulSetIsUpgradingFn = tikvStatefulSetIsUpgrading
return &kvmm
Expand Down Expand Up @@ -764,7 +768,9 @@ func (tkmm *tikvMemberManager) setStoreLabelsForTiKV(tc *v1alpha1.TidbCluster) (
if !tkmm.storeLabelsEqualNodeLabels(store.Store.Labels, ls) {
set, err := pdCli.SetStoreLabels(store.Store.Id, ls)
if err != nil {
klog.Warningf("failed to set pod: [%s/%s]'s store labels: %v", ns, podName, ls)
msg := fmt.Sprintf("failed to set labels %v for store (id: %d, pod: %s/%s): %v ",
ls, store.Store.Id, ns, podName, err)
tkmm.recorder.Event(tc, corev1.EventTypeWarning, FailedSetStoreLabels, msg)
continue
}
if set {
Expand Down
3 changes: 3 additions & 0 deletions pkg/manager/member/tikv_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
kubefake "k8s.io/client-go/kubernetes/fake"
corelisters "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/utils/pointer"
)

Expand Down Expand Up @@ -1454,6 +1455,7 @@ func newFakeTiKVMemberManager(tc *v1alpha1.TidbCluster) (
nodeInformer := kubeinformers.NewSharedInformerFactory(kubeCli, 0).Core().V1().Nodes()
tikvScaler := NewFakeTiKVScaler()
tikvUpgrader := NewFakeTiKVUpgrader()
recorder := record.NewFakeRecorder(10)
genericControl := controller.NewFakeGenericControl()

tmm := &tikvMemberManager{
Expand All @@ -1467,6 +1469,7 @@ func newFakeTiKVMemberManager(tc *v1alpha1.TidbCluster) (
svcLister: svcInformer.Lister(),
tikvScaler: tikvScaler,
tikvUpgrader: tikvUpgrader,
recorder: recorder,
}
tmm.tikvStatefulSetIsUpgradingFn = tikvStatefulSetIsUpgrading
return tmm, setControl, svcControl, pdClient, podInformer.Informer().GetIndexer(), nodeInformer.Informer().GetIndexer()
Expand Down

0 comments on commit d99193b

Please sign in to comment.