Skip to content

Commit

Permalink
feat: load etcd configuration when apisix starts
Browse files Browse the repository at this point in the history
Fix #3370
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Mar 10, 2021
1 parent 8609cd5 commit 9d55aa2
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 97 deletions.
14 changes: 10 additions & 4 deletions apisix/cli/etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

local base64_encode = require("base64").encode
local dkjson = require("dkjson")
local constants = require("apisix.constants")
local util = require("apisix.cli.util")
local file = require("apisix.cli.file")
local http = require("socket.http")
Expand All @@ -25,6 +26,7 @@ local ltn12 = require("ltn12")

local type = type
local ipairs = ipairs
local pairs = pairs
local print = print
local tonumber = tonumber
local str_format = string.format
Expand Down Expand Up @@ -248,11 +250,15 @@ function _M.init(env, args)
end


for _, dir_name in ipairs({"/routes", "/upstreams", "/services",
"/plugins", "/consumers", "/ssl",
"/global_rules", "/stream_routes", "/proto",
"/plugin_metadata", "/plugin_configs"}) do
local dirs = {}
for name in pairs(constants.HTTP_ETCD_DIRECTORY) do
dirs[name] = true
end
for name in pairs(constants.STREAM_ETCD_DIRECTORY) do
dirs[name] = true
end

for dir_name in pairs(dirs) do
local key = (etcd_conf.prefix or "") .. dir_name .. "/"

local put_url = host .. "/v3/kv/put"
Expand Down
38 changes: 38 additions & 0 deletions apisix/constants.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
return {
HTTP_ETCD_DIRECTORY = {
["/upstreams"] = true,
["/plugins"] = true,
["/ssl"] = true,
["/stream_routes"] = true,
["/plugin_metadata"] = true,
["/routes"] = true,
["/services"] = true,
["/consumers"] = true,
["/global_rules"] = true,
["/proto"] = true,
["/plugin_configs"] = true,
},
STREAM_ETCD_DIRECTORY = {
["/upstreams"] = true,
["/plugins"] = true,
["/ssl"] = true,
["/stream_routes"] = true,
["/plugin_metadata"] = true,
},
}
Loading

0 comments on commit 9d55aa2

Please sign in to comment.