Documentation
¶
Overview ¶
Package discovery defines basic concepts around service discovery and locating endpoints.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶
type Endpoint struct { // Transport protocol. Almost always "tcp" or "udp". See net.Addr and // net.Dial. Network string // DNS name or IPv4/IPv6 address. Host string // Port number or (discouraged) well-known port name. Port string // Implementation- and user-defined key-value pairs. Annotations map[string]string }
An Endpoint represents a port on a particular server instance or load balancer.
type Locator ¶
type Locator interface { // Cached returns the latest available endpoints without blocking. Repeated // calls to Cached should return fresher results over time. Cached() Result // WaitForUpdate blocks until it can return a different, newer Result from // the one identified by the given version, or the context expires. Version // 0 corresponds to a Result with no endpoints. The only error this method // returns is ctx.Err(). WaitForUpdate(ctx context.Context, oldVersion uint64) (Result, error) // String returns a brief one-line description of the Locator. String() string }
A Locator is used to discover servers or services to communicate with.
type Result ¶
type Result struct { // The set of discovered endpoints, in no particular order. The caller must // not modify the contents of this slice. Locators should return the same // *Endpoint pointer in future Results if the values haven't changed. Endpoints []*Endpoint // A number that increases every time Endpoints changes. Version uint64 }
Result is returned by a Locator to describe specific endpoints.
type StaticLocator ¶
type StaticLocator struct {
// contains filtered or unexported fields
}
StaticLocator is a Locator that returns a Result stored within. It's possible to update the StaticLocator's endpoints using Set().
func NewStaticLocator ¶
func NewStaticLocator(endpoints []*Endpoint) *StaticLocator
NewStaticLocator returns a Locator containing a single Result that can only be updated externally. The caller may not modify the endpoints slice after calling this function. When endpoints is nil the Result.Version is set to 0, 1 otherwise.
This is useful for testing and development purposes. It's also useful where the endpoints are a static list of DNS hostnames or load balancers, which may point to different hosts over time. Using Set(), this can also form the basis of a truly dynamic locator.
func (*StaticLocator) Cached ¶
func (locator *StaticLocator) Cached() Result
Cached implements Locator.Cached.
func (*StaticLocator) Set ¶
func (locator *StaticLocator) Set(endpoints []*Endpoint)
Set updates the Locator to return the given endpoints. This is thread-safe. The caller may not modify the endpoints slice after calling this function.
func (*StaticLocator) String ¶
func (locator *StaticLocator) String() string
String implements Locator.String.
func (*StaticLocator) WaitForUpdate ¶
WaitForUpdate implements Locator.WaitForUpdate.
Directories
¶
Path | Synopsis |
---|---|
Package discoveryfactory constructs service discovery implementations.
|
Package discoveryfactory constructs service discovery implementations. |
Package kubediscovery provides an implementation of the Locator interface backed by Kubernetes service discovery.
|
Package kubediscovery provides an implementation of the Locator interface backed by Kubernetes service discovery. |