Documentation ¶
Overview ¶
Package ktog contains a reusable abstraction for efficiently watching for changes in resources in a Kubernetes cluster.
Index ¶
Constants ¶
const ( // SyncPeriod is how often the syncer will attempt to // reconcile the expected Service states. SyncPeriod = 5 * time.Second // ServicePollPeriod is how often a Service is checked for // whether it has instances to reap. ServicePollPeriod = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backgrounder ¶
type Backgrounder interface {
Run(<-chan struct{})
}
Backgrounder should be implemented by a Resource that requires additional background processing. If a Resource implements this, then the Controller will automatically Run the Backgrounder for the duration of the controller.
The channel will be closed when the Controller is quitting. The Controller will block until the Backgrounder completes.
type Controller ¶
type Controller struct { Resource Resource // contains filtered or unexported fields }
Controller is a generic cache.Controller implementation that watches Kubernetes for changes to specific set of resources and calls the configured callbacks as data changes.
func (*Controller) HasSynced ¶
func (c *Controller) HasSynced() bool
HasSynced implements cache.Controller.
func (*Controller) LastSyncResourceVersion ¶
func (c *Controller) LastSyncResourceVersion() string
LastSyncResourceVersion implements cache.Controller.
func (*Controller) Run ¶
func (c *Controller) Run(stopCh <-chan struct{})
Run starts the Controller and blocks until stopCh is closed.
Important: Callers must ensure that Run is only called once at a time.
type Event ¶
type Event struct { // Key is in the form of <namespace>/<name>, e.g. default/pod-abc123, // and corresponds to the resource modified. Key string // Obj holds the resource that was modified at the time of the event // occurring. If possible, the resource should be retrieved from the informer // cache, instead of using this field because the cache will be more up to // date at the time the event is processed. // In some cases, such as a delete event, the resource will no longer exist // in the cache and then it is useful to have the resource here. Obj interface{} }
Event is something that occurred to the resources we're watching.
type GatewayResource ¶
type GatewayResource struct { Service *ServiceResource // contains filtered or unexported fields }
GatewayResource implements controller.Resource and starts a background watcher o gateway to keep track of changing gateway.
func (*GatewayResource) Delete ¶
func (gw *GatewayResource) Delete(key string, raw interface{}) error
func (*GatewayResource) Informer ¶
func (gw *GatewayResource) Informer() cache.SharedIndexInformer
func (*GatewayResource) Upsert ¶
func (gw *GatewayResource) Upsert(key string, raw interface{}) error
type GatewayRouteSyncer ¶
type GatewayRouteSyncer struct { SyncPeriod time.Duration ServicePollPeriod time.Duration GatewayResource *GatewayResource // contains filtered or unexported fields }
GatewayRouteSyncer is a Syncer that takes the set of gateway routes.
func (*GatewayRouteSyncer) Run ¶
func (s *GatewayRouteSyncer) Run(ctx context.Context, ctrls ...*Controller)
Run is the long-running runloop for reconciling the local set of services to register with the remote state.
func (*GatewayRouteSyncer) Sync ¶
func (s *GatewayRouteSyncer) Sync(rs []*corev1.Service)
Sync implements Syncer.
type Resource ¶
type Resource interface { // Informer returns the SharedIndexInformer that the controller will // use to watch for changes. An Informer is the long-running task that // holds blocking queries to K8S and stores data in a local store. Informer() cache.SharedIndexInformer // Upsert is the callback called when processing the queue // of changes from the Informer. If an error is returned, the given item // will be retried. Upsert(key string, obj interface{}) error // Delete is called on object deletion. // obj is the last known state of the object before deletion. In some // cases, it may not be up to date with the latest state of the object. // If an error is returned, the given item will be retried. Delete(key string, obj interface{}) error }
Resource should be implemented by anything that should be watchable by Controller. The Resource needs to be aware of how to create the Informer that is responsible for making API calls as well as what to do on Upsert and Delete.
type ResourceDeleteFunc ¶
type ResourceUpsertFunc ¶
ResourceUpsertFunc and ResourceDeleteFunc are the callback types for when a resource is inserted, updated, or deleted.
type ServiceResource ¶
type ServiceResource struct { FsmNamespace string Client kubernetes.Interface GatewayClient gwapi.Interface // Ctx is used to cancel processes kicked off by ServiceResource. Ctx context.Context // AllowK8sNamespacesSet is a set of k8s namespaces to explicitly allow for // syncing. It supports the special character `*` which indicates that // all k8s namespaces are eligible unless explicitly denied. This filter // is applied before checking pod annotations. AllowK8sNamespacesSet mapset.Set // DenyK8sNamespacesSet is a set of k8s namespaces to explicitly deny // syncing and thus Service registration with Consul. An empty set // means that no namespaces are removed from consideration. This filter // takes precedence over AllowK8sNamespacesSet. DenyK8sNamespacesSet mapset.Set // 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 GatewayResource *GatewayResource Syncer Syncer // contains filtered or unexported fields }
ServiceResource implements controller.Resource to sync CatalogService resource types from K8S.
func (*ServiceResource) Delete ¶
func (t *ServiceResource) Delete(key string, _ interface{}) 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.