Documentation ¶
Overview ¶
Package etcd is a library for performing common Etcd tasks.
Index ¶
- func AddMember(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func CreateClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func CreateSimpleClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func FindSSHUser(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func Get(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func GetInitialCluster(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func IsRunning(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func MakeDir(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func NewSimpleClient(hosts []string) (*simpleEtcdClient, error)
- func RemoveMemberByName(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func RemoveStaleMembers(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func Set(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func SimpleGet(cli client.Client, key string, recursive bool) (*client.Response, error)
- func SimpleSet(cli client.Client, key, value string, expires time.Duration) (*client.Response, error)
- func StoreHostKeys(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func UpdateHostPort(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- func Watch(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
- type DirCreator
- type Getter
- type GetterSetter
- type Setter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddMember ¶
AddMember Add a new member to the cluster.
Conceptually, this is equivalent to `etcdctl member add NAME IP`.
Params:
- client(client.Client): An etcd client
- name (string): The name of the member to add.
- url (string): The peer ip:port or domain: port to use.
Returns:
An etcd *client.Member.
func CreateClient ¶
CreateClient creates a new Etcd client and prepares it for work.
Params:
- url (string): A server to connect to. This runs through os.ExpandEnv().
- retries (int): Number of times to retry a connection to the server
- retrySleep (time.Duration): How long to sleep between retries
Returns:
This puts an *etcd.Client into the context.
func CreateSimpleClient ¶
CreateSimpleClient creates a legacy simple client.
DO NOT USE unless you must for backward compatibility.
Params:
- url (string): A server to connect to. This runs through os.ExpandEnv().
- retries (int): Number of times to retry a connection to the server
- retrySleep (time.Duration): How long to sleep between retries
Returns:
This puts a simpleEtcdClient into context (implements Getter, Setter, etc.)
func FindSSHUser ¶
FindSSHUser finds an SSH user by public key.
Some parts of the system require that we know not only the SSH key, but also the name of the user. That information is stored in etcd.
Params:
- client (EtcdGetter)
- fingerprint (string): The fingerprint of the SSH key.
Returns: - username (string)
func Get ¶
Get performs an etcd Get operation.
Params:
- client (EtcdGetter): Etcd client
- path (string): The path/key to fetch
- recursive (bool): Get children, too. Default: false.
- sort (bool): Lexigraphically sort by name. Default: false.
Returns:
- This puts an `etcd.Response` into the context, and returns an error if the client could not connect.
func GetInitialCluster ¶
GetInitialCluster gets the initial cluster members.
When adding a new node to a cluster, Etcd requires that you pass it a list of initial members, in the form "MEMBERNAME=URL". This command generates that list and puts it into the environment variable ETCD_INITIAL_CLUSTER
Params:
client (client.Client): An etcd client.
Returns:
string representation of the list, also put into the enviornment.
func IsRunning ¶
IsRunning checks to see if etcd is running.
It will test `count` times before giving up.
Params:
- client (EtcdGetter)
- count (int): Number of times to try before giving up.
Returns:
boolean true if etcd is listening.
func MakeDir ¶
MakeDir makes a directory in Etcd.
Params:
- client (EtcdDirCreator): Etcd client
- path (string): The name of the directory to create.
- ttl (uint64): Time to live.
Returns:
*etcd.Response
func NewSimpleClient ¶
Provides a simple wrapper around the old API.
DO NOT USE for new code. Instead, use NewClient().
func RemoveMemberByName ¶
RemoveMemberByName removes a member whose name matches the given.
Params:
- client(client.Client): An etcd client
- name (string): The name to remove
Returns:
true if the member was found, false otherwise.
func RemoveStaleMembers ¶
RemoveStaleMembers deletes cluster members whose pods are no longer running.
This queries Kubernetes to determine what etcd pods are running, and then compares that to the member list in the etcd cluster. It removes any cluster members who are no longer in the pod list.
The purpose of this is to keep the cluster membership from deadlocking when inactive members prevent consensus building.
Params:
- client (etcd/client.Client): The etcd client
- label (string): The pod label indicating an etcd node
- namespace (string): The namespace we're operating in
func Set ¶
Set sets a value in etcd.
Params:
- key (string): The key
- value (string): The value
- ttl (uint64): Time to live
- client (EtcdGetter): Client, usually an *etcd.Client.
Returns:
- *etcd.Result
func SimpleGet ¶
SimpleGet performs the common base-line get, using a default context.
This can be used in cases where no special contextual concerns apply.
func StoreHostKeys ¶
StoreHostKeys stores SSH hostkeys locally.
First it tries to fetch them from etcd. If the keys are not present there, it generates new ones and then puts them into etcd.
Params:
- client(EtcdGetterSetter)
- ciphers([]string): A list of ciphers to generate. Defaults are dsa, ecdsa, ed25519 and rsa.
- basepath (string): Base path in etcd (ETCD_PATH).
func UpdateHostPort ¶
UpdateHostPort intermittently notifies etcd of the builder's address.
If `port` is specified, this will notify etcd at 10 second intervals that the builder is listening at $HOST:$PORT, setting the TTL to 20 seconds.
This will notify etcd as long as the local sshd is running.
Params:
- base (string): The base path to write the data: $base/host and $base/port.
- host (string): The hostname
- port (string): The port
- client (Setter): The client to use to write the data to etcd.
- sshPid (int): The PID for SSHD. If SSHD dies, this stops notifying.
func Watch ¶
Watch watches a given path, and executes a git check-repos for each event.
It starts the watcher and then returns. The watcher runs on its own goroutine. To stop the watching, send the returned channel a bool.
Params: - client (Watcher): An Etcd client. - path (string): The path to watch
Types ¶
type DirCreator ¶
DirCreator describes etcd's CreateDir behavior.
Usually you will want to use go-etcd/etcd.Client to satisfy this.
type Getter ¶
Getter describes the Get behavior of an Etcd client.
Usually you will want to use go-etcd/etcd.Client to satisfy this.
We use an interface because it is more testable.
type GetterSetter ¶
GetterSetter performs get and set operations.