You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/03/06 02:30:40 UTC

[incubator-apisix] branch master updated: Revert "feature: auto import nameservers into APISIX from system resolver. (#1167)" (#1205)

This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new a610e89  Revert "feature: auto import nameservers into APISIX from system resolver. (#1167)" (#1205)
a610e89 is described below

commit a610e8917c7535e8aacfb24c17c0bf61b0186dd8
Author: Wen Ming <mo...@gmail.com>
AuthorDate: Fri Mar 6 10:30:32 2020 +0800

    Revert "feature: auto import nameservers into APISIX from system resolver. (#1167)" (#1205)
    
    This reverts commit e1ac426443293c6140ddb257e482537edd43c36a.
    This PR break CI and no test cases cover, so I have to revert it.
---
 .travis/apisix_cli_test.sh | 14 ----------
 bin/apisix                 | 70 ++++++++++------------------------------------
 lua/apisix.lua             | 34 ++++++++--------------
 3 files changed, 27 insertions(+), 91 deletions(-)

diff --git a/.travis/apisix_cli_test.sh b/.travis/apisix_cli_test.sh
index 5274137..7ef2089 100755
--- a/.travis/apisix_cli_test.sh
+++ b/.travis/apisix_cli_test.sh
@@ -52,17 +52,3 @@ if [ ! $? -eq 0 ]; then
 fi
 
 echo "passed: change default ssl port"
-
-# check nameserver imported
-i=`grep  -E '^nameserver[[:space:]]+(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4]0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])[[:space:]]?$' /etc/resolv.conf | awk '{print $2}'`
-for ip in $i
-do
-  echo $ip
-  grep $ip conf/nginx.conf > /dev/null
-  if [ ! $? -eq 0 ]; then
-    echo "failed: system DNS "$ip "unimported"
-    exit 1
-  fi
-done
-
-echo "passed: system nameserver imported"
diff --git a/bin/apisix b/bin/apisix
index 1a7e7a3..2c097a7 100755
--- a/bin/apisix
+++ b/bin/apisix
@@ -22,10 +22,7 @@ local function trim(s)
 end
 
 local function excute_cmd(cmd)
-    local t, err = io.popen(cmd)
-    if not t then
-        return nil, "failed to execute command: " .. cmd .. ", error info:" .. err
-    end
+    local t = io.popen(cmd)
     local data = t:read("*all")
     t:close()
     return data
@@ -116,9 +113,6 @@ stream {
                       .. [=[{*lua_cpath*};";
     lua_socket_log_errors off;
 
-    resolver {% for _, dns_addr in ipairs(dns_resolver or {}) do %} {*dns_addr*} {% end %} valid={*dns_resolver_valid*} ipv6=off;
-    resolver_timeout 5;
-
     upstream apisix_backend {
         server 127.0.0.1:80;
         balancer_by_lua_block {
@@ -129,12 +123,7 @@ stream {
     init_by_lua_block {
         require "resty.core"
         apisix = require("apisix")
-
-        local dns_resolver = { {% for _, dns_addr in ipairs(dns_resolver or {}) do %} "{*dns_addr*}", {% end %} }
-        local args = {
-            dns_resolver = dns_resolver,
-        }
-        apisix.stream_init(args)
+        apisix.stream_init()
     }
 
     init_worker_by_lua_block {
@@ -249,12 +238,7 @@ http {
     init_by_lua_block {
         require "resty.core"
         apisix = require("apisix")
-
-        local dns_resolver = { {% for _, dns_addr in ipairs(dns_resolver or {}) do %} "{*dns_addr*}", {% end %} }
-        local args = {
-            dns_resolver = dns_resolver,
-        }
-        apisix.http_init(args)
+        apisix.http_init()
     }
 
     init_worker_by_lua_block {
@@ -450,9 +434,9 @@ http {
 ]=]
 
 local function write_file(file_path, data)
-    local file, err = io.open(file_path, "w+")
+    local file = io.open(file_path, "w+")
     if not file then
-        return false, "failed to open file: " .. file_path .. ", error info:" .. err
+        return false, "failed to open file: " .. file_path
     end
 
     file:write(data)
@@ -461,9 +445,9 @@ local function write_file(file_path, data)
 end
 
 local function read_file(file_path)
-    local file, err = io.open(file_path, "rb")
+    local file = io.open(file_path, "rb")
     if not file then
-        return false, "failed to open file: " .. file_path .. ", error info:" .. err
+        return false, "failed to open file: " .. file_path
     end
 
     local data = file:read("*all")
@@ -471,6 +455,12 @@ local function read_file(file_path)
     return data
 end
 
+local function exec(command)
+    local t= io.popen(command)
+    local res = t:read("*all")
+    t:close()
+    return trim(res)
+end
 
 local function read_yaml_conf()
     local profile = require("apisix.core.profile")
@@ -540,24 +530,6 @@ local function check_or_version(cur_ver_s, need_ver_s)
     return true
 end
 
-local function system_dns_resolver(file_path)
-    local file, err = io.open(file_path, "rb")
-    if not file then
-        return false, "failed to open file: " .. file_path .. ", error info:" .. err
-    end
-
-    local dns_addrs = {}
-    for line in file:lines() do
-        local addr, n = line:gsub("^nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$", "%1")
-        if n == 1 then
-            table.insert(dns_addrs, addr)
-        end
-    end
-
-    file:close()
-    return dns_addrs
-end
-
 local _M = {version = 0.1}
 
 function _M.help()
@@ -596,7 +568,7 @@ local function init()
     local sys_conf = {
         lua_path = pkg_path_org,
         lua_cpath = pkg_cpath_org,
-        os_name = excute_cmd("uname"),
+        os_name = exec("uname"),
         apisix_lua_home = apisix_home,
         with_module_status = with_module_status,
         error_log = {level = "warn"},
@@ -636,18 +608,6 @@ local function init()
         sys_conf["worker_processes"] = "auto"
     end
 
-    local dns_addrs = system_dns_resolver("/etc/resolv.conf")
-    if dns_addrs then
-        local dns_resolver = sys_conf["dns_resolver"]
-        if dns_resolver then
-            for _, addr  in ipairs(dns_addrs) do
-                table.insert(dns_resolver, 1, addr)
-            end
-        else
-            sys_conf["dns_resolver"] = dns_addrs
-        end
-    end
-
     local conf_render = template.compile(ngx_tpl)
     local ngxconf = conf_render(sys_conf)
 
@@ -703,7 +663,7 @@ local function init_etcd(show_output)
                     .. "--connect-timeout " .. timeout
                     .. " --max-time " .. timeout * 2 .. " --retry 1 2>&1"
 
-        local res = excute_cmd(cmd)
+        local res = exec(cmd)
         if not res:find("index", 1, true)
            and not res:find("createdIndex", 1, true) then
             error(cmd .. "\n" .. res)
diff --git a/lua/apisix.lua b/lua/apisix.lua
index 896b0cf..7517c46 100644
--- a/lua/apisix.lua
+++ b/lua/apisix.lua
@@ -32,21 +32,14 @@ local pairs         = pairs
 local tostring      = tostring
 local load_balancer
 
-local dns_resolver
-local parsed_domain
-
 
-local function parse_args(args)
-    if args and args["dns_resolver"] then
-        dns_resolver = args["dns_resolver"]
-    end
-end
+local parsed_domain
 
 
 local _M = {version = 0.3}
 
 
-function _M.http_init(args)
+function _M.http_init()
     require("resty.core")
 
     if require("ffi").os == "Linux" then
@@ -64,7 +57,7 @@ function _M.http_init(args)
         seed = ngx.now() * 1000 + ngx.worker.pid()
     end
     math.randomseed(seed)
-    parse_args(args)
+
     core.id.init()
 end
 
@@ -178,12 +171,11 @@ end
 
 
 local function parse_domain_in_up(up, ver)
-    if not dns_resolver then
-        local local_conf = core.config.local_conf()
-        dns_resolver = local_conf and local_conf.apisix and
-                local_conf.apisix.dns_resolver
-    end
+    local local_conf = core.config.local_conf()
+    local dns_resolver = local_conf and local_conf.apisix and
+                         local_conf.apisix.dns_resolver
     local new_nodes = core.table.new(0, 8)
+
     for addr, weight in pairs(up.value.nodes) do
         local host, port = core.utils.parse_addr(addr)
         if not ipmatcher.parse_ipv4(host) and
@@ -217,12 +209,11 @@ end
 
 
 local function parse_domain_in_route(route, ver)
-    if not dns_resolver then
-        local local_conf = core.config.local_conf()
-        dns_resolver = local_conf and local_conf.apisix and
-                local_conf.apisix.dns_resolver
-    end
+    local local_conf = core.config.local_conf()
+    local dns_resolver = local_conf and local_conf.apisix and
+                         local_conf.apisix.dns_resolver
     local new_nodes = core.table.new(0, 8)
+
     for addr, weight in pairs(route.value.upstream.nodes) do
         local host, port = core.utils.parse_addr(addr)
         if not ipmatcher.parse_ipv4(host) and
@@ -541,9 +532,8 @@ end
 end -- do
 
 
-function _M.stream_init(args)
+function _M.stream_init()
     core.log.info("enter stream_init")
-    parse_args(args)
 end