app

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 11

Documentation

Index

Constants

View Source
const (
	DefaultTempDir         = "/tmp/addon-operator"
	DefaultDebugUnixSocket = "/var/run/addon-operator/debug.socket"
)
View Source
const (
	ForcedDurationForDebugLevel = 30 * time.Minute
	ProxyJsonLogKey             = "proxyJsonLog"
)

ForcedDurationForDebugLevel - force expiration for debug level.

Variables

View Source
var (
	AppName        = "addon-operator"
	AppDescription = ""
	Version        = "dev"

	// AppStartMessage is the line logged at the start of the operator. The
	// binary entrypoint can override it (e.g. to embed the version).
	// Mirrors what shell-operator exposes as app.AppStartMessage so callers
	// no longer have to write into shell-operator globals.
	AppStartMessage = AppName

	ListenAddress = "0.0.0.0"
	ListenPort    = "9650"

	DefaultPrometheusMetricsPrefix = "addon_operator_"
	PrometheusMetricsPrefix        = DefaultPrometheusMetricsPrefix

	Helm3HistoryMax   int32 = 10
	Helm3Timeout            = 20 * time.Minute
	HelmIgnoreRelease       = ""

	HelmMonitorKubeClientQpsDefault   = "5"
	HelmMonitorKubeClientQps          float32
	HelmMonitorKubeClientBurstDefault = "10"
	HelmMonitorKubeClientBurst        int

	Namespace     = ""
	ConfigMapName = "addon-operator"

	GlobalHooksDir = "global-hooks"
	ModulesDir     = "modules"
	TempDir        = ""
	ShellChrootDir = ""

	UnnumberedModuleOrder = 1

	AdmissionServerListenPort = "9651"
	AdmissionServerCertsDir   = ""
	AdmissionServerEnabled    = false

	// StrictModeEnabled fail with error if MODULES_DIR/values.yaml does not exist
	StrictModeEnabled = false

	// AppliedExtenders defines the list and the order of applied module extenders
	AppliedExtenders = ""

	// ExtraLabels defines strings for CRDs label selector
	ExtraLabels = "heritage=addon-operator"
	// CRDsFilters defines filters for CRD files, example `doc-,_`
	CRDsFilters = "doc-,_"

	// NumberOfParallelQueues defines the number of precreated parallel queues for parallel execution
	NumberOfParallelQueues   = 20
	ParallelQueuePrefix      = "parallel_queue"
	ParallelQueueNamePattern = ParallelQueuePrefix + "_%d"

	// Kube client settings (previously from shell-operator globals)
	KubeContext     string
	KubeConfig      string
	KubeServer      string
	KubeClientQPS   float32
	KubeClientBurst int

	ObjectPatcherKubeClientQPS     float32
	ObjectPatcherKubeClientBurst   int
	ObjectPatcherKubeClientTimeout time.Duration

	// Debug settings (previously from shell-operator globals)
	DebugUnixSocket     string
	DebugHTTPServerAddr string
	DebugKeepTmpFiles   bool
	DebugKubernetesAPI  bool

	// Log settings (previously from shell-operator globals)
	LogLevel         string
	LogType          string
	LogNoTime        bool
	LogProxyHookJSON bool
)

Functions

func ApplyConfig added in v1.21.0

func ApplyConfig(cfg *Config)

ApplyConfig copies Config values into package-level variables for backward compatibility with code that reads them directly (e.g. module_manager).

func BindFlags added in v1.21.0

func BindFlags(cfg *Config, rootCmd *cobra.Command, cmd *cobra.Command)

BindFlags registers all operator CLI flags on cmd, using the current cfg values (already merged with env vars and hardcoded defaults) as flag defaults. An explicit CLI flag always wins.

func DefineDebugCommands

func DefineDebugCommands(rootCmd *cobra.Command)

func DefineDebugUnixSocketFlag added in v1.21.2

func DefineDebugUnixSocketFlag(cmd *cobra.Command)

DefineDebugUnixSocketFlag registers the --debug-unix-socket flag on cmd, binding it to the package-level DebugUnixSocket variable. Debug sub-commands (queue, hook, config, etc.) use this to locate the operator's debug socket without depending on shell-operator's app globals.

func ParseEnv added in v1.21.0

func ParseEnv(cfg *Config) error

ParseEnv overrides cfg fields with values from environment variables. Fields whose env var is not set retain their current values, so hardcoded defaults from NewConfig are preserved when no env var is present.

Both addon-operator's own variables (ADDON_OPERATOR_*, HELM_*, shared KUBE_*, OBJECT_PATCHER_*, DEBUG_*, LOG_*) and the shell-operator-side variables that have no ADDON_OPERATOR_* counterpart (SHELL_OPERATOR_* HOOKS_DIR / TMP_DIR / LISTEN_ADDRESS / LISTEN_PORT / PROMETHEUS_METRICS_PREFIX / NAMESPACE) are recognized. ADDON_OPERATOR_* wins when both are set because it is applied last and overlays whatever shell-operator envs put in cfg.

IMPORTANT: ParseEnv must only be invoked on the binary/CLI path, never on a caller-supplied *Config (see addon_operator.resolveConfig). Library users who pass WithConfig rely on env vars being ignored.

