controller

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2018 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultStorageClassName is the default storageClassName
	DefaultStorageClassName string
	// ClusterScoped controls whether operator should manage kubernetes cluster wide TiDB clusters
	ClusterScoped bool
)
View Source
var (
	TestStoreId     string = "000"
	TestMemberId    string = "111"
	TestClusterId   string = "222"
	TestAppName     string = "tikv"
	TestPodName     string = "pod-1"
	TestOwnerName   string = "tidbCluster"
	TestClusterName string = "test"
)
View Source
var ExternalTrafficPolicy string

ExternalTrafficPolicy denotes if this Service desires to route external traffic to node-local or cluster-wide endpoints.

Functions

func AnnProm

func AnnProm() map[string]string

AnnProm adds annotations for prometheus scraping metrics port is determined by container port in pod spec with name metrics

func DefaultPushGatewayRequest

func DefaultPushGatewayRequest() corev1.ResourceRequirements

DefaultPushGatewayRequest for the TiKV sidecar

func DeferClose

func DeferClose(c io.Closer, err *error)

DeferClose captures the error returned from closing (if an error occurs). This is designed to be used in a defer statement.

func GetOwnerRef

func GetOwnerRef(tc *v1alpha1.TidbCluster) metav1.OwnerReference

GetOwnerRef returns TidbCluster's OwnerReference

func GetPushgatewayImage

func GetPushgatewayImage(cluster *v1alpha1.TidbCluster) string

GetPushgatewayImage returns TidbCluster's pushgateway image

func GetServiceType

func GetServiceType(services []v1alpha1.Service, serviceName string) corev1.ServiceType

GetServiceType returns member's service type

func MonitorMemberName

func MonitorMemberName(clusterName string) string

MonitorMemberName returns monitor member name

func PDMemberName

func PDMemberName(clusterName string) string

PDMemberName returns pd member name

func PDPeerMemberName

func PDPeerMemberName(clusterName string) string

PDPeerMemberName returns pd peer service name

func PriTiDBMemberName

func PriTiDBMemberName(clusterName string) string

PriTiDBMemberName returns privileged tidb member name

func TiDBMemberName

func TiDBMemberName(clusterName string) string

TiDBMemberName returns tidb member name

func TiKVCapacity

func TiKVCapacity(limits *v1alpha1.ResourceRequirement) string

TiKVCapacity returns string resource requirement, tikv uses GB, TB as unit suffix, but it actually means GiB, TiB

func TiKVMemberName

func TiKVMemberName(clusterName string) string

TiKVMemberName returns tikv member name

func TiKVPeerMemberName

func TiKVPeerMemberName(clusterName string) string

TiKVPeerMemberName returns tikv peer service name

Types

type Action

type Action struct {
	ID     uint64
	Name   string
	Labels map[string]string
}

type ActionType

type ActionType string
const (
	GetHealthActionType          ActionType = "GetHealth"
	GetConfigActionType          ActionType = "GetConfig"
	GetClusterActionType         ActionType = "GetCluster"
	GetMembersActionType         ActionType = "GetMembers"
	GetStoresActionType          ActionType = "GetStores"
	GetTombStoneStoresActionType ActionType = "GetTombStoneStores"
	GetStoreActionType           ActionType = "GetStore"
	DeleteStoreActionType        ActionType = "DeleteStore"
	DeleteMemberByIDActionType   ActionType = "DeleteMemberByID"
	DeleteMemberActionType       ActionType = "DeleteMember "
	SetStoreLabelsActionType     ActionType = "SetStoreLabels"
	BeginEvictLeaderActionType   ActionType = "BeginEvictLeader"
	EndEvictLeaderActionType     ActionType = "EndEvictLeader"
)

type FakePDClient

type FakePDClient struct {
	// contains filtered or unexported fields
}

func NewFakePDClient

func NewFakePDClient() *FakePDClient

func (*FakePDClient) AddReaction

func (pc *FakePDClient) AddReaction(actionType ActionType, reaction Reaction)

func (*FakePDClient) BeginEvictLeader

func (pc *FakePDClient) BeginEvictLeader(storeID uint64) error

func (*FakePDClient) DeleteMember

func (pc *FakePDClient) DeleteMember(name string) error

func (*FakePDClient) DeleteMemberByID

