Documentation ¶
Index ¶
- Constants
- func ConcatRawRecord(primaryRaw, secondaryRaw []byte) []byte
- func LeaderElectionRecordToLeaseSpec(ler *LeaderElectionRecord) coordinationv1.LeaseSpec
- type EventRecorder
- type Interface
- type LeaderElectionRecord
- type LeaseLock
- func (ll *LeaseLock) Create(ctx context.Context, ler LeaderElectionRecord) error
- func (ll *LeaseLock) Describe() string
- func (ll *LeaseLock) Get(ctx context.Context) (*LeaderElectionRecord, []byte, error)
- func (ll *LeaseLock) Identity() string
- func (ll *LeaseLock) RecordEvent(s string)
- func (ll *LeaseLock) Update(ctx context.Context, ler LeaderElectionRecord) error
- type MultiLock
- func (ml *MultiLock) Create(ctx context.Context, ler LeaderElectionRecord) error
- func (ml *MultiLock) Describe() string
- func (ml *MultiLock) Get(ctx context.Context) (*LeaderElectionRecord, []byte, error)
- func (ml *MultiLock) Identity() string
- func (ml *MultiLock) RecordEvent(s string)
- func (ml *MultiLock) Update(ctx context.Context, ler LeaderElectionRecord) error
- type ResourceLockConfig
Constants ¶
const ( LeaderElectionRecordAnnotationKey = "control-plane.alpha.kubernetes.io/leader" LeasesResourceLock = "leases" // When using EndpointsLeasesResourceLock, you need to ensure that // API Priority & Fairness is configured with non-default flow-schema // that will catch the necessary operations on leader-election related // endpoint objects. // // The example of such flow scheme could look like this: // apiVersion: flowcontrol.apiserver.k8s.io/v1beta2 // kind: FlowSchema // metadata: // name: my-leader-election // spec: // distinguisherMethod: // type: ByUser // matchingPrecedence: 200 // priorityLevelConfiguration: // name: leader-election # reference the <leader-election> PL // rules: // - resourceRules: // - apiGroups: // - "" // namespaces: // - '*' // resources: // - endpoints // verbs: // - get // - create // - update // subjects: // - kind: ServiceAccount // serviceAccount: // name: '*' // namespace: kube-system EndpointsLeasesResourceLock = "endpointsleases" // When using EndpointsLeasesResourceLock, you need to ensure that // API Priority & Fairness is configured with non-default flow-schema // that will catch the necessary operations on leader-election related // configmap objects. // // The example of such flow scheme could look like this: // apiVersion: flowcontrol.apiserver.k8s.io/v1beta2 // kind: FlowSchema // metadata: // name: my-leader-election // spec: // distinguisherMethod: // type: ByUser // matchingPrecedence: 200 // priorityLevelConfiguration: // name: leader-election # reference the <leader-election> PL // rules: // - resourceRules: // - apiGroups: // - "" // namespaces: // - '*' // resources: // - configmaps // verbs: // - get // - create // - update // subjects: // - kind: ServiceAccount // serviceAccount: // name: '*' // namespace: kube-system ConfigMapsLeasesResourceLock = "configmapsleases" )
const (
UnknownLeader = "leaderelection.k8s.io/unknown"
)
Variables ¶
This section is empty.
Functions ¶
func ConcatRawRecord ¶
func LeaderElectionRecordToLeaseSpec ¶
func LeaderElectionRecordToLeaseSpec(ler *LeaderElectionRecord) coordinationv1.LeaseSpec
Types ¶
type EventRecorder ¶
type EventRecorder interface {
Eventf(obj runtime.Object, eventType, reason, message string, args ...interface{})
}
EventRecorder records a change in the ResourceLock.
type Interface ¶
type Interface interface { // Get returns the LeaderElectionRecord Get(ctx context.Context) (*LeaderElectionRecord, []byte, error) // Create attempts to create a LeaderElectionRecord Create(ctx context.Context, ler LeaderElectionRecord) error // Update will update and existing LeaderElectionRecord Update(ctx context.Context, ler LeaderElectionRecord) error // RecordEvent is used to record events RecordEvent(string) // Identity will return the locks Identity Identity() string // Describe is used to convert details on current resource lock // into a string Describe() string }
Interface offers a common interface for locking on arbitrary resources used in leader election. The Interface is used to hide the details on specific implementations in order to allow them to change over time. This interface is strictly for use by the leaderelection code.
func New ¶
func New(lockType string, ns string, name string, coreClient corev1.CoreV1Interface, coordinationClient coordinationv1.CoordinationV1Interface, rlc ResourceLockConfig) (Interface, error)
Manufacture will create a lock of a given type according to the input parameters
func NewFromKubeconfig ¶
func NewFromKubeconfig(lockType string, ns string, name string, rlc ResourceLockConfig, kubeconfig *restclient.Config, renewDeadline time.Duration) (Interface, error)
NewFromKubeconfig will create a lock of a given type according to the input parameters. Timeout set for a client used to contact to Kubernetes should be lower than RenewDeadline to keep a single hung request from forcing a leader loss. Setting it to max(time.Second, RenewDeadline/2) as a reasonable heuristic.
type LeaderElectionRecord ¶
type LeaderElectionRecord struct { // HolderIdentity is the ID that owns the lease. If empty, no one owns this lease and // all callers may acquire. Versions of this library prior to Kubernetes 1.14 will not // attempt to acquire leases with empty identities and will wait for the full lease // interval to expire before attempting to reacquire. This value is set to empty when // a client voluntarily steps down. HolderIdentity string `json:"holderIdentity"` LeaseDurationSeconds int `json:"leaseDurationSeconds"` AcquireTime metav1.Time `json:"acquireTime"` RenewTime metav1.Time `json:"renewTime"` LeaderTransitions int `json:"leaderTransitions"` }
LeaderElectionRecord is the record that is stored in the leader election annotation. This information should be used for observational purposes only and could be replaced with a random string (e.g. UUID) with only slight modification of this code. TODO(mikedanese): this should potentially be versioned
func LeaseSpecToLeaderElectionRecord ¶
func LeaseSpecToLeaderElectionRecord(spec *coordinationv1.LeaseSpec) *LeaderElectionRecord
type LeaseLock ¶
type LeaseLock struct { // LeaseMeta should contain a Name and a Namespace of a // LeaseMeta object that the LeaderElector will attempt to lead. LeaseMeta metav1.ObjectMeta Client coordinationv1client.LeasesGetter LockConfig ResourceLockConfig // contains filtered or unexported fields }
func (*LeaseLock) Create ¶
func (ll *LeaseLock) Create(ctx context.Context, ler LeaderElectionRecord) error
Create attempts to create a Lease
func (*LeaseLock) Describe ¶
Describe is used to convert details on current resource lock into a string
func (*LeaseLock) RecordEvent ¶
RecordEvent in leader election while adding meta-data
type MultiLock ¶
MultiLock is used for lock's migration
func (*MultiLock) Create ¶
func (ml *MultiLock) Create(ctx context.Context, ler LeaderElectionRecord) error
Create attempts to create both primary lock and secondary lock
func (*MultiLock) Describe ¶
Describe is used to convert details on current resource lock into a string
func (*MultiLock) RecordEvent ¶
RecordEvent in leader election while adding meta-data
type ResourceLockConfig ¶
type ResourceLockConfig struct { // Identity is the unique string identifying a lease holder across // all participants in an election. Identity string // EventRecorder is optional. EventRecorder EventRecorder }
ResourceLockConfig common data that exists across different resource locks