func (le *LeaderElector) IsLeader() bool {
	return le.observedRecord.HolderIdentity == le.config.Lock.Identity()
}
IsLeader returns true if the last observed leader was this client else returns false.
package leaderelection
import (
	"fmt"
	"reflect"
	"time"
	"k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/runtime"
	"k8s.io/apimachinery/pkg/util/wait"
	rl "k8s.io/client-go/tools/leaderelection/resourcelock"
	"github.com/golang/glog"
)
const (
	JitterFactor = 1.2
)
func NewLeaderElector(lec LeaderElectionConfig) (*LeaderElector, error) {
	if lec.LeaseDuration <= lec.RenewDeadline {
		return nil, fmt.Errorf("leaseDuration must be greater than renewDeadline")
	}
	if lec.RenewDeadline <= time.Duration(JitterFactor*float64(lec.RetryPeriod)) {
		return nil, fmt.Errorf("renewDeadline must be greater than retryPeriod*JitterFactor")
	}
	if lec.Lock == nil {
		return nil, fmt.Errorf("Lock must not be nil.")
	}
	return &LeaderElector{
		config: lec,
	}, nil
}
type LeaderElectionConfig struct {
	Lock rl.Interface
	LeaseDuration time.Duration
	RenewDeadline time.Duration
	RetryPeriod time.Duration
	Callbacks LeaderCallbacks
}
type LeaderCallbacks struct {
	OnStartedLeading func(stop <-chan struct{})
	OnStoppedLeading func()
	OnNewLeader func(identity string)
}
type LeaderElector struct {
	config LeaderElectionConfig
	observedRecord rl.LeaderElectionRecord
	observedTime   time.Time
	reportedLeader string
}
func (le *LeaderElector) Run() {
	defer func() {
		runtime.HandleCrash()
		le.config.Callbacks.OnStoppedLeading()
	}()
	le.acquire()
	stop := make(chan struct{})
	go le.config.Callbacks.OnStartedLeading(stop)
	le.renew()
	close(stop)
}
func RunOrDie(lec LeaderElectionConfig) {
	le, err := NewLeaderElector(lec)
	if err != nil {
		panic(err)
	}
	le.Run()
}
func (le *LeaderElector) GetLeader() string {
	return le.observedRecord.HolderIdentity
}