ksr

package
v0.0.0-...-a11b7ec Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2018 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package ksr implements plugin that watches K8s resources and causes all changes to be reflected in the ETCD data store.

Index

Constants

This section is empty.

Variables

View Source
var MockK8sCache = &cache.FakeCustomStore{}

MockK8sCache holds the k8s mock cache

Functions

This section is empty.

Types

type Deps

type Deps struct {
	local.PluginInfraDeps
	// Kubeconfig with k8s cluster address and access credentials to use.
	KubeConfig config.PluginConfig
	// broker is used to propagate changes into a key-value datastore.
	// contiv-ksr uses ETCD as datastore.
	Publish *kvdbsync.Plugin
}

Deps defines dependencies of ksr plugin.

type DsItems

type DsItems map[string]interface{}

DsItems defines the structure holding items listed from the data store.

type EndpointsReflector

type EndpointsReflector struct {
	Reflector
}

EndpointsReflector subscribes to K8s cluster to watch for changes in the configuration of k8s service endpoints. Protobuf-modelled changes are published into the selected key-value store.

func (*EndpointsReflector) Init

func (epr *EndpointsReflector) Init(stopCh2 <-chan struct{}, wg *sync.WaitGroup) error

Init subscribes to K8s cluster to watch for changes in the configuration of k8s services. The subscription does not become active until Start() is called.

type EtcdMonitor

type EtcdMonitor struct {
	// contains filtered or unexported fields
}

EtcdMonitor defines the state data for the Etcd Monitor

type K8sClientGetter

type K8sClientGetter func(*kubernetes.Clientset) rest.Interface

K8sClientGetter defines the signature for a function that allocates a REST client for a given K8s data type

type K8sListWatcher

type K8sListWatcher interface {
	// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
	NewListWatchFromClient(c cache.Getter, resource string, namespace string,
		fieldSelector fields.Selector) *cache.ListWatch

	// NewInformer returns a Store and a Controller for populating the store
	// while also providing event notifications.
	NewInformer(lw cache.ListerWatcher, objType runtime.Object, resyncPeriod time.Duration,
		h cache.ResourceEventHandler) (cache.Store, cache.Controller)
}

K8sListWatcher is used to watch for Kubernetes config changes.

type K8sToProtoConverter

type K8sToProtoConverter func(interface{}) (interface{}, string, bool)

K8sToProtoConverter defines the signature for a function converting k8s objects to KSR protobuf objects.

type KeyProtoValBroker

type KeyProtoValBroker interface {
	// Put <data> to ETCD or to any other key-value based data source.
	Put(key string, data proto.Message, opts ...datasync.PutOption) error

	// Delete data under the <key> in ETCD or in any other key-value based data
	// source.
	Delete(key string, opts ...datasync.DelOption) (existed bool, err error)

	// GetValue reads a value from etcd stored under the given key.
	GetValue(key string, reqObj proto.Message) (found bool, revision int64, err error)

	// List values stored in etcd under the given prefix.
	ListValues(prefix string) (keyval.ProtoKeyValIterator, error)
}

KeyProtoValBroker defines KSR's interface to the key-value data store. It defines a subset of operations from a generic cn-infra broker interface (keyval.ProtoBroker in cn-infra).

type NamespaceReflector

type NamespaceReflector struct {
	Reflector
}

NamespaceReflector subscribes to K8s cluster to watch for changes in the configuration of k8s namespaces. Protobuf-modelled changes are published into the selected key-value store.

func (*NamespaceReflector) Init

func (nr *NamespaceReflector) Init(stopCh2 <-chan struct{}, wg *sync.WaitGroup) error

Init subscribes to K8s cluster to watch for changes in the configuration of k8s namespaces. The subscription does not become active until Start() is called.

type NodeReflector

type NodeReflector struct {
	Reflector
}

NodeReflector subscribes to K8s cluster to watch for changes in the configuration of k8s nodes. Protobuf-modelled changes are published into the selected key-value store.

func (*NodeReflector) Init

func (nr *NodeReflector) Init(stopCh2 <-chan struct{}, wg *sync.WaitGroup) error

Init subscribes to K8s cluster to watch for changes in the configuration of k8s nodes. The subscription does not become active until Start() is called.

type Plugin

type Plugin struct {
	Deps

	StatusMonitor statuscheck.StatusReader

	StatsCollector StatsCollector
	// contains filtered or unexported fields
}

Plugin watches K8s resources and causes all changes to be reflected in the ETCD data store.

func (*Plugin) AfterInit

func (plugin *Plugin) AfterInit() error

