catalog

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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
)
View Source
const (
	TestConsulK8STag = "k8s"
)

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

	// ConsulK8STag is the tag value for services registered.
	ConsulK8STag string
	// 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 NodePortSyncType

type NodePortSyncType string
const (
	// Only sync NodePort services with a node's ExternalIP address.
	// Doesn't sync if an ExternalIP doesn't exist
	ExternalOnly NodePortSyncType = "ExternalOnly"

	// Sync with an ExternalIP first, if it doesn't exist, use the
	// node's InternalIP address instead
	ExternalFirst NodePortSyncType = "ExternalFirst"

	// Sync NodePort services using
	InternalOnly NodePortSyncType = "InternalOnly"
)

type ServiceResource

type ServiceResource struct {
	Log       hclog.Logger
	Client    kubernetes.Interface
	Syncer    Syncer
	Namespace string // K8S namespace to watch

	// ConsulK8STag is the tag value for services registered.
	ConsulK8STag string

	//ConsulServicePrefix prepends K8s services in Consul with a prefix
	ConsulServicePrefix string

	// 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

	// ClusterIPSync set to true (the default) syncs ClusterIP-type services.
	// Setting this to false will ignore ClusterIP services during the sync.
	ClusterIPSync bool

	// NodeExternalIPSync set to true (the default) syncs NodePort services
	// using the node's external ip address. When false, the node's internal
	// ip address will be used instead.
	NodePortSync NodePortSyncType

	// AddK8SNamespaceSuffix set to true appends Kubernetes namespace
	// to the service name being synced to Consul separated by a dash.
	// For example, service 'foo' in the 'default' namespace will be synced
	// as 'foo-default'.
	AddK8SNamespaceSuffix 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

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

Jump to

Keyboard shortcuts

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