Skip to content

Read configuration from env into typed options structs (koanf) - #381

Draft
fwiesel wants to merge 3 commits into
mainfrom
config/koanf
Draft

fwiesel wants to merge 3 commits into
mainfrom
config/koanf

Conversation

@fwiesel

@fwiesel fwiesel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Read operator settings from environment variables into module-owned
options structs with koanf.
The loader starts with local typed defaults. The environment provider
supplies raw strings, which generic mapstructure hooks decode as lists
or text values. The loader uses no confmap provider or trait-specific
reflection hook.

TraitConcurrency stores integer limits. Set and UnmarshalText
reject invalid entries before a later duplicate can hide an error.
A failed parse leaves the previous map unchanged. Valid duplicates
retain the last value. Explicit empty values remain visible to startup
validation instead of receiving defaults again.

Adding a tagged field needs no loader branch or flag registry in cmd.
A setting with a nonzero default can require a change to the typed
default values. Chart exposure and validation can require separate
changes. An external overlay checks that a new []string field receives
a comma-separated environment value without a change in cmd.

The three commits keep these concerns separate:

  1. Read environment settings into typed options and validate them.
  2. Remove the six --flag=$(ENV_VAR) chart arguments.
  3. Generate optional CLI flags with sflags.

The CLI commit contains the description tags and trait rendering methods.
CLI values override environment values. Environment values override the
local defaults. The chart commit remains separate and reversible.

Existing tests retain the option wiring and integer trait fixtures.
No new tests are committed. External acceptance and reviewer probes
check parsing, defaults, empty values, CLI replacement, and field discovery.

Relates to #13.

Kubernetes uses the environment as the main configuration interface.
Read settings into module-owned options so controllers do not depend
on process-wide configuration. Local typed values supply defaults.
Explicit empty values remain visible to startup validation.

Generic decoder hooks let tagged fields receive comma-separated
lists and text values without a registry in cmd. Typed trait limits
reject invalid entries before a later duplicate can hide an error.
New fields need no loader branch. Nonzero defaults can still require
changes to the typed default values, and chart exposure is separate.

Keep flag descriptions and rendering in the later CLI commit so
environment configuration does not depend on flag-only metadata.

Signed-off-by: Fabian Wiesel <[email protected]>
The manager reads its settings from the environment, so drop the
--flag=$(ENV_VAR) container arguments.

Signed-off-by: Fabian Wiesel <[email protected]>
Operators need to inspect and override settings from the command line.
Generate flags from the module-owned options and use environment
values as their defaults. Explicit CLI values replace those values.

Keep descriptions and trait rendering here so the environment-only
commit needs no flag metadata or rendering methods. Field discovery
requires no per-setting registration in cmd.

Signed-off-by: Fabian Wiesel <[email protected]>
@github-actions

Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/config 0.00% (ø)
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller 74.26% (-0.51%) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/eviction 58.87% (-9.00%) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/global 0.00% (-100.00%) 💀 💀 💀 💀 💀
Coverage details

Compared to commit f5172c4 (run #41086905849)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/cmd/config.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/cmd/main.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/config/options.go 0.00% (ø) 10 (+10) 0 10 (+10)
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/eviction/controller.go 67.53% (-0.35%) 194 (+1) 131 63 (+1) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/eviction/options.go 13.51% (+13.51%) 37 (+37) 5 (+5) 32 (+32) 🎉
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/hypervisor_controller.go 79.34% (-0.66%) 121 (+1) 96 25 (+1) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/node_certificate_controller.go 80.95% (ø) 42 34 8
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/options.go 0.00% (ø) 5 (+5) 0 5 (+5)
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/global/global.go 0.00% (-100.00%) 0 (-7) 0 (-7) 0 💀 💀 💀 💀 💀

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files:

  • github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/eviction/controller_test.go
  • github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/hypervisor_controller_test.go
  • github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/global/global_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant