Skip to content

Commit

Permalink
scheduler: inject a failure by pod annotation (#716)
Browse files Browse the repository at this point in the history
scheduler: inject a failure by pod label

This can be useful for testing scheduling failures.
You can for example add it to monitor-deployment
along with changing the scheduler to the custom scheduler.
  • Loading branch information
gregwebs authored Aug 7, 2019
1 parent 8bda658 commit 46c7b76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
StoreIDLabelKey string = "tidb.pingcap.com/store-id"
// MemberIDLabelKey is member id label key
MemberIDLabelKey string = "tidb.pingcap.com/member-id"
// AnnFailTiDBScheduler is for injecting a failure into the TiDB custom scheduler
// A pod with this annotation will produce an error when scheduled.
AnnFailTiDBScheduler string = "tidb.pingcap.com/fail-scheduler"
// AnnPodNameKey is pod name annotation key used in PV/PVC for synchronizing tidb cluster meta info
AnnPodNameKey string = "tidb.pingcap.com/pod-name"
// AnnPVCDeferDeleting is pvc defer deletion annotation key used in PVC for defer deleting PVC
Expand Down
16 changes: 16 additions & 0 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package scheduler

import (
"fmt"
"github.com/golang/glog"
"github.com/pingcap/tidb-operator/pkg/client/clientset/versioned"
"github.com/pingcap/tidb-operator/pkg/features"
Expand Down Expand Up @@ -79,6 +80,12 @@ func (s *scheduler) Filter(args *schedulerapiv1.ExtenderArgs) (*schedulerapiv1.E
podName := pod.GetName()
kubeNodes := args.Nodes.Items

if pod.Annotations != nil {
if _, ok := pod.Annotations[label.AnnFailTiDBScheduler]; ok {
return nil, FailureError{PodName: pod.Name}
}
}

var instanceName string
var exist bool
if instanceName, exist = pod.Labels[label.InstanceLabelKey]; !exist {
Expand Down Expand Up @@ -118,6 +125,15 @@ func (s *scheduler) Filter(args *schedulerapiv1.ExtenderArgs) (*schedulerapiv1.E
}, nil
}

// FailureError is returned when the FailTiDBSchedulerLabelKey is seen
type FailureError struct {
PodName string
}

func (ferr FailureError) Error() string {
return fmt.Sprintf("pod %s had an intentional failure injected", ferr.PodName)
}

// We don't pass `prioritizeVerb` to kubernetes scheduler extender's config file, this method will not be called.
func (s *scheduler) Priority(args *schedulerapiv1.ExtenderArgs) (schedulerapiv1.HostPriorityList, error) {
result := schedulerapiv1.HostPriorityList{}
Expand Down

0 comments on commit 46c7b76

Please sign in to comment.