topology

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

In order to properly satisfy the topology interface, the kubernetes wrapper will monitor POD events (either starting, updating, or stopping) and match them with information from the underlying CRI (Container Runtime Interface) which is managed by the kubelet.

We utilize the CRI endpoints to fetch the current PID, and PID namespace associated with every container in a POD. When any POD event is seen, this code will automatically scan the CRI for containers that match these PODS.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilEvent          = errors.New("nil event")
	ErrNilContainer      = errors.New("nil container")
	ErrUnknownType       = errors.New("unknown event-type")
	ErrBadNamespace      = errors.New("invalid kernel pid-namespace")
	ErrContainerNotFound = errors.New("container not found")
)

Functions

This section is empty.

Types

type Docker

type Docker struct {
}

type DockerOption

type DockerOption func(*Docker) error

type EventType

type EventType int
const (
	EventTypeStart EventType = iota
	EventTypeStop
)

type Kubernetes

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

Kubernetes contains all the working parts to facilitate a Observer for kubernetes operation.

func NewKubernetes

func NewKubernetes(opts ...KubernetesOption) (*Kubernetes, error)

NewKubernetes creates a Observer object for watching kubernetes changes

func (*Kubernetes) Close

func (k *Kubernetes) Close() error

Close frees up all the running resources of this Kubernetes observer

func (*Kubernetes) Connect

func (k *Kubernetes) Connect(ctx context.Context) error

Connect will do all the things to create client connects to both the kubernetes api, and the CRI grpc endpoint.

func (*Kubernetes) Containers

func (k *Kubernetes) Containers(ctx context.Context) ([]*types.Container, error)

Containers returns an array of running containers inside kubernetes.

func (*Kubernetes) Run

func (k *Kubernetes) Run(ctx context.Context, out chan<- *ObservationEvent)

Run connects to kube and watches for POD changes. When changes are seen, attempt to match the changes with the underlying CRI containers (to find the running PID of the container, and the underlying PID namespace).

type KubernetesOption

type KubernetesOption func(*Kubernetes) error

func WithKubernetesCRI

func WithKubernetesCRI(criSocket string) KubernetesOption

WithKubernetesCRI sets the cri file configuration option

func WithKubernetesConfig

func WithKubernetesConfig(kubeConfig string) KubernetesOption

WithKubernetesConfig sets the path to the kube configuration file

func WithKubernetesFieldSelector

func WithKubernetesFieldSelector(f string) KubernetesOption

WithKubernetesFieldSelector sets the fieldselector match configuration option

func WithKubernetesLabelSelector

func WithKubernetesLabelSelector(l string) KubernetesOption

WithKubernetesLabelSelector sets the labelselector match configuration option

func WithKubernetesNamespace

func WithKubernetesNamespace(namespace string) KubernetesOption

WithKubernetesNamespace sets the namespace configuration option

func WithKubernetesProcRoot

func WithKubernetesProcRoot(path string) KubernetesOption

WithKubernetesProcRoot sets the root-directory to the "/proc" directory

type ObservationEvent

type ObservationEvent struct {
	Type      EventType
	Container *types.Container
}

type Observer

type Observer interface {
	Connect(ctx context.Context) error
	Containers(ctx context.Context) ([]*types.Container, error)
	Run(ctx context.Context, out chan<- *ObservationEvent)
	Close() error
}

type OnEventCallback

type OnEventCallback func(t EventType, container *types.Container)

type Topology

type Topology struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTopology

func NewTopology(obs Observer) *Topology

func (*Topology) Close

func (t *Topology) Close() error

func (*Topology) Connect

func (t *Topology) Connect(ctx context.Context) error

func (*Topology) Containers

func (t *Topology) Containers(ctx context.Context) ([]*types.Container, error)

func (*Topology) LookupContainer

func (t *Topology) LookupContainer(ctx context.Context, pidns int) (*types.Container, error)

func (*Topology) Run

func (t *Topology) Run(ctx context.Context, cb OnEventCallback)

Jump to

Keyboard shortcuts

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