add_kubernetes_metadata

package
v6.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContainerIndexerName = "container"
	PodNameIndexerName   = "pod_name"
)
View Source
const (
	FieldMatcherName       = "fields"
	FieldFormatMatcherName = "field_format"
)

Variables

View Source
var Indexing = NewRegister()

Indexing is the singleton Register instance where all Indexers and Matchers are stored

Functions

func IndexerPlugin

func IndexerPlugin(name string, c IndexerConstructor) map[string][]interface{}

func MatcherPlugin

func MatcherPlugin(name string, m MatcherConstructor) map[string][]interface{}

Types

type Container

type Container struct {
	Image                  string          `json:"image"`
	ImagePullPolicy        string          `json:"imagePullPolicy"`
	Name                   string          `json:"name"`
	Ports                  []ContainerPort `json:"ports"`
	Resources              struct{}        `json:"resources"`
	TerminationMessagePath string          `json:"terminationMessagePath"`
	VolumeMounts           []struct {
		MountPath string `json:"mountPath"`
		Name      string `json:"name"`
		ReadOnly  bool   `json:"readOnly"`
	} `json:"volumeMounts"`
}

type ContainerIndexer

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

ContainerIndexer indexes pods based on all their containers IDs

func (*ContainerIndexer) GetIndexes

func (c *ContainerIndexer) GetIndexes(pod *Pod) []string

func (*ContainerIndexer) GetMetadata

func (c *ContainerIndexer) GetMetadata(pod *Pod) []MetadataIndex

type ContainerPort

type ContainerPort struct {
	Name          string `json:"name"`
	ContainerPort int64  `json:"containerPort"`
	Protocol      string `json:"protocol"`
}

type Enabled

type Enabled struct {
	Enabled bool `config:"enabled"`
}

type FieldFormatMatcher

type FieldFormatMatcher struct {
	Codec codec.Codec
}

func (*FieldFormatMatcher) MetadataIndex

func (f *FieldFormatMatcher) MetadataIndex(event common.MapStr) string

type FieldMatcher

type FieldMatcher struct {
	MatchFields []string
}

func (*FieldMatcher) MetadataIndex

func (f *FieldMatcher) MetadataIndex(event common.MapStr) string

type GenDefaultMeta

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

func NewGenDefaultMeta

func NewGenDefaultMeta(annotations, labels, labelsExclude []string) *GenDefaultMeta

func (*GenDefaultMeta) GenerateMetaData

func (g *GenDefaultMeta) GenerateMetaData(pod *Pod) common.MapStr

GenerateMetaData generates default metadata for the given pod taking to account certain filters

type GenMeta

type GenMeta interface {
	//GenerateMetaData generates metadata by taking in a pod as an input
	GenerateMetaData(pod *Pod) common.MapStr
}

GenMeta takes in pods to generate metadata for them

type Indexer

type Indexer interface {
	// GetMetadata generates event metadata for the given pod, then returns the
	// list of indexes to create, with the metadata to put on them
	GetMetadata(pod *Pod) []MetadataIndex

	// GetIndexes return the list of indexes the given pod belongs to. This function
	// must return the same indexes than GetMetadata
	GetIndexes(pod *Pod) []string
}

Indexer take known pods and generate all the metadata we need to enrich events in a efficient way. By preindexing the metadata in the way it will be checked when matching events

func NewContainerIndexer

func NewContainerIndexer(_ common.Config, genMeta GenMeta) (Indexer, error)

func NewPodNameIndexer

func NewPodNameIndexer(_ common.Config, genMeta GenMeta) (Indexer, error)

type IndexerConstructor

type IndexerConstructor func(config common.Config, genMeta GenMeta) (Indexer, error)

type Indexers

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

func NewIndexers

func NewIndexers(configs PluginConfig, metaGen *GenDefaultMeta) *Indexers

func (*Indexers) Empty

func (i *Indexers) Empty() bool

func (*Indexers) GetIndexes

func (i *Indexers) GetIndexes(pod *Pod) []string

GetIndexes returns the composed index list from all registered indexers

func (*Indexers) GetMetadata

func (i *Indexers) GetMetadata(pod *Pod) []MetadataIndex

GetMetadata returns the composed metadata list from all registered indexers

type Matcher

type Matcher interface {
	// MetadataIndex returns the index string to use in annotation lookups for the given
	// event. A previous indexer should have generated that index for this to work
	// This function can return "" if the event doesn't match
	MetadataIndex(event common.MapStr) string
}

Matcher takes a new event and returns the index

func NewFieldFormatMatcher

func NewFieldFormatMatcher(cfg common.Config) (Matcher, error)

func NewFieldMatcher

func NewFieldMatcher(cfg common.Config) (Matcher, error)

type MatcherConstructor

type MatcherConstructor func(config common.Config) (Matcher, error)

type Matchers

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

func NewMatchers

func NewMatchers(configs PluginConfig) *Matchers

func (*Matchers) Empty

func (m *Matchers) Empty() bool

func (*Matchers) MetadataIndex

func (m *Matchers) MetadataIndex(event common.MapStr) string

MetadataIndex returns the index string for the first matcher from the Registry returning one

type MetadataIndex

type MetadataIndex struct {
	Index string
	Data  common.MapStr
}

MetadataIndex holds a pair of index -> metadata info

type ObjectMeta