func (pc *FakePDClient) DeleteMemberByID(id uint64) error

func (*FakePDClient) DeleteStore

func (pc *FakePDClient) DeleteStore(id uint64) error

func (*FakePDClient) EndEvictLeader

func (pc *FakePDClient) EndEvictLeader(storeID uint64) error

func (*FakePDClient) GetCluster

func (pc *FakePDClient) GetCluster() (*metapb.Cluster, error)

func (*FakePDClient) GetConfig

func (pc *FakePDClient) GetConfig() (*server.Config, error)

func (*FakePDClient) GetHealth

func (pc *FakePDClient) GetHealth() (*HealthInfo, error)

func (*FakePDClient) GetMembers

func (pc *FakePDClient) GetMembers() (*MembersInfo, error)

func (*FakePDClient) GetStore

func (pc *FakePDClient) GetStore(id uint64) (*StoreInfo, error)

func (*FakePDClient) GetStores

func (pc *FakePDClient) GetStores() (*StoresInfo, error)

func (*FakePDClient) GetTombStoneStores

func (pc *FakePDClient) GetTombStoneStores() (*StoresInfo, error)

func (*FakePDClient) SetStoreLabels

func (pc *FakePDClient) SetStoreLabels(storeID uint64, labels map[string]string) (bool, error)

SetStoreLabels sets TiKV labels

type FakePDControl

type FakePDControl struct {
	// contains filtered or unexported fields
}

func NewFakePDControl

func NewFakePDControl() *FakePDControl

func (*FakePDControl) GetPDClient

func (pdc *FakePDControl) GetPDClient(tc *v1alpha1.TidbCluster) PDClient

GetPDClient provide a PDClient of real pd cluster,if the PDClient not existing, it will create new one.

func (*FakePDControl) SetPDClient

func (fpc *FakePDControl) SetPDClient(tc *v1alpha1.TidbCluster, pdclient PDClient)

type FakePVCControl

type FakePVCControl struct {
	PVCIndexer cache.Indexer
	// contains filtered or unexported fields
}

FakePVCControl is a fake PVCControlInterface

func NewFakePVCControl

func NewFakePVCControl(pvcInformer coreinformers.PersistentVolumeClaimInformer) *FakePVCControl

NewFakePVCControl returns a FakePVCControl

func (*FakePVCControl) DeletePVC

DeletePVC deletes the pvc

func (*FakePVCControl) SetDeletePVCError

func (fpc *FakePVCControl) SetDeletePVCError(err error, after int)

SetDeletePVCError sets the error attributes of deletePVCTracker

func (*FakePVCControl) SetUpdatePVCError

func (fpc *FakePVCControl) SetUpdatePVCError(err error, after int)

SetUpdatePVCError sets the error attributes of updatePVCTracker

func (*FakePVCControl) UpdateMetaInfo

func (fpc *FakePVCControl) UpdateMetaInfo(tc *v1alpha1.TidbCluster, pvc *corev1.PersistentVolumeClaim, pod *corev1.Pod) error

UpdateMetaInfo updates the meta info of pvc

func (*FakePVCControl) UpdatePVC

Update updates the annotation, labels and spec of pvc

type FakePVControl

type FakePVControl struct {
	PVCLister corelisters.PersistentVolumeClaimLister
	PVIndexer cache.Indexer
	// contains filtered or unexported fields
}

FakePVControl is a fake PVControlInterface

func NewFakePVControl

NewFakePVControl returns a FakePVControl

func (*FakePVControl) PatchPVReclaimPolicy

func (fpc *FakePVControl) PatchPVReclaimPolicy(tc *v1alpha1.TidbCluster, pv *corev1.PersistentVolume, reclaimPolicy corev1.PersistentVolumeReclaimPolicy) error

PatchPVReclaimPolicy patchs the reclaim policy of PV

func (*FakePVControl) SetUpdatePVError

func (fpc *FakePVControl) SetUpdatePVError(err error, after int)

SetUpdatePVError sets the error attributes of updatePVTracker

func (*FakePVControl) UpdateMetaInfo

func (fpc *FakePVControl) UpdateMetaInfo(tc *v1alpha1.TidbCluster, pv *corev1.PersistentVolume) error

UpdateMetaInfo update the meta info of pv

type FakePodControl

