The Wayback Machine - https://web.archive.org/web/20201202081949/https://github.com/Kong/kong/issues/5021
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

Declarative Configuration in a lua file #5021

Open
dorongold opened this issue Sep 11, 2019 · 5 comments · May be fixed by #5128
Open

Declarative Configuration in a lua file #5021

dorongold opened this issue Sep 11, 2019 · 5 comments · May be fixed by #5128

Comments

@dorongold
Copy link

@dorongold dorongold commented Sep 11, 2019

Summary

Currently Kong supports writing configuration in a file, in YAML or JSON.
To provide a more flexible configuration, especially for those running Kong in different environments (dev, staging, production), an option to write configuration in lua can be very useful.

Additional Details

There are many use-cases that come to mind:

  • Using environment variables inside the declarative configuration, something like:
return {
services = {
  name = my-upstream
  url = os.getenv("UPSTREAM_URL_FOR_THIS_ENVRIONMENT")
   ...
  }
}
  • Injecting parts of the configuration from a file, a Kubernetes config-map, or any other source which has different content in different environments.
    This can be done using lua functions such as dofile, load, loadfile, loadstring.

  • etc.

@dorongold
Copy link
Author

@dorongold dorongold commented Sep 12, 2019

@hishamhm currently (after the issue you referenced is merged) this piece of code in kong/db/declarative/init.lua still blocks the use of Lua declarative configuration:

 -- do not accept Lua by default
  accept = accept or { yaml = true, json = true }

In addition, when you guys decide to fix that and support Lua declarative configuration, it would be nice to change this line setfenv(chunk, {}) and instead of setting an empty environment, at least pass in _G.os, so that os.getenv can be used inside the declarative configuration.

It would be nice the be updated here if and when this support is going to be added.

@mohatagarvit
Copy link

@mohatagarvit mohatagarvit commented Oct 13, 2019

Should I make a different PR for these changes or continue in the last PR?

 -- do not accept Lua by default
  accept = accept or { yaml = true, json = true, lua = true }

setfenv(chunk, {_G.os}) in the elseif of lua

mohatagarvit added a commit to mohatagarvit/kong that referenced this issue Oct 15, 2019
This enables the already present support for lua declarative configuration
as per these [comments](Kong#5021 (comment))
@andrepiske
Copy link

@andrepiske andrepiske commented Apr 1, 2020

@dorongold I'm currently trying to put together a tool that allows to configure Kong in a declarative way, pretty much like you described here.

It's not open sourced yet, but I plan to do it in the foreseeable future.

I have a question though: Is your idea only for Kong configurations in the DB-less mode?

@dorongold
Copy link
Author

@dorongold dorongold commented Apr 1, 2020

@andrepiske We only use DB-less mode, so that is the only use-case I was aiming at.
Not sure what you mean about putting together a tool.
Declarative configuration using a Lua file is almost there.
All it takes is that someone from the Kong team merges the tiny 2 line change in the attached PR (or for them to create a similar PR themselves and merge it).

@andrepiske
Copy link

@andrepiske andrepiske commented Apr 3, 2020

@dorongold Oh that might be it, you're using DB-less mode.
What I mean by the tool is that I'm creating a tool to declare configuration (services, routes, plugins etc) of Kong in a declarative way, similar to decK. But I think it wouldn't be appropriate for db-less mode :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.