Skip to content
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

[cli] decouple apicast environment and 3scale configuration channel #590

Merged
merged 6 commits into from
Feb 14, 2018

Conversation

mikz
Copy link
Contributor

@mikz mikz commented Feb 13, 2018

  • THREESCALE_DEPLOYMENT_ENV controls the 3scale proxy configuration
    channel (staging/production) and can be passed as -3 --channel from the CLI
  • APICAST_ENVIRONMENT controls the APIcast settings (caching, ...) and can be passed by -e --environment from the CLI
  • APICAST_LOADED_ENVIRONMENTS can control always loaded APIcast environments (internal use only)
  • update Test-APIcast to include [blackbox] forward ENV to APIcast Test-APIcast#3
  • production is still the default configuration channel, that loads the production environment configuration which configures the configuration loader to "boot". In short this makes APIcast to require THREESCALE_PORTAL_ENDPOINT or --configuration when started without any other params. That makes bin/apicast to not start because it is missing configuration.

Needed for 3scale/apicast-cloud-hosted#1

@mikz mikz force-pushed the env-configuration-ineritance branch from 3ded468 to 751ab3f Compare February 13, 2018 12:57
* THREESCALE_DEPLOYMENT_ENV controls the 3scale proxy configuration
channel (staging/production)
* APICAST_ENVIRONMENT controls the APIcast settings (caching, ...)
* APICAST_LOADED_ENVIRONMENTS can control always loaded APIcast environments
@mikz mikz force-pushed the env-configuration-ineritance branch from af1754e to ea10dc5 Compare February 14, 2018 07:54
mikz added a commit that referenced this pull request Feb 14, 2018
mikz added 3 commits February 14, 2018 09:05
* so the environment configuration is default value
* the cli options are just overrides

It should be possible to run apicast staging/production
and get all the caching configurations already set.
and allow per test setting of environment
and use new test configuration loader (that does nothing)
@mikz mikz force-pushed the env-configuration-ineritance branch from e196165 to 786a5c2 Compare February 14, 2018 08:05
mikz added 2 commits February 14, 2018 10:03
* gateway needs some endpoint that returns to for the "boot" loader
* some tests used to run in lazy mode, so keep it that way
@mikz mikz requested a review from davidor February 14, 2018 09:24
@@ -0,0 +1 @@
staging.lua
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why sandbox and why it's the same as staging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because some configurations can still have THREESCALE_DEPLOYMENT_ENV=sandbox. It was the original value in AMP 2.0 IIRC. We alias it now to staging which makes more sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

master_process = 'on',
lua_code_cache = 'on',
configuration_loader = 'lazy',
configuration_cache = 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not os.getenv('APICAST_CONFIGURATION_CACHE') or 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our staging should always reload configuration. And because of the order of options and context in the start.lua the CLI options take precedence. So setting APICAST_CONFIGURATION_CACHE env would override this anyway.

That makes the production.lua os.getenv a bit redundant, but I wanted it there as an example of what can be done. But if it is confusing I could change/remove it.

@@ -148,7 +148,7 @@ function _M:add(env)

local config = loadfile(path, 't', {
print = print, inspect = require('inspect'), context = self._context,
tonumber = tonumber, tostring = tostring,
tonumber = tonumber, tostring = tostring, os = { getenv = resty_env.value },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that overriding getenv here can be a bit confusing.
Although I get that you're doing this to be able to use it in the environment files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I think it is more useful to expose resty_env.value than plain resty_env.get or os.getenv.
And the only difference is that it does not return empty strings. Which is actually useful for default values.

env_to_nginx(
'APICAST_CONFIGURATION_LOADER',
env_to_apicast(
'APICAST_CONFIGURATION_LOADER' => 'boot'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this allowed before or it's supported since Test::APIcast 0.08 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't really working before Test::APIcast 0.08. env_to_nginx was not working in Test::APIcast::Blackbox at all.

@@ -15,7 +15,7 @@ init_by_lua_block {
-- This ENV variable is defined in the main nginx.conf.liquid and injected when including this partial.
-- The content of the ENV variable is a Lua table, so when rendered it actually can run ipairs on it.
for k,v in pairs({{ ENV }}) do
if type(k) == 'string' and k ~= 'APICAST_CONFIGURATION_LOADER' then
if type(k) == 'string' and not resty_env.value(k) then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this change. Can you explain it, please?

Copy link
Contributor Author

@mikz mikz Feb 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sets only missing/empty variables.

This leaves the flexibility of overriding the ENV when starting nginx and treating the {{ ENV }} only as default values.

Because Test::APIcast runs APICAST_CONFIGURATION_LOADER=test bin/apicast and expects it to work. But in cases where APICAST_CONFIGURATION_LOADER=boot is already set in the ENV this would not apply and APICAST_CONFIGURATION_LOADER would have value boot during initialization. Basically ignoring what ENV it was started in.

So this change is for two reasons:

  • I think it makes sense for ENV of the shell to take priority than what is in the config file
  • Test::APIcast needs to start APIcast with APICAST_CONFIGURATION_LOADER=test when testing configuration with --test but then later start it with boot when the config is started for real (with no APICAST_CONFIGURATION_LOADER - but that is already hardcoded in the config as the default).

@mikz mikz merged commit 775de4d into master Feb 14, 2018
@mikz mikz deleted the env-configuration-ineritance branch February 14, 2018 10:20
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.

2 participants