components

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

nolint:gofumpt

nolint:gofumpt

nolint:gofumpt

nolint: gofumpt

Index

Constants

View Source
const DefaultRecAddress = "0.0.0.0"

Variables

View Source
var (
	GrpcProtocol    = "grpc"
	HttpProtocol    = "http"
	UnsetPort       int32
	ErrPortNotFound = errors.New("port should not be empty")
)

Functions

func AddressDefaulter

func AddressDefaulter(logger *zap.Logger, defaultRecAddr string, port int32, config *SingleEndpointConfig) (map[string]any, error)

func ComponentType

func ComponentType(name string) string

ComponentType returns the type for a given component name. components have a name like: - mycomponent/custom - mycomponent we extract the "mycomponent" part and see if we have a parser for the component.

func ConstructServicePort

func ConstructServicePort(current *corev1.ServicePort, port int32) corev1.ServicePort

func ParseSingleEndpoint

func ParseSingleEndpoint(logger *zap.Logger, name string, defaultPort *corev1.ServicePort, singleEndpointConfig *SingleEndpointConfig) ([]corev1.ServicePort, error)

func ParseSingleEndpointSilent

func ParseSingleEndpointSilent(logger *zap.Logger, name string, defaultPort *corev1.ServicePort, singleEndpointConfig *SingleEndpointConfig) ([]corev1.ServicePort, error)

func PortFromEndpoint

func PortFromEndpoint(endpoint string) (int32, error)

Types

type Builder

type Builder[ComponentConfigType any] []ParserOption[ComponentConfigType]

func NewBuilder

func NewBuilder[ComponentConfigType any]() Builder[ComponentConfigType]

func NewProtocolBuilder

func NewProtocolBuilder(name string, port int32) Builder[*MultiProtocolEndpointConfig]

func NewSilentSinglePortParserBuilder

func NewSilentSinglePortParserBuilder(name string, port int32) Builder[*SingleEndpointConfig]

func NewSinglePortParserBuilder

func NewSinglePortParserBuilder(name string, port int32) Builder[*SingleEndpointConfig]

func (Builder[ComponentConfigType]) Build

func (b Builder[ComponentConfigType]) Build() (*GenericParser[ComponentConfigType], error)

func (Builder[ComponentConfigType]) MustBuild

func (b Builder[ComponentConfigType]) MustBuild() *GenericParser[ComponentConfigType]

func (Builder[ComponentConfigType]) WithAppProtocol

func (b Builder[ComponentConfigType]) WithAppProtocol(appProtocol *string) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithDefaultRecAddress

func (b Builder[ComponentConfigType]) WithDefaultRecAddress(defaultRecAddr string) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithDefaultsApplier

func (b Builder[ComponentConfigType]) WithDefaultsApplier(defaultsApplier Defaulter[ComponentConfigType]) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithEnvVarGen

func (b Builder[ComponentConfigType]) WithEnvVarGen(envVarGen EnvVarGenerator[ComponentConfigType]) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithLivenessGen

func (b Builder[ComponentConfigType]) WithLivenessGen(livenessGen ProbeGenerator[ComponentConfigType]) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithName

func (b Builder[ComponentConfigType]) WithName(name string) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithNodePort

func (b Builder[ComponentConfigType]) WithNodePort(nodePort int32) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithPort

func (b Builder[ComponentConfigType]) WithPort(port int32) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithPortParser

func (b Builder[ComponentConfigType]) WithPortParser(portParser PortParser[ComponentConfigType]) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithProtocol

func (b Builder[ComponentConfigType]) WithProtocol(protocol corev1.Protocol) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithRbacGen

func (b Builder[ComponentConfigType]) WithRbacGen(rbacGen RBACRuleGenerator[ComponentConfigType]) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithReadinessGen

func (b Builder[ComponentConfigType]) WithReadinessGen(readinessGen ProbeGenerator[ComponentConfigType]) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithTargetPort

func (b Builder[ComponentConfigType]) WithTargetPort(targetPort int32) Builder[ComponentConfigType]

func (Builder[ComponentConfigType]) WithUrlPaths

func (b Builder[ComponentConfigType]) WithUrlPaths(urlPaths []string) Builder[ComponentConfigType]

mydecisive

type ComponentsPortsUrlPaths

type ComponentsPortsUrlPaths map[string][]PortUrlPaths

ComponentsPortsUrlPaths maps component name to the list of PortUrlPaths

type Defaulter

type Defaulter[ComponentConfigType any] func(logger *zap.Logger, defaultAddr string, defaultPort int32, config ComponentConfigType) (map[string]any, error)

