kube

package
v0.22.0-sumo Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFakeInformer

func NewFakeInformer(
	_ kubernetes.Interface,
	namespace string,
	labelSelector labels.Selector,
	fieldSelector fields.Selector,
) cache.SharedInformer

Types

type APIClientsetProvider

type APIClientsetProvider func(config k8sconfig.APIConfig) (kubernetes.Interface, error)

APIClientsetProvider defines a func type that initializes and return a new kubernetes Clientset object.

type Association added in v0.22.0

type Association struct {
	From string
	Name string
}

Association represents one association rule

type Associations added in v0.22.0

type Associations struct {
	Associations []Association
}

Associations represent a list of rules for Pod metadata associations with resources

type Client

type Client interface {
	GetPod(PodIdentifier) (*Pod, bool)
	Start()
	Stop()
}

Client defines the main interface that allows querying pods by metadata.

func New

func New(logger *zap.Logger, apiCfg k8sconfig.APIConfig, rules ExtractionRules, filters Filters, associations []Association, newClientSet APIClientsetProvider, newInformer InformerProvider, newOwnerProviderFunc OwnerProvider) (Client, error)

New initializes a new k8s Client.

type ClientProvider

ClientProvider defines a func type that returns a new Client.

type ExtractionFieldTags

type ExtractionFieldTags struct {
	ClusterName     string
	ContainerID     string
	ContainerImage  string
	ContainerName   string
	DaemonSetName   string
	DeploymentName  string
	HostName        string
	PodUID          string
	PodName         string
	Namespace       string
	NodeName        string
	ReplicaSetName  string
	ServiceName     string
	StartTime       string
	StatefulSetName string
}

ExtractionFieldTags is used to describe selected exported key names for the extracted data

func NewExtractionFieldTags

func NewExtractionFieldTags() ExtractionFieldTags

NewExtractionFieldTags builds a new instance of tags with default values

type ExtractionRules

type ExtractionRules struct {
	ClusterName     bool
	ContainerID     bool
	ContainerImage  bool
	ContainerName   bool
	DaemonSetName   bool
	DeploymentName  bool
	HostName        bool
	PodUID          bool
	PodName         bool
	ReplicaSetName  bool
	ServiceName     bool
	StatefulSetName bool
	StartTime       bool
	Namespace       bool
	NodeName        bool

	OwnerLookupEnabled bool

	Tags            ExtractionFieldTags
	Annotations     []FieldExtractionRule
	Labels          []FieldExtractionRule
	NamespaceLabels []FieldExtractionRule
}

ExtractionRules is used to specify the information that needs to be extracted from pods and added to the spans as tags.

type FakeController

type FakeController struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*FakeController) HasStopped

func (c *FakeController) HasStopped() bool

func (*FakeController) HasSynced

func (c *FakeController) HasSynced() bool

func (*FakeController) LastSyncResourceVersion

func (c *FakeController) LastSyncResourceVersion() string

func (*FakeController) Run

func (c *FakeController) Run(stopCh <-chan struct{})

type FakeInformer

type FakeInformer struct {
	*FakeController
	// contains filtered or unexported fields
}

func (*FakeInformer) AddEventHandler

func (f *FakeInformer) AddEventHandler(handler cache.ResourceEventHandler)

func (*FakeInformer) AddEventHandlerWithResyncPeriod

func (f *FakeInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, period time.Duration)

func (*FakeInformer) GetController

func (f *FakeInformer) GetController() cache.Controller

func (*FakeInformer) GetStore

func (f *FakeInformer) GetStore() cache.Store

func (*FakeInformer) SetWatchErrorHandler added in v0.10.0

func (f *FakeInformer) SetWatchErrorHandler(cache.WatchErrorHandler) error

type FieldExtractionRule

type FieldExtractionRule struct {
	// Name is used to as the Span tag name.
	Name string
	// Key is used to lookup k8s pod fields.
	Key string
	// Regex is a regular expression used to extract a sub-part of a field value.
	// Full value is extracted when no regexp is provided.
	Regex *regexp.Regexp
}