func SetupLogging added in v1.21.2

func SetupLogging(level string, runtimeConfig Registerer, logger *log.Logger)

SetupLogging sets the log level and registers a runtime config hook so the level can be changed without restarting the operator. It mirrors the helper previously provided by shell-operator's app package so addon-operator no longer depends on shell-operator globals for log setup.

Types

type AdmissionSettings added in v1.21.0

type AdmissionSettings struct {
	ListenPort string `env:"ADMISSION_SERVER_LISTEN_PORT"`
	CertsDir   string `env:"ADMISSION_SERVER_CERTS_DIR"`
	Enabled    bool   `env:"ADMISSION_SERVER_ENABLED"`
}

type AppSettings added in v1.21.0

type AppSettings struct {
	ModulesDir     string `env:"MODULES_DIR"`
	GlobalHooksDir string `env:"GLOBAL_HOOKS_DIR"`
	TempDir        string `env:"TMP_DIR"`
	Namespace      string `env:"NAMESPACE"`
	ListenAddress  string `env:"LISTEN_ADDRESS"`
	ListenPort     string `env:"LISTEN_PORT"`
	ConfigMapName  string `env:"CONFIG_MAP"`

	PrometheusMetricsPrefix string `env:"PROMETHEUS_METRICS_PREFIX"`

	UnnumberedModuleOrder int `env:"UNNUMBERED_MODULES_ORDER"`

	ShellChrootDir string `env:"SHELL_CHROOT_DIR"`

	StrictModeEnabled bool   `env:"STRICT_CHECK_VALUES_MODE_ENABLED"`
	AppliedExtenders  string `env:"APPLIED_MODULE_EXTENDERS"`
	ExtraLabels       string `env:"CRD_EXTRA_LABELS"`
	CRDsFilters       string `env:"CRD_FILTER_PREFIXES"`
}

type Config added in v1.21.0

type Config struct {
	App           AppSettings           `envPrefix:"ADDON_OPERATOR_"`
	Helm          HelmSettings          `envPrefix:"HELM_"`
	Admission     AdmissionSettings     `envPrefix:"ADDON_OPERATOR_"`
	Kube          KubeSettings          `envPrefix:"KUBE_"`
	ObjectPatcher ObjectPatcherSettings `envPrefix:"OBJECT_PATCHER_"`
	Debug         DebugSettings         `envPrefix:"DEBUG_"`
	Log           LogSettings           `envPrefix:"LOG_"`
}

Config is the single source of truth for addon-operator configuration. Populate it in stages: NewConfig sets hardcoded defaults, ParseEnv overrides with environment variables, BindFlags registers CLI flags whose defaults are the current cfg values so that an explicit flag always wins. Priority: CLI flags > env vars > hardcoded defaults.

func NewConfig added in v1.21.0

func NewConfig() *Config

type DebugSettings added in v1.21.0

type DebugSettings struct {
	UnixSocket     string `env:"UNIX_SOCKET"`
	HTTPServerAddr string `env:"HTTP_SERVER_ADDR"`
	KeepTmpFiles   bool   `env:"KEEP_TMP_FILES"`
	KubernetesAPI  bool   `env:"KUBERNETES_API"`
}

type HelmSettings added in v1.21.0

type HelmSettings struct {
	HistoryMax    int32         `env:"HISTORY_MAX"`
	Timeout       time.Duration `env:"TIMEOUT"`
	IgnoreRelease string        `env:"IGNORE_RELEASE"`

	MonitorKubeClientQps   float32 `env:"MONITOR_KUBE_CLIENT_QPS"`
	MonitorKubeClientBurst int     `env:"MONITOR_KUBE_CLIENT_BURST"`
}

type KubeSettings added in v1.21.0

type KubeSettings struct {
	Context     string  `env:"CONTEXT"`
	Config      string  `env:"CONFIG"`
	Server      string  `env:"SERVER"`
	ClientQPS   float32 `env:"CLIENT_QPS"`
	ClientBurst int     `env:"CLIENT_BURST"`
}

type LogSettings added in v1.21.0

type LogSettings struct {
	Level         string `env:"LEVEL"`
	Type          string `env:"TYPE"`
	NoTime        bool   `env:"NO_TIME"`
	ProxyHookJSON bool   `env:"PROXY_HOOK_JSON"`
}

type ObjectPatcherSettings added in v1.21.0

type ObjectPatcherSettings struct {
	KubeClientQPS     float32       `env:"KUBE_CLIENT_QPS"`
	KubeClientBurst   int           `env:"KUBE_CLIENT_BURST"`
	KubeClientTimeout time.Duration `env:"KUBE_CLIENT_TIMEOUT"`
}

type Registerer added in v1.21.2

type Registerer interface {
	Register(key string, help string, defaultValue string,
		setter func(key string, newValue string) error,
		expirer func(key string, newValue string) time.Duration)
}

Registerer is the minimal runtime-config surface SetupLogging needs to register a hook that updates the log level on the fly. shell-operator's runtime config package implements this interface.

Jump to

Keyboard shortcuts

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