-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Structured Configuration and context values overrides #2024
Conversation
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
waiting for a comment from upstream .... I get why the order of merging config gets twisted around when running The only other solution I see would be to implement our own merging algorithm, that keeps track of the differen types of config sources and can differentiate between the |
changes to the extensions should be limited to blocks like the one seeing in the proxy command: Before: func(ctx *cli.Context) error {
return ParseConfig(ctx, cfg)
beforeOverride := config.Config{}
if err := copier.Copy(&beforeOverride, cfg); err != nil {
return err
}
if err := ParseConfig(ctx, cfg); err != nil {
return err
}
if err := mergo.Merge(cfg, beforeOverride, mergo.WithOverride); err != nil {
return err
}
return nil
}, |
Configuration Concept
Some Axioms
Config File Contentsocis.yaml: proxy:
http:
addr: "0.0.0.0:1111"
accounts:
http:
addr: "0.0.0.0:2222" proxy.yaml http:
addr: "0.0.0.0:3333" http:
addr: "0.0.0.0:4444" |
@butonic since b0ee695 we can now load the proxy policies from a file, that only holds proxy policies). This is how to use it:
[
{
"name": "ocis",
"routes": [
{
"endpoint": "/",
"backend": "http://localhost:9100"
}
]
}
] MICRO_LOG_LEVEL=error OCIS_LOG_PRETTY=true OCIS_LOG_COLOR=true OCIS_LOG_LEVEL=debug PROXY_POLICIES_FILE=proxy_policies.json bin/ocis proxy
2021-07-08T16:19:19+02:00 DBG Tracing is not enabled service=proxy
2021-07-08T16:19:19+02:00 INF loaded proxy policies service=proxy source="policies file"
2021-07-08T16:19:19+02:00 WRN policy-selector not configured. Will always use first policy: 'ocis' service=proxy
2021-07-08T16:19:19+02:00 DBG loading policy-selector selector_config={"Migration":null,"Static":{"Policy":"ocis"}} service=proxy
2021-07-08T16:19:19+02:00 DBG adding route route={"ApacheVHost":false,"Backend":"http://localhost:9100","Endpoint":"/","Type":""} service=proxy
2021-07-08T16:19:19+02:00 WRN No tls certificate provided, using a generated one service=proxy
2021-07-08T16:19:19+02:00 INF starting server addr=0.0.0.0:9200 service=proxy transport=https
2021-07-08T16:19:19+02:00 INF starting server addr=0.0.0.0:9205 service=proxy transport=debug The log was updated to reflect the source of the policies, in this case
|
Trying to run
I need this because I run the dev container behind traefik ... but the browseor gives me And in a debug level log I see:
so it indeed seems to ignore the Also, I added a row in #2024 (comment) ... I think I know what should happen but maybe you can copy the great explanation into a dev docs section? |
bf96e3a
to
2262e47
Compare
|
||
// Default are values stored in the flagset, but moved to a struct. | ||
func DefaultConfig() Config { | ||
return Config{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not compatible with flaex. We need to change the config parser and then make this change to every extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
808e2f1
to
0382624
Compare
df03ece
to
b9c9c89
Compare
b9c9c89
to
a498d61
Compare
a498d61
to
b99a464
Compare
Kudos, SonarCloud Quality Gate passed! |
can we close this PR in favor of #2708? |
Configuring oCIS
Use Cases
Supervised
Something to keep in mind is that commands sent to the runtime to control started extensions neither accept cli flags, nor environment variables. The only way to configure an extension this way is via global config files or individual config files.
Let's have a look at some scenarios where we run
ocis server
:ocis.yaml
configextension.yaml
config file, no globalocis.yaml
configextension.yaml
config file and a globalocis.yaml
configUnsupervised
ocis proxy
ocis.yaml
is present it will get loaded and configure the proxy.ocis.yaml
+proxy.yaml
are both present in expected locations,ocis.yaml
will override values fromproxy.yaml
, however, values will be merged. Let's see an example:ocis.yaml:
proxy.yaml
running
ocis proxy
will result in the proxy service running with the following configuration:end config
ocis.yaml
takes precedence and overridesproxy.yaml
values. This is an artificial limitation due to the cli framework we're using is not flexible enough for this use case, and hence we have to merge values. We do it this way to ensure that for extensions running supervised, their configuration file overrides values from a globalocis.yaml
.This command still behaves as expected when combined with environment variables or cli arguments. Let's consider the following commands:
In both cases the outcome is the same, in which values from
proxy.yaml
override globals. However when CLI flags are present, its values will override those from the config files (as they are more explicit). Let's see an example with the contents from the above scenario.> ocis proxy --http-addr=1111`
The resulting service will run with the following configuration:
It works similarly with its counterpart environment variable:
> PROXY_HTTP_ADDR=1111 ocis proxy`
The end result is the same.
Given these limitations, for an easier to reason about deployment, it is encouraged to use environment variables as opposed to structured configuration from files.
Apply to