etcd

package
v0.13.225 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0, MIT Imports: 15 Imported by: 8

Documentation

Overview

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.

Example
package main

import (
	"github.com/zalando/skipper/etcd"
	"github.com/zalando/skipper/filters/builtin"
	"github.com/zalando/skipper/proxy"
	"github.com/zalando/skipper/routing"
	"log"
)

func main() {
	// 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()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

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

Creates a new Client with the provided options.

func (*Client) Delete

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

Deletes a route from etcd.

func (*Client) DeleteAllIf

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

func (*Client) LoadAll

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

Returns all the route definitions currently stored in etcd.

func (*Client) LoadAndParseAll

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

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

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

Inserts or updates a route in etcd.

func (*Client) UpsertAll

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

type Options

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

Path Synopsis
Package etcdtest implements an easy startup script to start a local etcd instance for testing purpose.
Package etcdtest implements an easy startup script to start a local etcd instance for testing purpose.

Jump to

Keyboard shortcuts

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