type ObjectMeta struct {
	Annotations       map[string]string `json:"annotations"`
	CreationTimestamp string            `json:"creationTimestamp"`
	DeletionTimestamp string            `json:"deletionTimestamp"`
	GenerateName      string            `json:"generateName"`
	Labels            map[string]string `json:"labels"`
	Name              string            `json:"name"`
	Namespace         string            `json:"namespace"`
	OwnerReferences   []struct {
		APIVersion string `json:"apiVersion"`
		Controller bool   `json:"controller"`
		Kind       string `json:"kind"`
		Name       string `json:"name"`
		UID        string `json:"uid"`
	} `json:"ownerReferences"`
	ResourceVersion string `json:"resourceVersion"`
	SelfLink        string `json:"selfLink"`
	UID             string `json:"uid"`
}

type PluginConfig

type PluginConfig []map[string]common.Config

type Pod

type Pod struct {
	APIVersion string     `json:"apiVersion"`
	Kind       string     `json:"kind"`
	Metadata   ObjectMeta `json:"metadata"`
	Spec       PodSpec    `json:"spec"`
	Status     PodStatus  `json:"status"`
}

func GetPodMeta

func GetPodMeta(pod *corev1.Pod) *Pod

type PodContainerStatus

type PodContainerStatus struct {
	ContainerID string `json:"containerID"`
	Image       string `json:"image"`
	ImageID     string `json:"imageID"`
	LastState   struct {
		Terminated struct {
			ContainerID string `json:"containerID"`
			ExitCode    int64  `json:"exitCode"`
			FinishedAt  string `json:"finishedAt"`
			Reason      string `json:"reason"`
			StartedAt   string `json:"startedAt"`
		} `json:"terminated"`
	} `json:"lastState"`
	Name         string `json:"name"`
	Ready        bool   `json:"ready"`
	RestartCount int64  `json:"restartCount"`
	State        struct {
		Running struct {
			StartedAt string `json:"startedAt"`
		} `json:"running"`
	} `json:"state"`
}

type PodNameIndexer

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

PodNameIndexer implements default indexer based on pod name

func (*PodNameIndexer) GetIndexes

func (p *PodNameIndexer) GetIndexes(pod *Pod) []string

func (*PodNameIndexer) GetMetadata

func (p *PodNameIndexer) GetMetadata(pod *Pod) []MetadataIndex

type PodSpec

type PodSpec struct {
	Containers                    []Container `json:"containers"`
	DNSPolicy                     string      `json:"dnsPolicy"`
	NodeName                      string      `json:"nodeName"`
	RestartPolicy                 string      `json:"restartPolicy"`
	SecurityContext               struct{}    `json:"securityContext"`
	ServiceAccount                string      `json:"serviceAccount"`
	ServiceAccountName            string      `json:"serviceAccountName"`
	TerminationGracePeriodSeconds int64       `json:"terminationGracePeriodSeconds"`
}

type PodStatus

type PodStatus struct {
	Conditions            []PodStatusCondition `json:"conditions"`
	ContainerStatuses     []PodContainerStatus `json:"containerStatuses"`
	InitContainerStatuses []PodContainerStatus `json:"initContainerStatuses"`
	HostIP                string               `json:"hostIP"`
	Phase                 string               `json:"phase"`
	PodIP                 string               `json:"podIP"`
	StartTime             string               `json:"startTime"`
}

type PodStatusCondition

type PodStatusCondition struct {
	LastProbeTime      interface{} `json:"lastProbeTime"`
	LastTransitionTime string      `json:"lastTransitionTime"`
	Status             string      `json:"status"`
	Type               string      `json:"type"`
}

type PodWatcher

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

PodWatcher is a controller that synchronizes Pods.

func NewPodWatcher

func NewPodWatcher(kubeClient *k8s.Client, indexers *Indexers, syncPeriod, cleanupTimeout time.Duration, host string) *PodWatcher

NewPodWatcher initializes the watcher client to provide a local state of pods from the cluster (filtered to the given host)

func (*PodWatcher) GetMetaData

func (p *PodWatcher) GetMetaData(arg string) common.MapStr

func (*PodWatcher) GetPod

func (p *PodWatcher) GetPod(uid string) *Pod

func (*PodWatcher) Run

func (p *PodWatcher) Run() bool

func (*PodWatcher) Stop

func (p *PodWatcher) Stop()

type Register

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

Register contains Indexer and Matchers to use on pod indexing and event matching

func NewRegister

func NewRegister() *Register

NewRegister creates and returns a new Register.

func (*Register) AddDefaultIndexerConfig

func (r *Register) AddDefaultIndexerConfig(name string, config common.Config)

AddIndexer to the register

func (*Register) AddDefaultMatcherConfig

func (r *Register) AddDefaultMatcherConfig(name string, config common.Config)

AddMatcher to the register

func (*Register) AddIndexer

func (r *Register) AddIndexer(name string, indexer IndexerConstructor)

AddIndexer to the register

func (*Register) AddMatcher

func (r *Register) AddMatcher(name string, matcher MatcherConstructor)

AddMatcher to the register

func (*Register) GetDefaultIndexerConfigs

func (r *Register) GetDefaultIndexerConfigs() map[string]common.Config

func (*Register) GetDefaultMatcherConfigs

func (r *Register) GetDefaultMatcherConfigs() map[string]common.Config

func (*Register) GetIndexer

func (r *Register) GetIndexer(name string) IndexerConstructor

AddIndexer to the register

func (*Register) GetMatcher

func (r *Register) GetMatcher(name string) MatcherConstructor

AddMatcher to the register

Jump to

Keyboard shortcuts

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