Documentation ¶
Index ¶
Constants ¶
const ( // ConsulSourceKey is the key used in the meta to track the "k8s" source. // ConsulSourceValue is the value of the source. ConsulSourceKey = "external-source" ConsulSourceValue = "kubernetes" // ConsulK8SNS is the key used in the meta to record the namespace // of the service/node registration. ConsulK8SNS = "external-k8s-ns" // ConsulK8STag is the tag value for services registered. ConsulK8STag = "k8s" )
const ( // ConsulSyncPeriod is how often the syncer will attempt to // reconcile the expected service states with the remote Consul server. ConsulSyncPeriod = 30 * time.Second // ConsulServicePollPeriod is how often a service is checked for // whether it has instances to reap. ConsulServicePollPeriod = 60 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsulSyncer ¶
type ConsulSyncer struct { Client *api.Client Log hclog.Logger // Namespace is the namespace to run this syncer for. This is used // primarily to limit the reaping of the syncer: the syncer will only // reap services/nodes that 1.) have no NS key set or 2.) have an NS // key set that is equal to this. // // If this is blank, any NS key is allowed. This should only be blank // if a single syncer is running for the entire cluster. Namespace string // SyncPeriod is the interval between full catalog syncs. These will // re-register all services to prevent overwrites of data. This should // happen relatively infrequently and default to 30 seconds. // // ServicePollPeriod is the interval to look for invalid services to // deregister. One request will be made for each synced service in // Kubernetes. // // For both syncs, smaller more frequent and focused syncs may be // triggered by known drift or changes. SyncPeriod time.Duration ServicePollPeriod time.Duration // contains filtered or unexported fields }
ConsulSyncer is a Syncer that takes the set of registrations and registers them with Consul. It also watches Consul for changes to the services and ensures the local set of registrations represents the source of truth, overwriting any external changes to the services.
func (*ConsulSyncer) Run ¶
func (s *ConsulSyncer) Run(ctx context.Context)
Run is the long-running runloop for reconciling the local set of services to register with the remote state.
func (*ConsulSyncer) Sync ¶
func (s *ConsulSyncer) Sync(rs []*api.CatalogRegistration)
Sync implements Syncer
type ServiceResource ¶
type ServiceResource struct { Log hclog.Logger Client kubernetes.Interface Syncer Syncer Namespace string // K8S namespace to watch // ExplictEnable should be set to true to require explicit enabling // using annotations. If this is false, then services are implicitly // enabled (aka default enabled). ExplicitEnable bool // contains filtered or unexported fields }
ServiceResource implements controller.Resource to sync Service resource types from K8S.
func (*ServiceResource) Delete ¶
func (t *ServiceResource) Delete(key string) error
Delete implements the controller.Resource interface.
func (*ServiceResource) Informer ¶
func (t *ServiceResource) Informer() cache.SharedIndexInformer
Informer implements the controller.Resource interface.
func (*ServiceResource) Run ¶
func (t *ServiceResource) Run(ch <-chan struct{})
Run implements the controller.Backgrounder interface.
func (*ServiceResource) Upsert ¶
func (t *ServiceResource) Upsert(key string, raw interface{}) error
Upsert implements the controller.Resource interface.
type Syncer ¶
type Syncer interface { // Sync is called to sync the full set of registrations. Sync([]*api.CatalogRegistration) }
Syncer is responsible for syncing a set of Consul catalog registrations. An external system manages the set of registrations and periodically updates the Syncer. The Syncer should keep the remote system in sync with the given set of registrations.
type TestSyncer ¶
type TestSyncer struct { sync.Mutex // Lock should be held while accessing Registrations Registrations []*api.CatalogRegistration }
TestSyncer implements Syncer for tests, giving easy access to the set of registrations.
func (*TestSyncer) Sync ¶
func (s *TestSyncer) Sync(rs []*api.CatalogRegistration)
Sync implements Syncer