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

change: move config_center under deployment and named as config_provider #7901

Merged
merged 10 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix/cli/etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function _M.init(env, args)
util.die("failed to read `apisix` field from yaml file when init etcd")
end

if yaml_conf.apisix.config_center ~= "etcd" then
if yaml_conf.deployment.config_provider ~= "etcd" then
return true
end

Expand Down
33 changes: 18 additions & 15 deletions apisix/cli/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,8 @@ function _M.read_yaml_conf(apisix_home)
end
end

if default_conf.apisix.config_center == "yaml" then
local apisix_conf_path = profile:yaml_path("apisix")
local apisix_conf_yaml, _ = util.read_file(apisix_conf_path)
if apisix_conf_yaml then
local apisix_conf = yaml.parse(apisix_conf_yaml)
if apisix_conf then
local ok, err = resolve_conf_var(apisix_conf)
if not ok then
return nil, err
end
end
end
end

if default_conf.deployment then
default_conf.deployment.config_provider = "etcd"
if default_conf.deployment.role == "traditional" then
default_conf.etcd = default_conf.deployment.etcd

Expand All @@ -257,7 +244,9 @@ function _M.read_yaml_conf(apisix_home)

elseif default_conf.deployment.role == "data_plane" then
if default_conf.deployment.role_data_plane.config_provider == "yaml" then
default_conf.apisix.config_center = "yaml"
default_conf.deployment.config_provider = "yaml"
elseif default_conf.deployment.role_data_plane.config_provider == "xds" then
default_conf.deployment.config_provider = "xds"
else
default_conf.etcd = default_conf.deployment.role_data_plane.control_plane
end
Expand All @@ -276,6 +265,20 @@ function _M.read_yaml_conf(apisix_home)
end
end

if default_conf.deployment.config_provider == "yaml" then
local apisix_conf_path = profile:yaml_path("apisix")
local apisix_conf_yaml, _ = util.read_file(apisix_conf_path)
if apisix_conf_yaml then
local apisix_conf = yaml.parse(apisix_conf_yaml)
if apisix_conf then
local ok, err = resolve_conf_var(apisix_conf)
if not ok then
return nil, err
end
end
end
end

return default_conf
end

Expand Down
4 changes: 2 additions & 2 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Please modify "admin_key" in conf/config.yaml .
end

if yaml_conf.apisix.enable_admin and
yaml_conf.apisix.config_center == "yaml"
yaml_conf.deployment.config_provider == "yaml"
then
util.die("ERROR: Admin API can only be used with etcd config_center.\n")
util.die("ERROR: Admin API can only be used with etcd config_provider.\n")
end