type FakePodControl struct {
	PodIndexer cache.Indexer
	// contains filtered or unexported fields
}

FakePodControl is a fake PodControlInterface

func NewFakePodControl

func NewFakePodControl(podInformer coreinformers.PodInformer) *FakePodControl

NewFakePodControl returns a FakePodControl

func (*FakePodControl) SetGetClusterError

func (fpc *FakePodControl) SetGetClusterError(err error, after int)

SetGetClusterError sets the error attributes of getClusterTracker

func (*FakePodControl) SetGetMemberError

func (fpc *FakePodControl) SetGetMemberError(err error, after int)

SetGetMemberError sets the error attributes of getMemberTracker

func (*FakePodControl) SetGetStoreError

func (fpc *FakePodControl) SetGetStoreError(err error, after int)

SetGetStoreError sets the error attributes of getStoreTracker

func (*FakePodControl) SetUpdatePodError

func (fpc *FakePodControl) SetUpdatePodError(err error, after int)

SetUpdatePodError sets the error attributes of updatePodTracker

func (*FakePodControl) UpdateMetaInfo

func (fpc *FakePodControl) UpdateMetaInfo(tc *v1alpha1.TidbCluster, pod *corev1.Pod) error

UpdateMetaInfo update the meta info of Pod

type FakeServiceControl

type FakeServiceControl struct {
	SvcLister  corelisters.ServiceLister
	SvcIndexer cache.Indexer
	TcLister   v1listers.TidbClusterLister
	TcIndexer  cache.Indexer
	// contains filtered or unexported fields
}

FakeServiceControl is a fake ServiceControlInterface

func NewFakeServiceControl

func NewFakeServiceControl(svcInformer coreinformers.ServiceInformer, tcInformer tcinformers.TidbClusterInformer) *FakeServiceControl

NewFakeServiceControl returns a FakeServiceControl

func (*FakeServiceControl) CreateService

func (ssc *FakeServiceControl) CreateService(tc *v1alpha1.TidbCluster, svc *corev1.Service) error

CreateService adds the service to SvcIndexer

func (*FakeServiceControl) DeleteService

func (ssc *FakeServiceControl) DeleteService(tc *v1alpha1.TidbCluster, svc *corev1.Service) error

DeleteService deletes the service of SvcIndexer

func (*FakeServiceControl) SetCreateServiceError

func (ssc *FakeServiceControl) SetCreateServiceError(err error, after int)

SetCreateServiceError sets the error attributes of createServiceTracker

func (*FakeServiceControl) SetDeleteServiceError

func (ssc *FakeServiceControl) SetDeleteServiceError(err error, after int)

SetDeleteServiceError sets the error attributes of deleteServiceTracker

func (*FakeServiceControl) SetUpdateServiceError

func (ssc *FakeServiceControl) SetUpdateServiceError(err error, after int)

SetUpdateServiceError sets the error attributes of updateServiceTracker

func (*FakeServiceControl) UpdateService

func (ssc *FakeServiceControl) UpdateService(tc *v1alpha1.TidbCluster, svc *corev1.Service) error

UpdateService updates the service of SvcIndexer

type FakeStatefulSetControl

type FakeStatefulSetControl struct {
	SetLister  appslisters.StatefulSetLister
	SetIndexer cache.Indexer
	TcLister   v1listers.TidbClusterLister
	TcIndexer  cache.Indexer
	// contains filtered or unexported fields
}

FakeStatefulSetControl is a fake StatefulSetControlInterface

func NewFakeStatefulSetControl

func NewFakeStatefulSetControl(setInformer appsinformers.StatefulSetInformer, tcInformer tcinformers.TidbClusterInformer) *FakeStatefulSetControl

NewFakeStatefulSetControl returns a FakeStatefulSetControl

func (*FakeStatefulSetControl) CreateStatefulSet

func (ssc *FakeStatefulSetControl) CreateStatefulSet(tc *v1alpha1.TidbCluster, set *apps.StatefulSet) error

CreateStatefulSet adds the statefulset to SetIndexer

func (*FakeStatefulSetControl) DeleteStatefulSet

func (ssc *FakeStatefulSetControl) DeleteStatefulSet(tc *v1alpha1.TidbCluster, set *apps.StatefulSet) error

DeleteStatefulSet deletes the statefulset of SetIndexer

