From 8cea2c66d728b40db929a62635eb7fa3b1b66f1b Mon Sep 17 00:00:00 2001 From: Yuansheng Wang Date: Wed, 5 Jun 2019 14:21:25 +0800 Subject: [PATCH] bugfix: used a single option as the apisix configuration prefix name. --- README_CN.md | 6 ++++-- bin/apisix | 5 +++-- conf/config.yaml | 2 +- lua/apisix/core/config_etcd.lua | 11 +++++++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README_CN.md b/README_CN.md index d31dc4ad..54d84175 100644 --- a/README_CN.md +++ b/README_CN.md @@ -28,7 +28,7 @@ apisix: etcd: host: "http://127.0.0.1:2379" # etcd address - prefix: "/v2/keys/apisix" # etcd prefix + prefix: "apisix" # apisix configurations prefix timeout: 60 plugins: # plugin name list @@ -41,11 +41,13 @@ plugins: # plugin name list *注意* 不要手工修改 Apisix 自身的 `conf/nginx.conf` 文件,当服务每次启动时,`apisix` 会根据 `conf/config.yaml` 配置自动生成新的 `conf/nginx.conf` 并自动启动服务。 +目前读写 `etcd` 操作使用的是 v2 协议,所有配置均存储在 `/v2/keys` 目录下。 + [Back to TOC](#summary) ## Route -默认路径:`/v2/keys/apisix/routes/****` +默认路径:`/apisix/routes/****` `Route` 是如何匹配用户请求的具体描述。目前 Apisix 支持 `URI` 和 `Method` 两种方式匹配 用户请求。其他比如 `Host` 方式,将会持续增加。 diff --git a/bin/apisix b/bin/apisix index 0afd540e..9e2e66e4 100755 --- a/bin/apisix +++ b/bin/apisix @@ -234,9 +234,10 @@ local function init_etcd(show_output) end local etcd_conf = yaml_conf.etcd - local uri = etcd_conf.host .. etcd_conf.prefix + local uri = etcd_conf.host .. "/v2/keys" .. (etcd_conf.prefix or "") - for _, dir_name in ipairs({"/routes", "/upstreams", "/services"}) do + for _, dir_name in ipairs({"/routes", "/upstreams", "/services", + "/plugins", "/consumers"}) do local cmd = "curl " .. uri .. dir_name .. "?prev_exist=false -X PUT -d dir=true 2>&1" local res = exec(cmd) diff --git a/conf/config.yaml b/conf/config.yaml index 14bbe7e9..e7b8ee2a 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -3,7 +3,7 @@ apisix: etcd: host: "http://127.0.0.1:2379" # etcd address - prefix: "/v2/keys/apisix" # etcd prefix + prefix: "/apisix" # apisix configurations prefix timeout: 60 plugins: # plugin name list diff --git a/lua/apisix/core/config_etcd.lua b/lua/apisix/core/config_etcd.lua index f9ba2c8a..c5462927 100644 --- a/lua/apisix/core/config_etcd.lua +++ b/lua/apisix/core/config_etcd.lua @@ -232,6 +232,9 @@ function _M.new(key, opts) return nil, err end + local prefix = local_conf.etcd.prefix + local_conf.etcd.prefix = nil + local etcd_cli etcd_cli, err = etcd.new(local_conf.etcd) if not etcd_cli then @@ -242,14 +245,14 @@ function _M.new(key, opts) local obj = setmetatable({ etcd_cli = etcd_cli, - values = nil, - routes_hash = nil, - prev_index = nil, - key = key, + key = key and prefix .. key, automatic = automatic, sync_times = 0, running = true, conf_version = 0, + values = nil, + routes_hash = nil, + prev_index = nil, last_err = nil, last_err_time = nil, }, mt)