object

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package object holds functions that convert the objects from the k8s API in to a more memory efficient structures.

Adding new fields to any of the structures defined in pod.go, endpoint.go and service.go should not be done lightly as this increases the memory use and will leads to OOMs in the k8s scale test.

We can do some optimizations here as well. We store IP addresses as strings, this might be moved to uint32 (for v4) for instance, but then we need to convert those again.

Also the msg.Service use in this plugin may be deprecated at some point, as we don't use most of those features anyway and would free us from the *etcd* dependency, where msg.Service is defined. And should save some mem/cpu as we convert to and from msg.Services.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DNSProgrammingLatency is defined as the time it took to program a DNS instance - from the time
	// a service or pod has changed to the time the change was propagated and was available to be
	// served by a DNS server.
	// The definition of this SLI can be found at https://github.com/kubernetes/community/blob/master/sig-scalability/slos/dns_programming_latency.md
	// Note that the metrics is partially based on the time exported by the endpoints controller on
	// the master machine. The measurement may be inaccurate if there is a clock drift between the
	// node and master machine.
	// The service_kind label can be one of:
	//   * cluster_ip
	//   * headless_with_selector
	//   * headless_without_selector
	DNSProgrammingLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: plugin.Namespace,
		Subsystem: "kubernetes",
		Name:      "dns_programming_duration_seconds",

		Buckets: prometheus.ExponentialBuckets(0.001, 2, 20),
		Help:    "Histogram of the time (in seconds) it took to program a dns instance.",
	}, []string{"service_kind"})

	// DurationSinceFunc returns the duration elapsed since the given time.
	// Added as a global variable to allow injection for testing.
	DurationSinceFunc = time.Since
)

Functions

func EndpointSliceToEndpoints

func EndpointSliceToEndpoints(obj meta.Object) (meta.Object, error)

EndpointSliceToEndpoints converts a *discovery.EndpointSlice to a *Endpoints.

func EndpointsKey

func EndpointsKey(name, namespace string) string

EndpointsKey returns a string using for the index.

func NewIndexerInformer

func NewIndexerInformer(lw cache.ListerWatcher, objType runtime.Object, h cache.ResourceEventHandler, indexers cache.Indexers, builder ProcessorBuilder) (cache.Indexer, cache.Controller)

NewIndexerInformer is a copy of the cache.NewIndexerInformer function, but allows custom process function

func ServiceKey

func ServiceKey(name, namespace string) string

ServiceKey returns a string using for the index.

func ToNamespace

func ToNamespace(obj meta.Object) (meta.Object, error)

ToNamespace returns a function that converts an api.Namespace to a *Namespace.

func ToPod

func ToPod(obj meta.Object) (meta.Object, error)

ToPod converts an api.Pod to a *Pod.

func ToService

func ToService(obj meta.Object) (meta.Object, error)

ToService converts an api.Service to a *Service.

Types

type Empty

type Empty struct{}

Empty is an empty struct.

func (*Empty) GetAnnotations

func (e *Empty) GetAnnotations() map[string]string

GetAnnotations implements the metav1.Object interface.

func (*Empty) GetCreationTimestamp

func (e *Empty) GetCreationTimestamp() v1.Time

GetCreationTimestamp implements the metav1.Object interface.

func (*Empty) GetDeletionGracePeriodSeconds

func (e *Empty) GetDeletionGracePeriodSeconds() *int64

GetDeletionGracePeriodSeconds implements the metav1.Object interface.

func (*Empty) GetDeletionTimestamp

func (e *Empty) GetDeletionTimestamp() *v1.Time

GetDeletionTimestamp implements the metav1.Object interface.

func (*Empty) GetFinalizers

func (e *Empty) GetFinalizers() []string

GetFinalizers implements the metav1.Object interface.

func (*Empty) GetGenerateName

func (e *Empty) GetGenerateName() string

GetGenerateName implements the metav1.Object interface.

func (*Empty) GetGeneration

func (e *Empty) GetGeneration() int64

GetGeneration implements the metav1.Object interface.

func (*Empty) GetLabels

func (e *Empty) GetLabels() map[string]string

GetLabels implements the metav1.Object interface.

func (*Empty) GetManagedFields

func (e *Empty) GetManagedFields() []v1.ManagedFieldsEntry

GetManagedFields implements the metav1.Object interface.

func (*Empty) GetObjectKind

func (e *Empty) GetObjectKind() schema.ObjectKind

GetObjectKind implements the ObjectKind interface as a noop.

func (*Empty) GetOwnerReferences

func (e *Empty) GetOwnerReferences() []v1.OwnerReference

GetOwnerReferences implements the metav1.Object interface.

func (e *Empty) GetSelfLink() string

