Skip to content

Option to let the environment take precedence over configurations - #664

Open
tlercher wants to merge 1 commit into
alecthomas:masterfrom
tlercher:feat/env-overrides-configuration
Open

tlercher wants to merge 1 commit into
alecthomas:masterfrom
tlercher:feat/env-overrides-configuration

Conversation

@tlercher

Copy link
Copy Markdown

Some people are confused by the choice Kong did which prefers Configuration (files) over Environment Variables.

This happened to me yesterday and colleagues of mine as well friends intuition would be the opposite.
FWIW: This is a topic with a bit of history12.

Instead of implementing a custom loader in every project i use Kong i thought why not bring this topic up again and maybe even resolve #566 with it.

I found two groups of related issues, 1 which are mostly about how it works, while 2 was about moving loading environments via resolver. The latter introduced breaking changes.

So this MR is purely about allowing users to swap this behavior (... > Config > Env > ... to ... > Env > Config > ...) to align the behavior of Kong more with the expectations which are common in the DevOps world.

To not introduce any breaking changes i've made this a callable Option from kong.Parse(...).
Maybe also in the hopes we could have a separate discussion3 if we could make this the default behavior with a new major release.
(The less knobs the better IMO)

Anyway. Since 1.x already made a breaking change, maybe we can find a way to stagger the change over multiple releases?

Footnotes

  1. Related Issues over time Flag / Env / Config / Default argument ordering #566, Precedence order when config file is specified on the command line #249, Precedence order when config file is specified on the command line #254, Questions about setting the path to the config file path on the command line in Kong  #351, Questions about setting the path to the config file path on the command line in Kong #353 ↩ ↩2

  2. Load Env via Resolver Load environment variables as a resolver #480 (reverted), 1.8.0 broke environment resolving #497 and 1.8.0 seems to introduce breaking change to custom decoders #498 ↩ ↩2

  3. Where i can provide arguments and examples etc. why i think such a change might be a welcome one for users ↩

By default, values from configuration files loaded via Configuration or
ConfigFlag take precedence over environment variables from `env` tags:
flag > configuration > env > default.

EnvOverridesConfiguration swaps configuration files and environment
variables, so the precedence becomes flag > env > configuration >
default. Other resolvers are not affected. The option is opt-in so the
default behaviour is unchanged.

Also document the precedence of values in the README.
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