Documentation
¶
Index ¶
Constants ¶
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 ¶
var SyncToK8sCounters = []prometheus.CounterDefinition{
{
Name: registerName,
Help: "Increments for each Consul service registered to kubernetes via catalog sync",
},
{
Name: deregisterName,
Help: "Increments for each Consul service deregistered from kubernetes via catalog sync",
},
{
Name: registerErrorName,
Help: "Increments whenever a Consul API client returns an error for a catalog sync register request",
},
{
Name: deregisterErrorName,
Help: "Increments whenever a Consul API client returns an error for a catalog sync deregister request request",
},
}
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 PrometheusSink *prometheus.PrometheusSink // 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) 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 ¶
SetServices implements Sink.
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.
type TestSink ¶
TestSink implements Sink for tests by just storing the services. Reading/writing the services should be done only while the lock is held.