Skip to content

Read configuration from env into typed options structs - #382

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

fwiesel wants to merge 3 commits into
mainfrom
config/envconfig

Conversation

@fwiesel

@fwiesel fwiesel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Parse the operator configuration into module-owned options structs filled from
environment variables by
kelseyhightower/envconfig, so
introducing a parameter only touches the options struct and the chart's env
values: the env name, the default and the description live in the struct tags,
and invalid values fail once at startup with an error naming the setting. An
explicitly set but empty environment variable takes effect instead of silently
falling back to the default. The chart drops the --flag=$(ENV_VAR) arguments
in a separate, revertable commit.

Trait concurrency limits use integer values. The parser requires positive
decimal integers in every TRAIT=N entry. An invalid entry rejects the whole
input without replacing the previous map, even if a valid duplicate follows.
Valid duplicates keep the last value. Environment input must parse before CLI
flags can override it.

A separate commit re-adds the optional CLI flags via
sflags, generated from the same options
structs with the environment values as the flag defaults. The precedence is
command line, then environment, then built-in default. This commit also owns
the desc tags and the trait value's String() and Type() methods.

Existing tests are updated for the option wiring; no new tests.

Relates to #13.

Kubernetes uses the environment as the primary configuration interface.
Module-owned options keep each environment name and default with its
field. kelseyhightower/envconfig fills these structs at startup. An
explicitly empty environment value takes effect without a default.

Parse trait limits as positive decimal integers before duplicate entries
can hide an invalid value. Reject the complete input without replacing
the previous map. Keep controller validation and concurrency guards for
options that callers construct directly.

Keep flag descriptions and value rendering in the later CLI commit so
this commit depends only on envconfig for configuration parsing.

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

Signed-off-by: Fabian Wiesel <[email protected]>
Operators can still inspect and override the settings from the command
line. The flags are generated from the same options structs with
sflags, and the env-derived values become their defaults, so the
precedence is command line, then environment, then the built-in
default. This keeps the flag names, descriptions and defaults that
the chart used before it passed the settings via the environment.

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 59.13% (-8.75%) 👎
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/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.89% (+13.89%) 36 (+36) 5 (+5) 31 (+31) 🎉
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