GetSelfLink implements the metav1.Object interface.

func (*Empty) GetUID

func (e *Empty) GetUID() types.UID

GetUID implements the metav1.Object interface.

func (*Empty) GetZZZ_DeprecatedClusterName

func (e *Empty) GetZZZ_DeprecatedClusterName() string

GetZZZ_DeprecatedClusterName implements the metav1.Object interface.

func (*Empty) SetAnnotations

func (e *Empty) SetAnnotations(annotations map[string]string)

SetAnnotations implements the metav1.Object interface.

func (*Empty) SetCreationTimestamp

func (e *Empty) SetCreationTimestamp(timestamp v1.Time)

SetCreationTimestamp implements the metav1.Object interface.

func (*Empty) SetDeletionGracePeriodSeconds

func (e *Empty) SetDeletionGracePeriodSeconds(*int64)

SetDeletionGracePeriodSeconds implements the metav1.Object interface.

func (*Empty) SetDeletionTimestamp

func (e *Empty) SetDeletionTimestamp(timestamp *v1.Time)

SetDeletionTimestamp implements the metav1.Object interface.

func (*Empty) SetFinalizers

func (e *Empty) SetFinalizers(finalizers []string)

SetFinalizers implements the metav1.Object interface.

func (*Empty) SetGenerateName

func (e *Empty) SetGenerateName(name string)

SetGenerateName implements the metav1.Object interface.

func (*Empty) SetGeneration

func (e *Empty) SetGeneration(generation int64)

SetGeneration implements the metav1.Object interface.

func (*Empty) SetLabels

func (e *Empty) SetLabels(labels map[string]string)

SetLabels implements the metav1.Object interface.

func (*Empty) SetManagedFields

func (e *Empty) SetManagedFields(managedFields []v1.ManagedFieldsEntry)

SetManagedFields implements the metav1.Object interface.

func (*Empty) SetOwnerReferences

func (e *Empty) SetOwnerReferences([]v1.OwnerReference)

SetOwnerReferences implements the metav1.Object interface.

func (e *Empty) SetSelfLink(selfLink string)

SetSelfLink implements the metav1.Object interface.

func (*Empty) SetUID

func (e *Empty) SetUID(uid types.UID)

SetUID implements the metav1.Object interface.

func (*Empty) SetZZZ_DeprecatedClusterName

func (e *Empty) SetZZZ_DeprecatedClusterName(clusterName string)

SetZZZ_DeprecatedClusterName implements the metav1.Object interface.

type EndpointAddress

type EndpointAddress struct {
	IP            string
	Hostname      string
	NodeName      string
	TargetRefName string
}

EndpointAddress is a tuple that describes single IP address.

type EndpointLatencyRecorder

type EndpointLatencyRecorder struct {
	TT          time.Time
	ServiceFunc func(meta.Object) []*Service
	Services    []*Service
}

EndpointLatencyRecorder records latency metric for endpoint objects

type EndpointPort

type EndpointPort struct {
	Port     int32
	Name     string
	Protocol string
}

EndpointPort is a tuple that describes a single port.

type EndpointSubset

type EndpointSubset struct {
	Addresses []EndpointAddress
	Ports     []EndpointPort
}

EndpointSubset is a group of addresses with a common set of ports. The expanded set of endpoints is the Cartesian product of Addresses x Ports.

type Endpoints

type Endpoints struct {
	// Don't add new fields to this struct without talking to the CoreDNS maintainers.
	Version   string
	Name      string
	Namespace string
	Index     string
	IndexIP   []string
	Subsets   []EndpointSubset

	*Empty
}

Endpoints is a stripped down api.Endpoints with only the items we need for CoreDNS.

func (*Endpoints) CopyWithoutSubsets

func (e *Endpoints) CopyWithoutSubsets() *Endpoints

CopyWithoutSubsets copies e, without the subsets.

func (*Endpoints) DeepCopyObject

func (e *Endpoints) DeepCopyObject() runtime.Object

DeepCopyObject implements the ObjectKind interface.

func (*Endpoints) GetName

func (e *Endpoints) GetName() string

GetName implements the metav1.Object interface.

func (*Endpoints) GetNamespace

func (e *Endpoints) GetNamespace() string

GetNamespace implements the metav1.Object interface.

func (*Endpoints) GetResourceVersion

func (e *Endpoints) GetResourceVersion() string

GetResourceVersion implements the metav1.Object interface.

func (*Endpoints) SetName

func (e *Endpoints) SetName(name string)

SetName implements the metav1.Object interface.

func (*Endpoints) SetNamespace

func (e *Endpoints) SetNamespace(namespace string)

SetNamespace implements the metav1.Object interface.

