skipper: github.com/zalando/skipper/etcd Index | Examples | Files | Directories

package etcd

import "github.com/zalando/skipper/etcd"

Package etcd implements a DataClient for reading the skipper route definitions from an etcd service.

(See the DataClient interface in the skipper/routing package.)

etcd is a generic, distributed configuration service: https://github.com/coreos/etcd. The route definitions are stored under individual keys as eskip route expressions. When loaded from etcd, the routes will get the etcd key as id.

In addition to the DataClient implementation, type Client provides methods to Upsert and Delete routes.

Code:

// create etcd data client:
dataClient, err := etcd.New(etcd.Options{
    Endpoints: []string{"https://etcd.example.org"},
    Prefix:    "/skipper",
    Timeout:   0,
    Insecure:  false,
})

if err != nil {
    log.Fatal(err)
}

// create routing object:
rt := routing.New(routing.Options{
    FilterRegistry: builtin.MakeRegistry(),
    DataClients:    []routing.DataClient{dataClient}})
defer rt.Close()

// create http.Handler:
p := proxy.New(rt, proxy.OptionsNone)
defer p.Close()

Index

Examples

Package Files

etcd.go

type Client Uses

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

A Client is used to load the whole set of routes and the updates from an etcd store.

func New Uses

func New(o Options) (*Client, error)

Creates a new Client with the provided options.

func (*Client) Delete Uses

func (c *Client) Delete(id string) error

Deletes a route from etcd.

func (*Client) DeleteAllIf Uses

func (c *Client) DeleteAllIf(routes []*eskip.Route, cond eskip.RoutePredicate) error

func (*Client) LoadAll Uses

func (c *Client) LoadAll() ([]*eskip.Route, error)

Returns all the route definitions currently stored in etcd.

func (*Client) LoadAndParseAll Uses

func (c *Client) LoadAndParseAll() ([]*eskip.RouteInfo, error)

Returns all the route definitions currently stored in etcd, or the parsing error in case of failure.

func (*Client) LoadUpdate Uses

func (c *Client) LoadUpdate() ([]*eskip.Route, []string, error)

Returns the updates (upserts and deletes) since the last initial request or update.

It uses etcd's watch functionality that results in blocking this call until the next change is detected in etcd or reaches the configured hard timeout.

func (*Client) Upsert Uses

func (c *Client) Upsert(r *eskip.Route) error

Inserts or updates a route in etcd.

func (*Client) UpsertAll Uses

func (c *Client) UpsertAll(routes []*eskip.Route) error

type Options Uses

type Options struct {

    // A slice of etcd endpoint addresses.
    // (Schema and host.)
    Endpoints []string

    // Etcd path to a directory where the
    // Skipper related settings are stored.
    Prefix string

    // A timeout value for etcd long-polling.
    // The default timeout is 1 second.
    Timeout time.Duration

    // Skip TLS certificate check.
    Insecure bool

    // Optional OAuth-Token
    OAuthToken string

    // Optional username for basic auth
    Username string

    // Optional password for basic auth
    Password string
}

Initialization options.

Directories

PathSynopsis
etcdtestPackage etcdtest implements an easy startup script to start a local etcd instance for testing purpose.

Package etcd imports 16 packages (graph) and is imported by 7 packages. Updated 2019-05-13. Refresh now. Tools for package owners.