func (*FakeStatefulSetControl) SetCreateStatefulSetError

func (ssc *FakeStatefulSetControl) SetCreateStatefulSetError(err error, after int)

SetCreateStatefulSetError sets the error attributes of createStatefulSetTracker

func (*FakeStatefulSetControl) SetDeleteStatefulSetError

func (ssc *FakeStatefulSetControl) SetDeleteStatefulSetError(err error, after int)

SetDeleteStatefulSetError sets the error attributes of deleteStatefulSetTracker

func (*FakeStatefulSetControl) SetStatusChange

func (ssc *FakeStatefulSetControl) SetStatusChange(fn func(*apps.StatefulSet))

func (*FakeStatefulSetControl) SetUpdateStatefulSetError

func (ssc *FakeStatefulSetControl) SetUpdateStatefulSetError(err error, after int)

SetUpdateStatefulSetError sets the error attributes of updateStatefulSetTracker

func (*FakeStatefulSetControl) UpdateStatefulSet

func (ssc *FakeStatefulSetControl) UpdateStatefulSet(tc *v1alpha1.TidbCluster, set *apps.StatefulSet) error

UpdateStatefulSet updates the statefulset of SetIndexer

type HealthInfo

type HealthInfo struct {
	Healths []MemberHealth
}

HealthInfo define PD's healthy info

type MemberHealth

type MemberHealth struct {
	Name       string   `json:"name"`
	MemberID   uint64   `json:"member_id"`
	ClientUrls []string `json:"client_urls"`
	Health     bool     `json:"health"`
}

MemberHealth define a pd member's healthy info

type MembersInfo

type MembersInfo struct {
	Header     *pdpb.ResponseHeader `json:"header,omitempty"`
	Members    []*pdpb.Member       `json:"members,omitempty"`
	Leader     *pdpb.Member         `json:"leader,omitempty"`
	EtcdLeader *pdpb.Member         `json:"etcd_leader,omitempty"`
}

MembersInfo is PD members info returned from PD RESTful interface type Members map[string][]*pdpb.Member

type MetaStore

type MetaStore struct {
	*metapb.Store
	StateName string `json:"state_name"`
}

MetaStore is TiKV store status defined in protobuf

type NotFoundReaction

type NotFoundReaction struct {
	// contains filtered or unexported fields
}

func (*NotFoundReaction) Error

func (nfr *NotFoundReaction) Error() string

type PDClient

type PDClient interface {
	// GetHealth return the PD's health info
	GetHealth() (*HealthInfo, error)
	// GetConfig returns PD's config
	GetConfig() (*server.Config, error)
	// GetCluster return used when syncing pod labels.
	GetCluster() (*metapb.Cluster, error)
	// GetMembers returns all PD members from cluster
	GetMembers() (*MembersInfo, error)
	// GetStores lists all TiKV stores from cluster
	GetStores() (*StoresInfo, error)
	// GetTombStoneStores lists all tombstone stores from cluster
	GetTombStoneStores() (*StoresInfo, error)
	// GetStore gets a TiKV store for a specific store id from cluster
	GetStore(storeID uint64) (*StoreInfo, error)
	// storeLabelsEqualNodeLabels compares store labels with node labels
	// for historic reasons, PD stores TiKV labels as []*StoreLabel which is a key-value pair slice
	SetStoreLabels(storeID uint64, labels map[string]string) (bool, error)
	// DeleteStore deletes a TiKV store from cluster
	DeleteStore(storeID uint64) error
	// DeleteMember delete a PD member from cluster
	DeleteMember(name string) error
	// DeleteMemberByID delete a PD member from cluster
	DeleteMemberByID(memberID uint64) error
	// BeginEvictLeader initiates leader eviction for a storeID.
	// This is used when upgrading a pod.
	BeginEvictLeader(storeID uint64) error
	// EndEvictLeader is used at the end of pod upgrade.
	EndEvictLeader(storeID uint64) error
}

PDClient provider pd server's api

func NewPDClient

func NewPDClient(url string, timeout time.Duration) PDClient

NewPDClient return a new PDClient

type PDControlInterface

type PDControlInterface interface {
	// GetPDClient provide PDClient of the tidb cluster.
	GetPDClient(tc *v1alpha1.TidbCluster) PDClient
}

PDControlInterface is an interface that knows how to manage and get tidb cluster's PD client

