catalog

package
v0.0.0-...-534e0d3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// K8SQuietPeriod is the time to wait for no service changes before syncing.
	K8SQuietPeriod = 1 * time.Second

	// K8SMaxPeriod is the maximum time to wait before forcing a sync, even
	// if there are active changes going on.
	K8SMaxPeriod = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type K8SSink

type K8SSink struct {
	Client    kubernetes.Interface // Client is the K8S API client
	Namespace string               // Namespace is the namespace to sync to
	Log       hclog.Logger         // Logger

	// SyncPeriod is the duration to wait between registering or deregistering
	// services in Kubernetes. This can be fairly short since no work will be
	// done if there are no changes.
	SyncPeriod time.Duration

	// Ctx is used to cancel the Sink.
	Ctx context.Context
	// contains filtered or unexported fields
}

K8SSink is a Sink implementation that registers services with Kubernetes.

K8SSink also implements controller.Resource and is meant to run as a K8S controller that watches services. This is the primary way that the sink should be run.

func (*K8SSink) Delete

func (s *K8SSink) Delete(key string, _ interface{}) error

Delete implements the controller.Resource interface.

func (*K8SSink) Informer

func (s *K8SSink) Informer() cache.SharedIndexInformer

Informer implements the controller.Resource interface. It tells Kubernetes that we want to watch for changes to Services.

func (*K8SSink) Run

func (s *K8SSink) Run(ch <-chan struct{})

Run implements the controller.Backgrounder interface.

func (*K8SSink) SetServices

func (s *K8SSink) SetServices(svcs map[string]string)

SetServices implements Sink.

func (*K8SSink) Upsert

func (s *K8SSink) Upsert(key string, raw interface{}) error

Upsert implements the controller.Resource interface.

type Sink

type Sink interface {
	// SetServices is called with the services that should be created.
	// The key is the service name and the destination is the external DNS
	// entry to point to.
	SetServices(map[string]string)
}

Sink is the destination where services are registered.

While in practice we only have one sink (K8S), the interface abstraction makes it easy and possible to test the Source in isolation.

type Source

type Source struct {
	// ConsulClientConfig is the config for the Consul API client.
	ConsulClientConfig *consul.Config
	// ConsulServerConnMgr is the watcher for the Consul server addresses.
	ConsulServerConnMgr consul.ServerConnectionManager
	Domain              string       // Consul DNS domain
	Sink                Sink         // Sink is the sink to update with services
	Prefix              string       // Prefix is a prefix to prepend to services
	Log                 hclog.Logger // Logger
	ConsulK8STag        string       // The tag value for services registered
}

Source is the source for the sync that watches Consul services and updates a Sink whenever the set of services to register changes.

func (*Source) Run

func (s *Source) Run(ctx context.Context)

Run is the long-running runloop for watching Consul services and updating the Sink.

type TestSink

type TestSink struct {
	sync.Mutex
	Services map[string]string
}

TestSink implements Sink for tests by just storing the services. Reading/writing the services should be done only while the lock is held.

func (*TestSink) SetServices

func (s *TestSink) SetServices(raw map[string]string)

Jump to

Keyboard shortcuts

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