local or_ver = get_openresty_version()
Expand Down
5 changes: 1 addition & 4 deletions apisix/cli/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ local config_schema = {
properties = {
apisix = {
properties = {
config_center = {
enum = {"etcd", "yaml", "xds"},
},
lua_module_hook = {
pattern = "^[a-zA-Z._-]+$",
},
Expand Down Expand Up @@ -380,7 +377,7 @@ local deployment_schema = {
role_data_plane = {
properties = {
config_provider = {
enum = {"control_plane", "yaml"}
enum = {"control_plane", "yaml", "xds"}
},
},
required = {"config_provider"}
Expand Down
8 changes: 4 additions & 4 deletions apisix/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ if not local_conf then
error("failed to parse yaml config: " .. err)
end

local config_center = local_conf.apisix and local_conf.apisix.config_center
local config_provider = local_conf.deployment and local_conf.deployment.config_provider
or "etcd"
log.info("use config_center: ", config_center)
local config = require("apisix.core.config_" .. config_center)
config.type = config_center
log.info("use config_provider: ", config_provider)
local config = require("apisix.core.config_" .. config_provider)
config.type = config_provider


return {
Expand Down
2 changes: 0 additions & 2 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ apisix:
enable_reuseport: true # Enable nginx SO_REUSEPORT switch if set to true.
show_upstream_status_in_response_header: false # when true all upstream status write to `X-APISIX-Upstream-Status` otherwise only 5xx code
enable_ipv6: true
config_center: etcd # etcd: use etcd to store the config value
# yaml: fetch the config value from local yaml file `/your_path/conf/apisix.yaml`

#proxy_protocol: # Proxy Protocol configuration
#listen_http_port: 9181 # The port with proxy protocol for http, it differs from node_listen and admin_listen.
Expand Down
8 changes: 5 additions & 3 deletions docs/en/latest/stand-alone.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ The routing rules in the `conf/apisix.yaml` file are loaded into memory immediat

Since the current Admin API is based on the etcd configuration center solution, enable Admin API is not allowed when the Stand-alone mode is enabled.

To enable Stand-alone mode, we can set `apisix.config_center` to `yaml` and disable Admin API in file `conf/config.yaml`.
The Stand-alone mode can only be enabled when set the role of APISIX as data plane. We can set `deployment.role` to `data_plane` and `deployment.role_data_plane.config_provider` to `yaml`.

Refer to the example below:

```yaml
apisix:
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
```

### How to configure rules
Expand Down
8 changes: 5 additions & 3 deletions docs/zh/latest/stand-alone.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ APISIX 节点服务启动后会立刻加载 `conf/apisix.yaml` 文件中的路
由于目前 Admin API 都是基于 etcd 配置中心解决方案,当开启 Stand-alone 模式后,
Admin API 将不再被允许使用。

通过设置 `conf/config.yaml` 中的 `apisix.config_center` 选项为 `yaml` ,并禁用 Admin API 即可启用 Stand-alone 模式。
只有当 APISIX 的角色设置为 data plane 时,才能开启 Stand-alone 模式。通过设置 `deployment.role` 为 `data_plane`,设置 `deployment.role_data_plane.config_provider` 为 `yaml` 即可启用 Stand-alone 模式。

参考下面示例:

```yaml
apisix:
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
```

### 如何配置规则
Expand Down
5 changes: 4 additions & 1 deletion t/APISIX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,11 @@ add_block_preprocessor(sub {
$user_yaml_config = <<_EOC_;
apisix:
node_listen: 1984
config_center: yaml
enable_admin: false
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_
}

Expand Down
7 changes: 7 additions & 0 deletions t/bin/gen_snippet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ local yaml_conf, err = file.read_yaml_conf("t/servroot")
if not yaml_conf then
error(err)
end

if yaml_conf.deployment.role == "data_plane" and
yaml_conf.deployment.config_provider == "yaml"
or yaml_conf.deployment.config_provider == "xds" then
return
end

local ok, err = schema.validate(yaml_conf)
if not ok then
error(err)
Expand Down
14 changes: 9 additions & 5 deletions t/cli/test_admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,24 @@ fi

echo "pass: uninitialized variable not found during writing access log (admin_listen set)"

# Admin API can only be used with etcd config_center
# Admin API can only be used with etcd config_provider
## if role is data_plane, and config_provider is yaml, then enable_admin is set to false
echo '
apisix:
enable_admin: true
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
' > conf/config.yaml

out=$(make init 2>&1 || true)
if ! echo "$out" | grep "Admin API can only be used with etcd config_center"; then
echo "failed: Admin API can only be used with etcd config_center"
if echo "$out" | grep "Admin API can only be used with etcd config_provider"; then
echo "failed: Admin API can only be used with etcd config_provider"
exit 1
fi

echo "passed: Admin API can only be used with etcd config_center"
echo "passed: Admin API can only be used with etcd config_provider"

# disable Admin API and init plugins syncer
echo '
Expand Down
5 changes: 4 additions & 1 deletion t/cli/test_serverless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ rm logs/error.log || echo ''
echo '
apisix:
enable_admin: false
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
' > conf/config.yaml

make init
Expand Down
5 changes: 4 additions & 1 deletion t/cli/test_standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ trap standalone EXIT
echo '
apisix:
enable_admin: false
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
' > conf/config.yaml

echo '
Expand Down
5 changes: 4 additions & 1 deletion t/config-center-yaml/consumer.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ add_block_preprocessor(sub {
my $yaml_config = $block->yaml_config // <<_EOC_;
apisix:
node_listen: 1984
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_

$block->set_value("yaml_config", $yaml_config);
Expand Down
5 changes: 4 additions & 1 deletion t/config-center-yaml/global-rule.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ add_block_preprocessor(sub {
my $yaml_config = $block->yaml_config // <<_EOC_;
apisix:
node_listen: 1984
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_

$block->set_value("yaml_config", $yaml_config);
Expand Down
5 changes: 4 additions & 1 deletion t/config-center-yaml/plugin-configs.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ add_block_preprocessor(sub {
my $yaml_config = $block->yaml_config // <<_EOC_;
apisix:
node_listen: 1984
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_

$block->set_value("yaml_config", $yaml_config);
Expand Down
5 changes: 4 additions & 1 deletion t/config-center-yaml/plugin-metadata.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ add_block_preprocessor(sub {
my $yaml_config = $block->yaml_config // <<_EOC_;
apisix:
node_listen: 1984
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_

$block->set_value("yaml_config", $yaml_config);
Expand Down
17 changes: 13 additions & 4 deletions t/config-center-yaml/plugin.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ add_block_preprocessor(sub {
my $yaml_config = $block->yaml_config // <<_EOC_;
apisix:
node_listen: 1984
config_center: yaml
enable_admin: false
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_

$block->set_value("yaml_config", $yaml_config);
Expand Down Expand Up @@ -84,7 +87,7 @@ GET /t
--- response_body
hello world
--- error_log
use config_center: yaml
use config_provider: yaml
load(): loaded plugin and sort by priority: 3000 name: ip-restriction
load(): loaded plugin and sort by priority: 2510 name: jwt-auth
load_stream(): loaded stream plugin and sort by priority: 1000 name: mqtt-proxy
Expand All @@ -102,8 +105,11 @@ load(): new plugins
--- yaml_config
apisix:
node_listen: 1984
config_center: yaml
enable_admin: false
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
plugins:
- ip-restriction
- jwt-auth
Expand Down Expand Up @@ -169,8 +175,11 @@ GET /apisix/prometheus/metrics
--- yaml_config
apisix:
node_listen: 1984
config_center: yaml
enable_admin: false
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
plugins:
- ip-restriction
- jwt-auth
Expand Down
5 changes: 4 additions & 1 deletion t/config-center-yaml/route-service.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ no_shuffle();
our $yaml_config = <<_EOC_;
apisix:
node_listen: 1984
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_

run_tests();
Expand Down
5 changes: 4 additions & 1 deletion t/config-center-yaml/route-upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ no_shuffle();
our $yaml_config = <<_EOC_;
apisix:
node_listen: 1984
config_center: yaml
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
_EOC_

run_tests();
Expand Down
Loading