func (*Endpoints) SetResourceVersion

func (e *Endpoints) SetResourceVersion(version string)

SetResourceVersion implements the metav1.Object interface.

type Namespace

type Namespace struct {
	// Don't add new fields to this struct without talking to the CoreDNS maintainers.
	Version string
	Name    string

	*Empty
}

Namespace is a stripped down api.Namespace with only the items we need for CoreDNS.

func (*Namespace) DeepCopyObject

func (n *Namespace) DeepCopyObject() runtime.Object

DeepCopyObject implements the ObjectKind interface.

func (*Namespace) GetName

func (n *Namespace) GetName() string

GetName implements the metav1.Object interface.

func (*Namespace) GetNamespace

func (n *Namespace) GetNamespace() string

GetNamespace implements the metav1.Object interface.

func (*Namespace) GetResourceVersion

func (n *Namespace) GetResourceVersion() string

GetResourceVersion implements the metav1.Object interface.

func (*Namespace) SetName

func (n *Namespace) SetName(name string)

SetName implements the metav1.Object interface.

func (*Namespace) SetNamespace

func (n *Namespace) SetNamespace(namespace string)

SetNamespace implements the metav1.Object interface.

func (*Namespace) SetResourceVersion

func (n *Namespace) SetResourceVersion(version string)

SetResourceVersion implements the metav1.Object interface.

type Pod

type Pod struct {
	// Don't add new fields to this struct without talking to the CoreDNS maintainers.
	Version   string
	PodIP     string
	Name      string
	Namespace string

	*Empty
}

Pod is a stripped down api.Pod with only the items we need for CoreDNS.

func (*Pod) DeepCopyObject

func (p *Pod) DeepCopyObject() runtime.Object

DeepCopyObject implements the ObjectKind interface.

func (*Pod) GetName

func (p *Pod) GetName() string

GetName implements the metav1.Object interface.

func (*Pod) GetNamespace

func (p *Pod) GetNamespace() string

GetNamespace implements the metav1.Object interface.

func (*Pod) GetResourceVersion

func (p *Pod) GetResourceVersion() string

GetResourceVersion implements the metav1.Object interface.

func (*Pod) SetName

func (p *Pod) SetName(name string)

SetName implements the metav1.Object interface.

func (*Pod) SetNamespace

func (p *Pod) SetNamespace(namespace string)

SetNamespace implements the metav1.Object interface.

func (*Pod) SetResourceVersion

func (p *Pod) SetResourceVersion(version string)

SetResourceVersion implements the metav1.Object interface.

type ProcessorBuilder

type ProcessorBuilder func(cache.Indexer, cache.ResourceEventHandler) cache.ProcessFunc

ProcessorBuilder returns function to process cache events.

func DefaultProcessor

func DefaultProcessor(convert ToFunc, recordLatency *EndpointLatencyRecorder) ProcessorBuilder

DefaultProcessor is based on the Process function from cache.NewIndexerInformer except it does a conversion.

type RecordLatencyFunc

type RecordLatencyFunc func(meta.Object)

RecordLatencyFunc is a function for recording api object delta latency

type Service

type Service struct {
	// Don't add new fields to this struct without talking to the CoreDNS maintainers.
	Version      string
	Name         string
	Namespace    string
	Index        string
	ClusterIPs   []string
	Type         api.ServiceType
	ExternalName string
	Ports        []api.ServicePort

	// ExternalIPs we may want to export.
	ExternalIPs []string

	*Empty
}

Service is a stripped down api.Service with only the items we need for CoreDNS.

func (*Service) DeepCopyObject

func (s *Service) DeepCopyObject() runtime.Object

DeepCopyObject implements the ObjectKind interface.

func (*Service) GetName

func (s *Service) GetName() string

GetName implements the metav1.Object interface.

func (*Service) GetNamespace

func (s *Service) GetNamespace() string

GetNamespace implements the metav1.Object interface.

func (*Service) GetResourceVersion

func (s *Service) GetResourceVersion() string

GetResourceVersion implements the metav1.Object interface.

func (*Service) Headless

func (s *Service) Headless() bool

Headless returns true if the service is headless

func (*Service) SetName

func (s *Service) SetName(name string)

SetName implements the metav1.Object interface.

func (*Service) SetNamespace

func (s *Service) SetNamespace(namespace string)

SetNamespace implements the metav1.Object interface.

func (*Service) SetResourceVersion

func (s *Service) SetResourceVersion(version string)

SetResourceVersion implements the metav1.Object interface.

type ToFunc

type ToFunc func(v1.Object) (v1.Object, error)

ToFunc converts one v1.Object to another v1.Object.

Jump to

Keyboard shortcuts

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