Help us shape the future of Go! Take the 2026 Go Developer Survey

kubernetes

package
v0.313.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 41 Imported by: 322

Documentation

Index

Constants

View Source
const (
	MetricLabelRoleAdd    = "add"
	MetricLabelRoleDelete = "delete"
	MetricLabelRoleUpdate = "update"
)
View Source
const (
	NodeLegacyHostIP = "LegacyHostIP"
)

Variables

View Source
var DefaultSDConfig = SDConfig{
	HTTPClientConfig: config.DefaultHTTPClientConfig,
}

DefaultSDConfig is the default Kubernetes SD configuration.

Functions

func GetControllerOf

func GetControllerOf(controllee metav1.Object) *metav1.OwnerReference

GetControllerOf returns a pointer to a copy of the controllerRef if controllee has a controller https://github.com/kubernetes/apimachinery/blob/cd2cae2b39fa57e8063fa1f5f13cfe9862db3d41/pkg/apis/meta/v1/controller_ref.go

Types

type AttachMetadataConfig

type AttachMetadataConfig struct {
	Node              bool `yaml:"node"`
	Namespace         bool `yaml:"namespace"`
	PodMetadataConfig `yaml:",inline"`
}

AttachMetadataConfig is the configuration for attaching additional metadata coming from namespaces or nodes on which the targets are scheduled.

type Discovery

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

Discovery implements the discoverer interface for discovering targets from Kubernetes.

func New

func New(l *slog.Logger, metrics discovery.DiscovererMetrics, conf *SDConfig) (*Discovery, error)

New creates a new Kubernetes discovery for the given role.

func (*Discovery) Run

func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group)

Run implements the discoverer interface.

type EndpointSlice

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

EndpointSlice discovers new endpoint targets.

func NewEndpointSlice

func NewEndpointSlice(l *slog.Logger, eps cache.SharedIndexInformer, svc, pod, node, namespace, rs, job cache.SharedInformer, withDeploymentMetadata, withJobMetadata, withCronJobMetadata bool, eventCount *prometheus.CounterVec) *EndpointSlice

NewEndpointSlice returns a new endpointslice discovery.

func (*EndpointSlice) Run

func (e *EndpointSlice) Run(ctx context.Context, ch chan<- []*targetgroup.Group)

Run implements the Discoverer interface.

type Endpoints deprecated

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

Endpoints discovers new endpoint targets.

Deprecated: The Endpoints API is deprecated starting in K8s v1.33+. Use EndpointSlice.

func NewEndpoints deprecated

func NewEndpoints(l *slog.Logger, eps cache.SharedIndexInformer, svc, pod, node, namespace, rs, job cache.SharedInformer, withDeploymentMetadata, withJobMetadata, withCronJobMetadata bool, eventCount *prometheus.CounterVec) *Endpoints

NewEndpoints returns a new endpoints discovery.

Deprecated: The Endpoints API is deprecated starting in K8s v1.33+. Use NewEndpointSlice.

func (*Endpoints) Run

func (e *Endpoints) Run(ctx context.Context, ch chan<- []*targetgroup.Group)

Run implements the Discoverer interface.

type Ingress

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

Ingress implements discovery of Kubernetes ingress.

func NewIngress

func NewIngress(l *slog.Logger, inf cache.SharedIndexInformer, namespace cache.SharedInformer, eventCount *prometheus.CounterVec) *Ingress

NewIngress returns a new ingress discovery.

func (*Ingress) Run

func (i *Ingress) Run(ctx context.Context, ch chan<- []*targetgroup.Group)

Run implements the Discoverer interface.

type NamespaceDiscovery

type NamespaceDiscovery struct {
	IncludeOwnNamespace bool     `yaml:"own_namespace"`
	Names               []string `yaml:"names"`
}

NamespaceDiscovery is the configuration for discovering Kubernetes namespaces.

func (*NamespaceDiscovery) UnmarshalYAML

func (c *NamespaceDiscovery) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Node

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

Node discovers Kubernetes nodes.

func NewNode

func NewNode(l *slog.Logger, inf cache.SharedInformer, eventCount *prometheus.CounterVec) *Node

NewNode returns a new node discovery.

func (*Node) Run

func (n *Node) Run(ctx context.Context, ch chan<- []*targetgroup.Group)

Run implements the Discoverer interface.

type Pod

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

Pod discovers new pod targets.

func NewPod

func NewPod(l *slog.Logger, pods cache.SharedIndexInformer, nodes, namespace, replicaSets, jobs cache.SharedInformer, withDeploymentMetadata, withJobMetadata, withCronJobMetadata bool, eventCount *prometheus.CounterVec) *Pod

NewPod creates a new pod discovery.

func (*Pod) Run

func (p *Pod) Run(ctx context.Context, ch chan<- []*targetgroup.Group)

Run implements the Discoverer interface.

type PodMetadataConfig added in v0.311.0

type PodMetadataConfig struct {
	Deployment bool `yaml:"deployment"`
	Job        bool `yaml:"job"`
	CronJob    bool `yaml:"cronjob"`
}

PodMetadataConfig allows configuring which pod-related metadata to attach.

type Role

type Role string

Role is role of the service in Kubernetes.

const (
	RoleNode          Role = "node"
	RolePod           Role = "pod"
	RoleService       Role = "service"
	RoleEndpoint      Role = "endpoints"
	RoleEndpointSlice Role = "endpointslice"
	RoleIngress       Role = "ingress"
)

The valid options for Role.

func (Role) String added in v0.50.0

func (c Role) String() string

func (*Role) UnmarshalYAML

func (c *Role) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type SDConfig

type SDConfig struct {
	APIServer          config.URL              `yaml:"api_server,omitempty"`
	Role               Role                    `yaml:"role"`
	KubeConfig         string                  `yaml:"kubeconfig_file"`
	HTTPClientConfig   config.HTTPClientConfig `yaml:",inline"`
	NamespaceDiscovery NamespaceDiscovery      `yaml:"namespaces,omitempty"`
	Selectors          []SelectorConfig        `yaml:"selectors,omitempty"`
	AttachMetadata     AttachMetadataConfig    `yaml:"attach_metadata,omitempty"`
}

SDConfig is the configuration for Kubernetes service discovery.

func (*SDConfig) Name

func (*SDConfig) Name() string

Name returns the name of the Config.

func (*SDConfig) NewDiscoverer

func (c *SDConfig) NewDiscoverer(opts discovery.DiscovererOptions) (discovery.Discoverer, error)

NewDiscoverer returns a Discoverer for the Config.

func (*SDConfig) NewDiscovererMetrics added in v0.50.0

NewDiscovererMetrics implements discovery.Config.

func (*SDConfig) SetDirectory

func (c *SDConfig) SetDirectory(dir string)

SetDirectory joins any relative file paths with dir.

func (*SDConfig) UnmarshalYAML

func (c *SDConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type SelectorConfig

type SelectorConfig struct {
	Role  Role   `yaml:"role,omitempty"`
	Label string `yaml:"label,omitempty"`
	Field string `yaml:"field,omitempty"`
}

type Service

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

Service implements discovery of Kubernetes services.

func NewService

func NewService(l *slog.Logger, inf cache.SharedIndexInformer, namespace cache.SharedInformer, eventCount *prometheus.CounterVec) *Service

NewService returns a new service discovery.

func (*Service) Run

func (s *Service) Run(ctx context.Context, ch chan<- []*targetgroup.Group)

Run implements the Discoverer interface.

Jump to

Keyboard shortcuts

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