ksr

package
v3.3.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2019 License: Apache-2.0 Imports: 42 Imported by: 19

Documentation

Overview

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

Index

Constants

View Source
const (
	// ConfigFlagName is name of the flag that defines kubeconfig location
	ConfigFlagName = "kube-config"

	// MicroserviceLabel is the microservice label used by contiv-ksr.
	MicroserviceLabel = "contiv-ksr"

	// KubeConfigAdmin is the default location of kubeconfig with admin credentials.
	KubeConfigAdmin = "/etc/kubernetes/admin.conf"

	// KubeConfigUsage explains the purpose of 'kube-config' flag.
	KubeConfigUsage = "Path to the kubeconfig file to use for the client connection to K8s cluster"
)

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is default instance of Plugin.

View Source
var MockK8sCache = &cache.FakeCustomStore{}

MockK8sCache holds the k8s mock cache

Functions

This section is empty.

Types

type Deps

type Deps struct {
	infra.PluginDeps
	ServiceLabel servicelabel.ReaderAPI
	// 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
	// Prometheus used to publish statistics
	Prometheus *prometheus.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
	// contains filtered or unexported fields
}

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 Option

type Option func(*Plugin)

Option is a function that acts on a Plugin to inject Dependencies or configuration

func UseDeps

func UseDeps(cb func(*Deps)) Option

UseDeps returns Option that can inject custom dependencies.

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 NewPlugin

func NewPlugin(opts ...Option) *Plugin

NewPlugin creates a new Plugin with the provides Options

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 SfcPodReflector added in v1.4.0

type SfcPodReflector struct {
	Reflector
}

SfcPodReflector 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 (*SfcPodReflector) Init added in v1.4.0

func (spr *SfcPodReflector) 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 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
pod
sfc

Jump to

Keyboard shortcuts

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