Defaulter is a function that applies given defaults to the passed Config. It's expected that type Config is the configuration used by a parser.

type EnvVarGenerator

type EnvVarGenerator[ComponentConfigType any] func(logger *zap.Logger, config ComponentConfigType) ([]corev1.EnvVar, error)

EnvVarGenerator is a function that generates a list of environment variables for a given config. It's expected that type Config is the configuration used by a parser.

type GenericParser

type GenericParser[T any] struct {
	// contains filtered or unexported fields
}

GenericParser serves as scaffolding for custom parsing logic by isolating functionality to idempotent functions.

func (*GenericParser[T]) GetDefaultConfig

func (g *GenericParser[T]) GetDefaultConfig(logger *zap.Logger, config any) (any, error)

func (*GenericParser[T]) GetEnvironmentVariables

func (g *GenericParser[T]) GetEnvironmentVariables(logger *zap.Logger, config any) ([]corev1.EnvVar, error)

func (*GenericParser[T]) GetLivenessProbe

func (g *GenericParser[T]) GetLivenessProbe(logger *zap.Logger, config any) (*corev1.Probe, error)

func (*GenericParser[T]) GetRBACRules

func (g *GenericParser[T]) GetRBACRules(logger *zap.Logger, config any) ([]rbacv1.PolicyRule, error)

func (*GenericParser[T]) GetReadinessProbe

func (g *GenericParser[T]) GetReadinessProbe(logger *zap.Logger, config any) (*corev1.Probe, error)

func (*GenericParser[T]) ParserName

func (g *GenericParser[T]) ParserName() string

func (*GenericParser[T]) ParserType

func (g *GenericParser[T]) ParserType() string

func (*GenericParser[T]) Ports

func (g *GenericParser[T]) Ports(logger *zap.Logger, name string, config any) ([]corev1.ServicePort, error)

func (*GenericParser[T]) PortsWithUrlPaths

func (g *GenericParser[T]) PortsWithUrlPaths(logger *zap.Logger, name string, config any) ([]PortUrlPaths, error)

mydecisive

type MultiPortBuilder

type MultiPortBuilder[ComponentConfigType any] []Builder[ComponentConfigType]

func NewMultiPortReceiverBuilder

func NewMultiPortReceiverBuilder(name string) MultiPortBuilder[*MultiProtocolEndpointConfig]

func (MultiPortBuilder[ComponentConfigType]) AddPortMapping

func (mp MultiPortBuilder[ComponentConfigType]) AddPortMapping(builder Builder[ComponentConfigType]) MultiPortBuilder[ComponentConfigType]

func (MultiPortBuilder[ComponentConfigType]) Build

func (mp MultiPortBuilder[ComponentConfigType]) Build() (*MultiPortReceiver, error)

func (MultiPortBuilder[ComponentConfigType]) MustBuild

func (mp MultiPortBuilder[ComponentConfigType]) MustBuild() *MultiPortReceiver

type MultiPortOption

type MultiPortOption func(parser *MultiPortReceiver)

MultiPortOption allows the setting of options for a MultiPortReceiver.

type MultiPortReceiver

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

MultiPortReceiver is a special parser for components with endpoints for each protocol.

func (*MultiPortReceiver) GetDefaultConfig

func (m *MultiPortReceiver) GetDefaultConfig(logger *zap.Logger, config any) (any, error)

func (*MultiPortReceiver) GetEnvironmentVariables

func (m *MultiPortReceiver) GetEnvironmentVariables(logger *zap.Logger, config any) ([]corev1.EnvVar, error)

func (*MultiPortReceiver) GetLivenessProbe

func (m *MultiPortReceiver) GetLivenessProbe(logger *zap.Logger, config any) (*corev1.Probe, error)

func (*MultiPortReceiver) GetRBACRules

func (m *MultiPortReceiver) GetRBACRules(*zap.Logger, any) ([]rbacv1.PolicyRule, error)

func (*MultiPortReceiver) GetReadinessProbe

func (m *MultiPortReceiver) GetReadinessProbe(logger *zap.Logger, config any) (*corev1.Probe, error)

func (*MultiPortReceiver) ParserName

func (m *MultiPortReceiver) ParserName() string

func (*MultiPortReceiver) ParserType

func (m *MultiPortReceiver) ParserType() string

func (*MultiPortReceiver) Ports

func (m *MultiPortReceiver) Ports(logger *zap.Logger, name string, config any) ([]corev1.ServicePort, error)

func (*MultiPortReceiver) PortsWithUrlPaths

func (m *MultiPortReceiver) PortsWithUrlPaths(logger *zap.Logger, name string, config any) ([]PortUrlPaths, error)

