config

package
v0.151.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultListenAddr                                  = ":8080"
	DefaultHttpsListenAddr                             = ":8443"
	DefaultResyncTime                                  = 5 * time.Minute
	DefaultConfigFilePath               string         = "/conf/targetallocator.yaml"
	DefaultCRScrapeInterval             model.Duration = model.Duration(time.Second * 30)
	DefaultAllocationStrategy                          = "consistent-hashing"
	DefaultFilterStrategy                              = "relabel-config"
	DefaultCollectorNotReadyGracePeriod                = 30 * time.Second
)

Variables

View Source
var DefaultKubeConfigFilePath = filepath.Join(homedir.HomeDir(), ".kube", "config")

logger which discards all messages written to it. Replace this with slog.DiscardHandler after we require Go 1.24.

Functions

func LoadFromCLI

func LoadFromCLI(target *Config, flagSet *pflag.FlagSet) error

func LoadFromEnv added in v0.121.0

func LoadFromEnv(target *Config) error

LoadFromEnv loads configuration from environment variables.

func LoadFromFile

func LoadFromFile(file string, target *Config) error

func MapToLabelSelector

func MapToLabelSelector() mapstructure.DecodeHookFuncType

MapToLabelSelector returns a DecodeHookFuncType that provides a mechanism for decoding both matchLabels and matchExpressions from camelcase to lowercase because we use yaml unmarshaling that supports lowercase field names if no `yaml` tag is defined and metav1.LabelSelector uses `json` tags. If both the camelcase and lowercase version is present, then the camelcase version takes precedence.

func MapToPromConfig

func MapToPromConfig() mapstructure.DecodeHookFuncType

MapToPromConfig returns a DecodeHookFuncType that provides a mechanism for decoding promconfig.Config involving its own unmarshal logic.

func StringToModelOrTimeDurationHookFunc added in v0.122.0

func StringToModelOrTimeDurationHookFunc() mapstructure.DecodeHookFuncType

StringToModelOrTimeDurationHookFunc returns a DecodeHookFuncType that converts string to time.Duration, which can also be used as model.Duration.

func ValidateConfig

func ValidateConfig(config *Config) error

ValidateConfig validates the cli and file configs together.

Types

type CAReloader added in v0.145.0

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

CAReloader manages CA certificate reloading for client verification. It provides thread-safe access to the current CA certificate pool and can be triggered to reload via the Reload() method, typically called by a cert watcher callback.

func NewCAReloader added in v0.145.0

func NewCAReloader(caPath string, logger logr.Logger) (*CAReloader, error)

NewCAReloader creates a new CAReloader and loads the initial CA certificate.

func (*CAReloader) GetClientCAs added in v0.145.0

func (r *CAReloader) GetClientCAs() *x509.CertPool

GetClientCAs returns the current CA certificate pool for client verification. This method is safe for concurrent access and is called during TLS handshakes.

func (*CAReloader) Reload added in v0.145.0

func (r *CAReloader) Reload() error

Reload reads the CA certificate file from disk and updates the cached certificate pool. This method is thread-safe and can be called concurrently.

type Config

type Config struct {
	ListenAddr                   string                `yaml:"listen_addr,omitempty"`
	KubeConfigFilePath           string                `yaml:"kube_config_file_path,omitempty"`
	ClusterConfig                *rest.Config          `yaml:"-"`
	RootLogger                   logr.Logger           `yaml:"-"`
	CollectorSelector            *metav1.LabelSelector `yaml:"collector_selector,omitempty"`
	CollectorNamespace           string                `yaml:"collector_namespace,omitempty"`
	PromConfig                   *promconfig.Config    `yaml:"config"`
	AllocationStrategy           string                `yaml:"allocation_strategy,omitempty"`
	AllocationFallbackStrategy   string                `yaml:"allocation_fallback_strategy,omitempty"`
	FilterStrategy               string                `yaml:"filter_strategy,omitempty"`
	PrometheusCR                 PrometheusCRConfig    `yaml:"prometheus_cr,omitempty"`
	HTTPS                        HTTPSServerConfig     `yaml:"https,omitempty"`
	CollectorNotReadyGracePeriod time.Duration         `yaml:"collector_not_ready_grace_period,omitempty"`
}

func CreateDefaultConfig

func CreateDefaultConfig() Config

func Load

func Load(args []string) (*Config, error)

type HTTPSServerConfig

type HTTPSServerConfig struct {
	Enabled         bool   `yaml:"enabled,omitempty"`
	ListenAddr      string `yaml:"listen_addr,omitempty"`
	CAFilePath      string `yaml:"ca_file_path,omitempty"`
	TLSCertFilePath string `yaml:"tls_cert_file_path,omitempty"`
	TLSKeyFilePath  string `yaml:"tls_key_file_path,omitempty"`
}

func (HTTPSServerConfig) NewTLSConfig

func (c HTTPSServerConfig) NewTLSConfig(logger logr.Logger) (*tls.Config, *certwatcher.CertWatcher, error)

type PrometheusCRConfig

type PrometheusCRConfig struct {
	Enabled                         bool                          `yaml:"enabled,omitempty"`
	AllowNamespaces                 []string                      `yaml:"allow_namespaces,omitempty"`
	DenyNamespaces                  []string                      `yaml:"deny_namespaces,omitempty"`
	SecretNamespaces                []string                      `yaml:"secret_namespaces,omitempty"`
	PodMonitorSelector              *metav1.LabelSelector         `yaml:"pod_monitor_selector,omitempty"`
	PodMonitorNamespaceSelector     *metav1.LabelSelector         `yaml:"pod_monitor_namespace_selector,omitempty"`
	ServiceMonitorSelector          *metav1.LabelSelector         `yaml:"service_monitor_selector,omitempty"`
	ServiceMonitorNamespaceSelector *metav1.LabelSelector         `yaml:"service_monitor_namespace_selector,omitempty"`
	ScrapeConfigSelector            *metav1.LabelSelector         `yaml:"scrape_config_selector,omitempty"`
	ScrapeConfigNamespaceSelector   *metav1.LabelSelector         `yaml:"scrape_config_namespace_selector,omitempty"`
	ProbeSelector                   *metav1.LabelSelector         `yaml:"probe_selector,omitempty"`
	ProbeNamespaceSelector          *metav1.LabelSelector         `yaml:"probe_namespace_selector,omitempty"`
	ScrapeInterval                  model.Duration                `yaml:"scrape_interval,omitempty"`
	EvaluationInterval              model.Duration                `yaml:"evaluation_interval,omitempty"`
	ScrapeProtocols                 []monitoringv1.ScrapeProtocol `yaml:"scrape_protocols,omitempty"`
	ScrapeClasses                   []monitoringv1.ScrapeClass    `yaml:"scrape_classes,omitempty"`
}

func (PrometheusCRConfig) GetAllowDenyLists added in v0.121.0

func (c PrometheusCRConfig) GetAllowDenyLists() (allowList, denyList map[string]struct{})

func (PrometheusCRConfig) GetSecretsAllowList added in v0.151.0

func (c PrometheusCRConfig) GetSecretsAllowList(collectorNamespace string) map[string]struct{}

GetSecretsAllowList returns the namespaces to watch for secrets as a map. If SecretNamespaces is explicitly configured, those namespaces are used. Otherwise, it defaults to the collectorNamespace (the target allocator's own namespace).

Jump to

Keyboard shortcuts

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