AfterInit starts all reflectors. They have to be started in AfterInit so that the kvdbsync is fully initialized and ready for publishing when a k8s notification comes.

func (*Plugin) Close

func (plugin *Plugin) Close() error

Close stops all reflectors.

func (*Plugin) Init

func (plugin *Plugin) Init() error

Init builds K8s client-set based on the supplied kubeconfig and initializes all reflectors.

type PodReflector

type PodReflector struct {
	Reflector
}

PodReflector subscribes to K8s cluster to watch for changes in the configuration of k8s pods. Protobuf-modelled changes are published into the selected key-value store.

func (*PodReflector) Init

func (pr *PodReflector) Init(stopCh2 <-chan struct{}, wg *sync.WaitGroup) error

Init subscribes to K8s cluster to watch for changes in the configuration of k8s pods. The subscription does not become active until Start() is called.

type PolicyReflector

type PolicyReflector struct {
	Reflector
}

PolicyReflector subscribes to K8s cluster to watch for changes in the configuration of k8s network policies. Protobuf-modelled changes are published into the selected key-value store.

func (*PolicyReflector) Init

func (pr *PolicyReflector) Init(stopCh2 <-chan struct{}, wg *sync.WaitGroup) error

Init subscribes to K8s cluster to watch for changes in the configuration of k8s network policies. The subscription does not become active until Start() is called.

type ProtoAllocator

type ProtoAllocator func() proto.Message

ProtoAllocator defines the signature for a protobuf message allocation function

type Reflector

type Reflector struct {
	// Each reflector gets a separate child logger.
	Log logging.Logger
	// A K8s client gets the appropriate REST client.
	K8sClientset *kubernetes.Clientset
	// K8s List-Watch watches for Kubernetes config changes.
	K8sListWatch K8sListWatcher
	// broker is the interface to a key-val data store.
	Broker KeyProtoValBroker
	// reflector registry
	*ReflectorRegistry
	// contains filtered or unexported fields
}

Reflector holds data that is common to all KSR reflectors.

func (*Reflector) Close

func (r *Reflector) Close() error

Close deletes the reflector from the reflector registry.

func (*Reflector) GetStats

func (r *Reflector) GetStats() *ksrapi.KsrStats

GetStats returns the Service Reflector usage gauges

func (*Reflector) HasSynced

func (r *Reflector) HasSynced() bool

HasSynced returns the KSR Reflector's sync status.

func (*Reflector) Start

func (r *Reflector) Start()

Start activates the K8s subscription.

type ReflectorFunctions

type ReflectorFunctions struct {
	EventHdlrFunc cache.ResourceEventHandlerFuncs

	ProtoAllocFunc ProtoAllocator
	K8s2NodeFunc   K8sToProtoConverter
	K8sClntGetFunc K8sClientGetter
}

ReflectorFunctions defines the function types required in the KSR reflector

type ReflectorRegistry

type ReflectorRegistry struct {
	// contains filtered or unexported fields
}

ReflectorRegistry defines the data structures for the KSR Reflector Registry

type ServiceReflector

type ServiceReflector struct {
	Reflector
}

ServiceReflector subscribes to K8s cluster to watch for changes in the configuration of k8s services. Protobuf-modelled changes are published into the selected key-value store.

func (*ServiceReflector) Init

func (sr *ServiceReflector) Init(stopCh2 <-chan struct{}, wg *sync.WaitGroup) error

Init subscribes to K8s cluster to watch for changes in the configuration of k8s services. The subscription does not become active until Start() is called.

type StatsCollector

type StatsCollector struct {
	Log logging.Logger

	Prometheus prometheusplugin.API
	// contains filtered or unexported fields
}

StatsCollector defines the data structures for the KSR Stats Collector

func (*StatsCollector) Init

func (ksc *StatsCollector) Init() error

Init initializes the KSR Statistics Collector

Directories

Path Synopsis
model
endpoints
Package endpoints is a generated protocol buffer package.
Package endpoints is a generated protocol buffer package.
ksrapi
Package ksrapi is a generated protocol buffer package.
Package ksrapi is a generated protocol buffer package.
namespace
Package namespace is a generated protocol buffer package.
Package namespace is a generated protocol buffer package.
node
Package node is a generated protocol buffer package.
Package node is a generated protocol buffer package.
pod
Package pod is a generated protocol buffer package.
Package pod is a generated protocol buffer package.
policy
Package policy is a generated protocol buffer package.
Package policy is a generated protocol buffer package.
service
Package service is a generated protocol buffer package.
Package service is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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