etcd

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2015 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package etcd is a library for performing common Etcd tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMember

func AddMember(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func CreateClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func CreateSimpleClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func FindSSHUser(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func Get(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func GetInitialCluster(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func IsRunning(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func MakeDir(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func NewSimpleClient(hosts []string) (*simpleEtcdClient, error)

Provides a simple wrapper around the old API.

DO NOT USE for new code. Instead, use NewClient().

func RemoveMemberByName

func RemoveMemberByName(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func RemoveStaleMembers(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func Set(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func SimpleGet(cli client.Client, key string, recursive bool) (*client.Response, error)

SimpleGet performs the common base-line get, using a default context.

This can be used in cases where no special contextual concerns apply.

func SimpleSet

func SimpleSet(cli client.Client, key, value string, expires time.Duration) (*client.Response, error)

func StoreHostKeys

func StoreHostKeys(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func UpdateHostPort(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

func Watch(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

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

type DirCreator interface {
	CreateDir(string, uint64) (*client.Response, error)
}

DirCreator describes etcd's CreateDir behavior.

Usually you will want to use go-etcd/etcd.Client to satisfy this.

type Getter

type Getter interface {
	Get(string, bool, bool) (*client.Response, error)
}

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

type GetterSetter interface {
	Getter
	Setter
}

GetterSetter performs get and set operations.

type Setter

type Setter interface {
	Set(string, string, uint64) (*client.Response, error)
}

Setter sets a value in Etcd.

Directories

Path Synopsis
Package discovery contains utlities for Etcd discovery.
Package discovery contains utlities for Etcd discovery.

Jump to

Keyboard shortcuts

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