Documentation ¶
Index ¶
Constants ¶
View Source
const ( // EnvPodName is the environment variable which is checked for the Pod name. EnvPodName = "ELECTOR_POD_NAME" // ResourcePathPodLabel is the path to the Pod label metadata which is used // for updating Pod label values for election status. // // Note that the label key is the last element in the path. Since the key // contains a "/", it is escaped as "~1". ResourcePathPodLabel = "/metadata/labels/k8s-elector~1status" // StatusStandby is the standby status annotation value. StatusStandby = "standby" // StatusLeader is the leader status annotation value. StatusLeader = "leader" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ElectorConfig ¶
type ElectorConfig struct { // Address is the HTTP address[:port] that the elector will host an endpoint // on (at '/') to provide information on the node and if it is the leader. If // not set, an HTTP endpoint will not be set up. Address string // The ID of the elector node participating in the election. This is required // for an election and must be unique. If not specified, the elector will try // using the HOSTNAME as its ID. ID string // PodName is the name of the Pod which the elector is running in. This is // found via the ELECTOR_POD_NAME environment variable. If not set, this defaults // to the hostname. PodName string // KubeConfig is the path to the kubeconfig file to use for setting up the // elector node's Kubernetes client. If no kubeconfig is specified, the node // will default to using in-cluster configuration. KubeConfig string // LockType specifies the kind of Kubernetes object to use as the lock mechanism // to determine node leadership. If not specified, the node will use "leases" // by default. // // The valid LockTypes are: "endpoints", "configmaps", and "leases". LockType string // The Name of the election. The election name gets used as the name for the // Kubernetes object used as the election lock. This is required by the node // to join or create an election. Name string // The Namespace in Kubernetes to run the election in. The Kubernetes object // used as the election lock will be created in this namespace. If not specified, // "default" is used. Namespace string // The TTL for the election determines the lease duration (the time non-leader // candidates will wait to force acquire leadership), the renew deadline (the // duration that the acting master will retry refreshing leadership), and the // retry period (the duration that elector nodes should wait between retry // actions). TTL time.Duration }
ElectorConfig contains the configuration values for the elector node.
func (*ElectorConfig) Log ¶
func (conf *ElectorConfig) Log()
Log logs the ElectorConfig values at INFO level.
type ElectorNode ¶
type ElectorNode struct {
// contains filtered or unexported fields
}
ElectorNode is a participant node in an election.
func NewElectorNode ¶
func NewElectorNode(config *ElectorConfig) *ElectorNode
NewElectorNode creates a new instance of an elector node which will participate in an election.
func (*ElectorNode) IsLeader ¶
func (node *ElectorNode) IsLeader() bool
IsLeader checks whether the elector node is currently the leader.
func (*ElectorNode) Run ¶
func (node *ElectorNode) Run() error
Run the elector node.
This is the entry point that kicks off all of the elector node setup and run logic.
Click to show internal directories.
Click to hide internal directories.