feat(configuration): Allow environment variable overrides for config#4818
feat(configuration): Allow environment variable overrides for config#4818lucasreed wants to merge 3 commits into
Conversation
Signed-off-by: Luke Reed <luke@lreed.net>
0c686ef to
a81c6ba
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4818 +/- ##
==========================================
+ Coverage 28.09% 28.14% +0.05%
==========================================
Files 232 232
Lines 23141 23181 +40
==========================================
+ Hits 6501 6525 +24
- Misses 16200 16212 +12
- Partials 440 444 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
nice approach, the viper one thing to watch also didn't see tests in the diff even a small one that sets an env var and asserts the override lands in the final config would be solid. docs addition is great, especially the camelCase mapping table. |
Ah great call out thank you! Just updated and include a couple tests. Let me know what you think! |
Signed-off-by: Luke Reed <luke@lreed.net>
Signed-off-by: Luke Reed <luke@lreed.net>
ed6b36e to
422b4d6
Compare
|
nice, pulled and ran the tests locally — all 4 pass. materializeStructPtrs is a solid fix for the nil pointer case, and testing against the real scheduler config is a good call. lgtm 👍 |
|
@gaius-qi Let me know if there is anything else I need to do for this PR. Would love to make use of this change soon if possible :) |
Description
The goal is to support environment variable configuration that overrides the config file at runtime.
The helper
bindEnvsFromConfigexists to work around a viper limitation.viper.AutomaticEnv()does not make env vars visible to viper.Unmarshal() if they aren't in the loaded config yaml. For any key that lives only in your struct and isn't present in the loaded YAML, AutomaticEnv silently does nothing on unmarshal, so you have to explicitly BindEnv every key. The helper flattens the default config and does BindEnv each key.Reference:
Related Issue
#1108 and #3165 are marked as completed, but the only env var I've seen is to change the location of the config file.
Motivation and Context
The main motivation here is not storing secrets plainly in a configmap or helm values file in order to run dragonfly with an external database (not using the bundled mysql and redis helm charts)
Screenshots (if appropriate)
N/A
Types of changes
Checklist
I updated the docker-compose README, but It looks like the documentation on the website is in a different repo. I'm happy to open another PR there if this is approved/merged/released.