FieldExtractionRule is used to specify which fields to extract from pod fields and inject into spans as attributes.

type FieldFilter

type FieldFilter struct {
	// Key matches the field name.
	Key string
	// Value matches the field value.
	Value string
	// Op determines the matching operation.
	// Currently only two operations are supported,
	//  - Equals
	//  - NotEquals
	Op selection.Operator
}

FieldFilter represents exactly one filter by field rule.

type Filters

type Filters struct {
	Node            string
	Namespace       string
	Fields          []FieldFilter
	Labels          []FieldFilter
	NamespaceLabels []FieldFilter
}

Filters is used to instruct the client on how to filter out k8s pods. Right now only filters supported are the ones supported by k8s API itself for performance reasons. We can support adding additional custom filters in future if there is a real need.

type InformerProvider

type InformerProvider func(
	client kubernetes.Interface,
	namespace string,
	labelSelector labels.Selector,
	fieldSelector fields.Selector,
) cache.SharedInformer

InformerProvider defines a function type that returns a new SharedInformer. It is used to allow passing custom shared informers to the watch client.

type ObjectOwner

type ObjectOwner struct {
	UID types.UID
	// contains filtered or unexported fields
}

ObjectOwner keeps single entry

type OwnerAPI

type OwnerAPI interface {
	GetOwners(pod *api_v1.Pod) []*ObjectOwner
	GetNamespace(pod *api_v1.Pod) *api_v1.Namespace
	GetServices(pod *api_v1.Pod) []string
	Start()
	Stop()
}

OwnerAPI describes functions that could allow retrieving owner info

type OwnerCache

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

OwnerCache is a simple structure which aids querying for owners

func (*OwnerCache) GetNamespace

func (op *OwnerCache) GetNamespace(pod *api_v1.Pod) *api_v1.Namespace

GetNamespaces returns a cached namespace object (if one is found) or nil otherwise

func (*OwnerCache) GetOwners

func (op *OwnerCache) GetOwners(pod *api_v1.Pod) []*ObjectOwner

GetOwners goes through the cached data and assigns relevant metadata for pod

func (*OwnerCache) GetServices

func (op *OwnerCache) GetServices(pod *api_v1.Pod) []string

GetServices returns a slice with matched services - in case no services are found, it returns an empty slice

func (*OwnerCache) Start

func (op *OwnerCache) Start()

Start runs the informers

func (*OwnerCache) Stop

func (op *OwnerCache) Stop()

Stop shutdowns the informers

type OwnerProvider

type OwnerProvider func(
	logger *zap.Logger,
	client kubernetes.Interface,
	labelSelector labels.Selector,
	fieldSelector fields.Selector,
	namespace string,
) (OwnerAPI, error)

OwnerProvider allows to dynamically assign constructor

type Pod

type Pod struct {
	Name       string
	Address    string
	PodUID     string
	Attributes map[string]string
	StartTime  *metav1.Time
	Ignore     bool

	DeletedAt time.Time
}

Pod represents a kubernetes pod.

type PodIdentifier added in v0.22.0

type PodIdentifier string

PodIdentifier is a custom type to represent IP Address or Pod UID

type WatchClient

type WatchClient struct {

	// A map containing Pod related data, used to associate them with resources.
	// Key can be either an IP address or Pod UID
	Pods         map[PodIdentifier]*Pod
	Rules        ExtractionRules
	Filters      Filters
	Associations []Association
	// contains filtered or unexported fields
}

WatchClient is the main interface provided by this package to a kubernetes cluster.

func (*WatchClient) GetPod added in v0.22.0

func (c *WatchClient) GetPod(identifier PodIdentifier) (*Pod, bool)

GetPod takes an IP address or Pod UID and returns the pod the identifier is associated with.

func (*WatchClient) Start

func (c *WatchClient) Start()

Start registers pod event handlers and starts watching the kubernetes cluster for pod changes.

func (*WatchClient) Stop

func (c *WatchClient) Stop()

Stop signals the the k8s watcher/informer to stop watching for new events.

Jump to

Keyboard shortcuts

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