func NewDefaultPDControl

func NewDefaultPDControl() PDControlInterface

NewDefaultPDControl return a defaultPDControl instance

type PVCControlInterface

PVCControlInterface manages PVCs used in TidbCluster

func NewRealPVCControl

NewRealPVCControl creates a new PVCControlInterface

type PVControlInterface

type PVControlInterface interface {
	PatchPVReclaimPolicy(*v1alpha1.TidbCluster, *corev1.PersistentVolume, corev1.PersistentVolumeReclaimPolicy) error
	UpdateMetaInfo(*v1alpha1.TidbCluster, *corev1.PersistentVolume) error
}

PVControlInterface manages PVs used in TidbCluster

func NewRealPVControl

func NewRealPVControl(
	kubeCli kubernetes.Interface,
	pvcLister corelisters.PersistentVolumeClaimLister,
	recorder record.EventRecorder,
) PVControlInterface

NewRealPVControl creates a new PVControlInterface

type PodControlInterface

type PodControlInterface interface {
	UpdateMetaInfo(*v1alpha1.TidbCluster, *corev1.Pod) error
}

PodControlInterface manages Pods used in TidbCluster

func NewRealPodControl

func NewRealPodControl(
	kubeCli kubernetes.Interface,
	pdControl PDControlInterface,
	recorder record.EventRecorder,
) PodControlInterface

NewRealPodControl creates a new PodControlInterface

type Reaction

type Reaction func(action *Action) (interface{}, error)

type ServiceControlInterface

type ServiceControlInterface interface {
	CreateService(*v1alpha1.TidbCluster, *corev1.Service) error
	UpdateService(*v1alpha1.TidbCluster, *corev1.Service) error
	DeleteService(*v1alpha1.TidbCluster, *corev1.Service) error
}

ServiceControlInterface manages Services used in TidbCluster

func NewRealServiceControl

func NewRealServiceControl(kubeCli kubernetes.Interface, svcLister corelisters.ServiceLister, recorder record.EventRecorder) ServiceControlInterface

NewRealServiceControl creates a new ServiceControlInterface

type StatefulSetControlInterface

type StatefulSetControlInterface interface {
	// CreateStatefulSet creates a StatefulSet in a TidbCluster.
	CreateStatefulSet(*v1alpha1.TidbCluster, *apps.StatefulSet) error
	// UpdateStatefulSet updates a StatefulSet in a TidbCluster.
	UpdateStatefulSet(*v1alpha1.TidbCluster, *apps.StatefulSet) error
	// DeleteStatefulSet deletes a StatefulSet in a TidbCluster.
	DeleteStatefulSet(*v1alpha1.TidbCluster, *apps.StatefulSet) error
}

StatefulSetControlInterface defines the interface that uses to create, update, and delete StatefulSets,

func NewRealStatefuSetControl

func NewRealStatefuSetControl(kubeCli kubernetes.Interface, setLister appslisters.StatefulSetLister, recorder record.EventRecorder) StatefulSetControlInterface

NewRealStatefuSetControl returns a StatefulSetControlInterface

type StoreInfo

type StoreInfo struct {
	Store  *MetaStore   `json:"store"`
	Status *StoreStatus `json:"status"`
}

StoreInfo is a single store info returned from PD RESTful interface

type StoreStatus

type StoreStatus struct {
	Capacity           typeutil.ByteSize `json:"capacity"`
	Available          typeutil.ByteSize `json:"available"`
	LeaderCount        int               `json:"leader_count"`
	RegionCount        int               `json:"region_count"`
	SendingSnapCount   uint32            `json:"sending_snap_count"`
	ReceivingSnapCount uint32            `json:"receiving_snap_count"`
	ApplyingSnapCount  uint32            `json:"applying_snap_count"`
	IsBusy             bool              `json:"is_busy"`

	StartTS         time.Time         `json:"start_ts"`
	LastHeartbeatTS time.Time         `json:"last_heartbeat_ts"`
	Uptime          typeutil.Duration `json:"uptime"`
}

StoreStatus is TiKV store status returned from PD RESTful interface

type StoresInfo

type StoresInfo struct {
	Count  int          `json:"count"`
	Stores []*StoreInfo `json:"stores"`
}

StoresInfo is stores info returned from PD RESTful interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL