listener

package
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 25 Imported by: 1

Documentation

Overview

Package listener listens to Kubernetes for policy updates.

Package listener's nodes.go contains a subset of listener functionality where it connects to kubernetes using kubernetes client-go and watches node creation/deletion events and then adds/deletes the nodes to/from romana cluster appropriately.

Package listener implements kubernetes API specific helper functions.

Index

Constants

View Source
const (
	KubeEventAdded    = "ADDED"
	KubeEventDeleted  = "DELETED"
	KubeEventModified = "MODIFIED"
)
View Source
const TranslateGroupStartIndex = 0

Variables

This section is empty.

Functions

func GetTenantIDFromNamespaceName

func GetTenantIDFromNamespaceName(nsName string) string

TODO 1. we need this because policies have namespace names. For now we can have the name be the ID, but ideally it would be name and ID. We could cache ID-name mapping on namespace creation events, and get them all during startup, but is it possible for events to happen: 1. namespace created, 2. policy created, 3. namespace deleted, and us to receive them as 1,3,2 ?

2. This is used by CNI plugin so maybe this can go into something common to both listener & CNI plugin? move this into romana/core/kubernetes/helpers.go and move cni and listener under that romana/core/kubernetes too?

func GetTenantIDFromNamespaceObject

func GetTenantIDFromNamespaceObject(ns *v1.Namespace) string

TODO: see GetTenantIDFromNamespaceName

func HandleDefaultPolicy

func HandleDefaultPolicy(o *v1.Namespace, l *KubeListener)

HandleDefaultPolicy handles isolation flag on a namespace by creating/deleting default network policy. See http://kubernetes.io/docs/user-guide/networkpolicies/

func ProduceNewPolicyEvents

func ProduceNewPolicyEvents(out chan Event, done <-chan struct{}, KubeListener *KubeListener)

ProduceNewPolicyEvents produces kubernetes network policy events that arent applied in romana policy service yet.

Types

type Event

type Event struct {
	Type   string `json:"Type"`
	Object interface{}
}

Event is a representation of a structure that we receive from kubernetes API.

type ExposedIPSpecMap added in v1.1.0

type ExposedIPSpecMap struct {
	sync.Mutex
	IPForService map[string]api.ExposedIPSpec
}

type KubeListener

type KubeListener struct {
	Addr string

	// Maintains state about what things have been synchronized.
	// A mutex is required because of watchers emitting events in
	// separate goroutines
	sync.RWMutex
	// contains filtered or unexported fields
}

KubeListener is a Service that listens to updates from Kubernetes by connecting to the endpoints specified and consuming chunked JSON documents. The endpoints are constructed from kubeURL and the following paths:

  1. namespaceNotificationPath for namespace additions/deletions
  2. policyNotificationPathPrefix + <namespace name> + policyNotificationPathPostfix for policy additions/deletions.

func (*KubeListener) GetAddress

func (l *KubeListener) GetAddress() string

func (*KubeListener) Initialize

func (l *KubeListener) Initialize(clientConfig common.Config) error

func (*KubeListener) Name

func (l *KubeListener) Name() string

Name implements method of Service interface.

func (*KubeListener) ProcessNodeEvents

func (l *KubeListener) ProcessNodeEvents(done <-chan struct{})

ProcessNodeEvents processes kubernetes node events, there by adding/deleting nodes to/from romana cluster automatically when they are added/removed to/from kubernetes cluster.

func (*KubeListener) Routes

func (l *KubeListener) Routes() common.Routes

Routes returns various routes used in the service.

type NoMoreIngressEntities

type NoMoreIngressEntities struct{}

NoMoreIngressEntities is an error that indicates that translateNextIngress went through all Ingress entries in TranslateGroup.kubePolicy.

func (NoMoreIngressEntities) Error

func (e NoMoreIngressEntities) Error() string

type PolicyTranslator

type PolicyTranslator interface {
	Init(*client.Client, string, string)

	// Translates kubernetes policy into romana format.
	Kube2Romana(v1beta1.NetworkPolicy) (api.Policy, error)

	// Translates number of kubernetes policies into romana format.
	// Returns a list of translated policies, list of original policies
	// that failed to translate and an error.
	Kube2RomanaBulk([]v1beta1.NetworkPolicy) ([]api.Policy, []v1beta1.NetworkPolicy, error)
}

type TenantCacheEntry

type TenantCacheEntry struct {
	Tenant api.Tenant
}

type TranslateGroup

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

TranslateGroup represent a state of translation of kubernetes policy into romana policy.

type Translator

type Translator struct {
	// contains filtered or unexported fields
}
var PTranslator Translator

TODO there should be a better way to introduce translator then global variable like this one.

func (Translator) GetClient

func (t Translator) GetClient() *client.Client

func (*Translator) Init

func (t *Translator) Init(client *client.Client, segmentLabelName, tenantLabelName string)

func (Translator) Kube2Romana

func (t Translator) Kube2Romana(kubePolicy v1beta1.NetworkPolicy) (api.Policy, error)

Kube2Romana reserved for future use.

func (Translator) Kube2RomanaBulk

func (t Translator) Kube2RomanaBulk(kubePolicies []v1beta1.NetworkPolicy) ([]api.Policy, []v1beta1.NetworkPolicy, error)

Kube2RomanaBulk attempts to translate a list of kubernetes policies into romana representation, returns a list of translated policies and a list of policies that can't be translated in original format.

type TranslatorError

type TranslatorError struct {
	Code    TranslatorErrorType
	Details error
}

func (TranslatorError) Error

func (t TranslatorError) Error() string

type TranslatorErrorType

type TranslatorErrorType int
const (
	ErrorCacheUpdate TranslatorErrorType = iota
	ErrorTenantNotInCache
	ErrorTranslatingPolicyTarget
	ErrorTranslatingPolicyIngress
)

Jump to

Keyboard shortcuts

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