type MultiProtocolEndpointConfig

type MultiProtocolEndpointConfig struct {
	Protocols map[string]*SingleEndpointConfig `mapstructure:"protocols"`
}

MultiProtocolEndpointConfig represents the minimal struct for a given YAML configuration input containing a map to a struct with either endpoint or listen_address.

type Parser

type Parser interface {
	// GetDefaultConfig returns a config with set default values.
	// NOTE: Config merging must be done by the caller if desired.
	GetDefaultConfig(logger *zap.Logger, config any) (any, error)

	// Ports returns the service ports parsed based on the component's configuration where name is the component's name
	// of the form "name" or "type/name"
	Ports(logger *zap.Logger, name string, config any) ([]corev1.ServicePort, error)

	// GetRBACRules returns the rbac rules for this component
	GetRBACRules(logger *zap.Logger, config any) ([]rbacv1.PolicyRule, error)

	// GetLivenessProbe returns a liveness probe set for the collector
	GetLivenessProbe(logger *zap.Logger, config any) (*corev1.Probe, error)

	// GetEnvironmentVariables returns a list of environment variables for the collector
	GetEnvironmentVariables(logger *zap.Logger, config any) ([]corev1.EnvVar, error)

	// GetReadinessProbe returns a readiness probe set for the collector
	GetReadinessProbe(logger *zap.Logger, config any) (*corev1.Probe, error)

	// ParserType returns the type of this parser
	ParserType() string

	// ParserName is an internal name for the parser
	ParserName() string

	// PortsWithUrlPaths returns the service ports + URL paths parsed based on the receiver's configuration
	PortsWithUrlPaths(logger *zap.Logger, name string, config any) ([]PortUrlPaths, error)
}

type ParserOption

type ParserOption[ComponentConfigType any] func(*Settings[ComponentConfigType])

type ParserRetriever

type ParserRetriever func(string) Parser

type PortParser

type PortParser[ComponentConfigType any] func(logger *zap.Logger, name string, defaultPort *corev1.ServicePort, config ComponentConfigType) ([]corev1.ServicePort, error)

PortParser is a function that returns a list of servicePorts given a config of type Config.

type PortRetriever

type PortRetriever interface {
	GetPortNum() (int32, error)
	//nolint:inamedparam
	GetPortNumOrDefault(*zap.Logger, int32) int32
}

type PortUrlPaths

type PortUrlPaths struct {
	Port     corev1.ServicePort
	UrlPaths []string
}

PortUrlPaths represents a service port and a list of URL paths

type ProbeGenerator

type ProbeGenerator[ComponentConfigType any] func(logger *zap.Logger, config ComponentConfigType) (*corev1.Probe, error)

ProbeGenerator is a function that generates a valid probe for a container given Config It's expected that type Config is the configuration used by a parser.

type RBACRuleGenerator

type RBACRuleGenerator[ComponentConfigType any] func(logger *zap.Logger, config ComponentConfigType) ([]rbacv1.PolicyRule, error)

RBACRuleGenerator is a function that generates a list of RBAC Rules given a configuration of type Config It's expected that type Config is the configuration used by a parser.

type Settings

type Settings[ComponentConfigType any] struct {
	// contains filtered or unexported fields
}

func NewEmptySettings

func NewEmptySettings[ComponentConfigType any]() *Settings[ComponentConfigType]

func (*Settings[ComponentConfigType]) Apply

func (o *Settings[ComponentConfigType]) Apply(opts ...ParserOption[ComponentConfigType])

func (*Settings[ComponentConfigType]) GetServicePort

func (o *Settings[ComponentConfigType]) GetServicePort() *corev1.ServicePort

type SingleEndpointConfig

type SingleEndpointConfig struct {
	Endpoint      string `mapstructure:"endpoint,omitempty" yaml:"endpoint,omitempty"`
	ListenAddress string `mapstructure:"listen_address,omitempty" yaml:"listen_address,omitempty"`
}

SingleEndpointConfig represents the minimal struct for a given YAML configuration input containing either endpoint or listen_address.

func (*SingleEndpointConfig) GetPortNum

func (g *SingleEndpointConfig) GetPortNum() (int32, error)

GetPortNum attempts to get the port for the given config. If it cannot, the UnsetPort and the given missingPortError are returned.

func (*SingleEndpointConfig) GetPortNumOrDefault

func (g *SingleEndpointConfig) GetPortNumOrDefault(logger *zap.Logger, p int32) int32

Directories

Path Synopsis
nolint:mnd
nolint:mnd
nolint:gofumpt
nolint:gofumpt
nolint:gofumpt
nolint:gofumpt

Jump to

Keyboard shortcuts

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