You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/09/12 13:03:22 UTC
[GitHub] [apisix] spacewander commented on a diff in pull request #7895: feat: support multiple kubernets clusters discovery
spacewander commented on code in PR #7895:
URL: https://github.com/apache/apisix/pull/7895#discussion_r968363995
##########
apisix/discovery/kubernetes/schema.lua:
##########
@@ -28,113 +28,228 @@ local port_patterns = {
local namespace_pattern = [[^[a-z0-9]([-a-z0-9_.]*[a-z0-9])?$]]
local namespace_regex_pattern = [[^[\x21-\x7e]*$]]
+local shared_pattern = [[^[1-9][0-9]?m$]]
+
return {
- type = "object",
- properties = {
- service = {
+ anyOf = {
+ {
type = "object",
properties = {
- schema = {
- type = "string",
- enum = { "http", "https" },
- default = "https",
+ service = {
+ type = "object",
+ properties = {
+ schema = {
+ type = "string",
+ enum = { "http", "https" },
+ default = "https",
+ },
+ host = {
+ type = "string",
+ default = "${KUBERNETES_SERVICE_HOST}",
+ oneOf = host_patterns,
+ },
+ port = {
+ type = "string",
+ default = "${KUBERNETES_SERVICE_PORT}",
+ oneOf = port_patterns,
+ },
+ },
+ default = {
+ schema = "https",
+ host = "${KUBERNETES_SERVICE_HOST}",
+ port = "${KUBERNETES_SERVICE_PORT}",
+ }
},
- host = {
- type = "string",
- default = "${KUBERNETES_SERVICE_HOST}",
- oneOf = host_patterns,
+ client = {
+ type = "object",
+ properties = {
+ token = {
+ type = "string",
+ oneOf = {
+ { pattern = [[\${[_A-Za-z]([_A-Za-z0-9]*[_A-Za-z])*}$]] },
+ { pattern = [[^[A-Za-z0-9+\/._=-]{0,4096}$]] },
+ },
+ },
+ token_file = {
+ type = "string",
+ pattern = [[^[^\:*?"<>|]*$]],
+ minLength = 1,
+ maxLength = 500,
+ }
+ },
+ default = {
+ token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"
+ },
+ ["if"] = {
+ ["not"] = {
+ anyOf = {
+ { required = { "token" } },
+ { required = { "token_file" } },
+ }
+ }
+ },
+ ["then"] = {
+ properties = {
+ token_file = {
+ default = "/var/run/secrets/kubernetes.io/serviceaccount/token"
+ }
+ }
+ }
},
- port = {
- type = "string",
- default = "${KUBERNETES_SERVICE_PORT}",
- oneOf = port_patterns,
+ default_weight = {
+ type = "integer",
+ default = 50,
+ minimum = 0,
},
- },
- default = {
- schema = "https",
- host = "${KUBERNETES_SERVICE_HOST}",
- port = "${KUBERNETES_SERVICE_PORT}",
- }
- },
- client = {
- type = "object",
- properties = {
- token = {
- type = "string",
+ namespace_selector = {
+ type = "object",
+ properties = {
+ equal = {
+ type = "string",
+ pattern = namespace_pattern,
+ },
+ not_equal = {
+ type = "string",
+ pattern = namespace_pattern,
+ },
+ match = {
+ type = "array",
+ items = {
+ type = "string",
+ pattern = namespace_regex_pattern
+ },
+ minItems = 1
+ },
+ not_match = {
+ type = "array",
+ items = {
+ type = "string",
+ pattern = namespace_regex_pattern
+ },
+ minItems = 1
+ },
+ },
oneOf = {
- { pattern = [[\${[_A-Za-z]([_A-Za-z0-9]*[_A-Za-z])*}$]] },
- { pattern = [[^[A-Za-z0-9+\/._=-]{0,4096}$]] },
+ { required = {} },
+ { required = { "equal" } },
+ { required = { "not_equal" } },
+ { required = { "match" } },
+ { required = { "not_match" } }
},
},
- token_file = {
+ label_selector = {
+ type = "string",
+ },
+ shared_size = {
type = "string",
- pattern = [[^[^\:*?"<>|]*$]],
- minLength = 1,
- maxLength = 500,
+ pattern = shared_pattern,
+ default = "1m",
}
},
- oneOf = {
- { required = { "token" } },
- { required = { "token_file" } },
- },
- default = {
- token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"
- }
},
- default_weight = {
- type = "integer",
- default = 50,
- minimum = 0,
- },
- namespace_selector = {
- type = "object",
- properties = {
- equal = {
- type = "string",
- pattern = namespace_pattern,
- },
- not_equal = {
- type = "string",
- pattern = namespace_pattern,
- },
- match = {
- type = "array",
- items = {
+ {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "object",
+ properties = {
+ id = {
type = "string",
- pattern = namespace_regex_pattern
+ pattern = [[^[a-z0-9]{1,6}$]]
},
- minItems = 1
- },
- not_match = {
- type = "array",
- items = {
+ service = {
Review Comment:
We can save some repeated fields with something like `service = xxx.service`?
##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -298,88 +301,227 @@ local function create_endpoint_lrucache(endpoint_key, endpoint_port)
return endpoint[endpoint_port]
end
+
local _M = {
version = "0.0.1"
}
-function _M.nodes(service_name)
- local pattern = "^(.*):(.*)$" -- namespace/name:port_name
- local match = ngx.re.match(service_name, pattern, "jo")
- if not match then
- core.log.info("get unexpected upstream service_name: ", service_name)
- return nil
- end
- local endpoint_key = match[1]
- local endpoint_port = match[2]
- local endpoint_version = endpoint_dict:get_stale(endpoint_key .. "#version")
- if not endpoint_version then
- core.log.info("get empty endpoint version from discovery DICT ", endpoint_key)
- return nil
- end
+local function start_fetch(handle)
+ local timer_runner
+ timer_runner = function(premature)
+ if premature then
+ return
+ end
- return endpoint_lrucache(service_name, endpoint_version,
- create_endpoint_lrucache, endpoint_key, endpoint_port)
+ local ok, status = pcall(handle.list_watch, handle, handle.apiserver)
+
+ local retry_interval = 0
+ if not ok then
+ core.log.error("list_watch failed, kind: ", handle.kind,
+ ", reason: ", "RuntimeException", ", message : ", status)
+ retry_interval = 40
+ elseif not status then
+ retry_interval = 40
+ end
+
+ ngx.timer.at(retry_interval, timer_runner)
+ end
+ ngx.timer.at(0, timer_runner)
end
-function _M.init_worker()
- endpoint_dict = ngx.shared.kubernetes
+local function single_mode_init(conf)
+ local endpoint_dict = ngx.shared.kubernetes
if not endpoint_dict then
- error("failed to get lua_shared_dict: kubernetes, please check your APISIX version")
+ error("failed to get lua_shared_dict: ngx.shared.kubernetes, " ..
+ "please check your APISIX version")
end
if process.type() ~= "privileged agent" then
+ ctx = endpoint_dict
return
end
- local discovery_conf = local_conf.discovery.kubernetes
-
- default_weight = discovery_conf.default_weight
-
- local apiserver, err = get_apiserver(discovery_conf)
+ local apiserver, err = get_apiserver(conf)
if err then
error(err)
return
end
- local endpoints_informer, err = informer_factory.new("", "v1",
- "Endpoints", "endpoints", "")
+ local default_weight = conf.default_weight
+
+ local endpoints_informer, err = informer_factory.new("", "v1", "Endpoints", "endpoints", "")
if err then
error(err)
return
end
- setup_namespace_selector(discovery_conf, endpoints_informer)
- setup_label_selector(discovery_conf, endpoints_informer)
+ setup_namespace_selector(conf, endpoints_informer)
+ setup_label_selector(conf, endpoints_informer)
endpoints_informer.on_added = on_endpoint_modified
endpoints_informer.on_modified = on_endpoint_modified
endpoints_informer.on_deleted = on_endpoint_deleted
endpoints_informer.pre_list = pre_list
endpoints_informer.post_list = post_list
- local timer_runner
- timer_runner = function(premature)
- if premature then
+ ctx = setmetatable({
+ endpoint_dict = endpoint_dict,
+ apiserver = apiserver,
+ default_weight = default_weight
+ }, { __index = endpoints_informer })
+
+ start_fetch(ctx)
+end
+
+
+local function single_mode_nodes(service_name)
+ local pattern = "^(.*):(.*)$" -- namespace/name:port_name
+ local match = ngx.re.match(service_name, pattern, "jo")
+ if not match then
+ core.log.info("get unexpected upstream service_name: ", service_name)
+ return nil
+ end
+
+ local endpoint_dict = ctx
+ local endpoint_key = match[1]
+ local endpoint_port = match[2]
+ local endpoint_version = endpoint_dict:get_stale(endpoint_key .. "#version")
+ if not endpoint_version then
+ core.log.info("get empty endpoint version from discovery DICT ", endpoint_key)
+ return nil
+ end
+
+ return endpoint_lrucache(service_name, endpoint_version,
+ create_endpoint_lrucache, endpoint_dict, endpoint_key, endpoint_port)
+end
+
+
+local function multi_mode_worker_init(confs)
+ for _, conf in ipairs(confs) do
+
+ local id = conf.id
+ if ctx[id] then
+ error("duplicate id value")
+ end
+
+ local endpoint_dict = ngx.shared["kubernetes-" .. id]
+ if not endpoint_dict then
+ error(core.table.concat {
+ "failed to get lua_shared_dict: ngx.shared.",
+ "kubernetes-" .. id,
+ ", please check your APISIX version"
+ })
+ end
+
+ ctx[id] = endpoint_dict
+ end
+end
+
+
+local function multi_mode_init(confs)
+ ctx = core.table.new(#confs, 0)
+
+ if process.type() ~= "privileged agent" then
+ multi_mode_worker_init(confs)
+ return
+ end
+
+ for _, conf in ipairs(confs) do
+ local id = conf.id
+
+ if ctx[id] then
+ error("duplicate id value")
+ end
+
+ local endpoint_dict = ngx.shared["kubernetes-" .. id]
+ if not endpoint_dict then
+ error(core.table.concat {
+ "failed to get lua_shared_dict: ngx.shared.",
+ "kubernetes-" .. id,
+ ", please check your APISIX version"
+ })
+ end
+
+ local apiserver, err = get_apiserver(conf)
+ if err then
+ error(err)
return
end
- local ok, status = pcall(endpoints_informer.list_watch, endpoints_informer, apiserver)
+ local default_weight = conf.default_weight
- local retry_interval = 0
- if not ok then
- core.log.error("list_watch failed, kind: ", endpoints_informer.kind,
- ", reason: ", "RuntimeException", ", message : ", status)
- retry_interval = 40
- elseif not status then
- retry_interval = 40
+ local endpoints_informer, err = informer_factory.new("", "v1", "Endpoints", "endpoints", "")
+ if err then
+ error(err)
+ return
end
- ngx.timer.at(retry_interval, timer_runner)
+ setup_namespace_selector(conf, endpoints_informer)
+ setup_label_selector(conf, endpoints_informer)
+
+ endpoints_informer.on_added = on_endpoint_modified
+ endpoints_informer.on_modified = on_endpoint_modified
+ endpoints_informer.on_deleted = on_endpoint_deleted
+ endpoints_informer.pre_list = pre_list
+ endpoints_informer.post_list = post_list
+
+ core.log.debug("get informer ", core.json.encode(endpoints_informer, true))
+
+ ctx[id] = setmetatable({
+ endpoint_dict = endpoint_dict,
+ apiserver = apiserver,
+ default_weight = default_weight
+ }, { __index = endpoints_informer })
end
- ngx.timer.at(0, timer_runner)
+ for id, item in pairs(ctx) do
+ core.log.debug("start fetch ", id, " ", core.json.encode(item, true), item.kind)
+ start_fetch(item)
+ end
+end
+
+
+local function multi_mode_nodes(service_name)
+ local pattern = "^(.*)/(.*/.*):(.*)$" -- id/namespace/name:port_name
+ local match = ngx.re.match(service_name, pattern, "jo")
+ if not match then
+ core.log.info("get unexpected upstream service_name: ", service_name)
+ return nil
+ end
+
+ core.log.info("ctx: ", core.json.encode(ctx, true), match[1])
+ local id = match[1]
+ local endpoint_dict = ctx[id]
+ if not endpoint_dict then
+ core.log.info("id not exis")
Review Comment:
```suggestion
core.log.info("id not exist")
```
##########
t/kubernetes/discovery/kubernetes2.t:
##########
@@ -0,0 +1,671 @@
+#
+# 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.
+#
+
+BEGIN {
+ our $token_file = "/tmp/var/run/secrets/kubernetes.io/serviceaccount/token";
+ our $token_value = eval {`cat $token_file 2>/dev/null`};
+
+ our $yaml_config = <<_EOC_;
+apisix:
+ node_listen: 1984
+ config_center: yaml
+ enable_admin: false
Review Comment:
We don't need to disable admin when config_center is yaml. Many existing yaml relative tests have this configuration, but we can remove it from the new test.
##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -298,88 +301,227 @@ local function create_endpoint_lrucache(endpoint_key, endpoint_port)
return endpoint[endpoint_port]
end
+
local _M = {
version = "0.0.1"
}
-function _M.nodes(service_name)
- local pattern = "^(.*):(.*)$" -- namespace/name:port_name
- local match = ngx.re.match(service_name, pattern, "jo")
- if not match then
- core.log.info("get unexpected upstream service_name: ", service_name)
- return nil
- end
- local endpoint_key = match[1]
- local endpoint_port = match[2]
- local endpoint_version = endpoint_dict:get_stale(endpoint_key .. "#version")
- if not endpoint_version then
- core.log.info("get empty endpoint version from discovery DICT ", endpoint_key)
- return nil
- end
+local function start_fetch(handle)
+ local timer_runner
+ timer_runner = function(premature)
+ if premature then
+ return
+ end
- return endpoint_lrucache(service_name, endpoint_version,
- create_endpoint_lrucache, endpoint_key, endpoint_port)
+ local ok, status = pcall(handle.list_watch, handle, handle.apiserver)
+
+ local retry_interval = 0
+ if not ok then
+ core.log.error("list_watch failed, kind: ", handle.kind,
+ ", reason: ", "RuntimeException", ", message : ", status)
+ retry_interval = 40
+ elseif not status then
+ retry_interval = 40
+ end
+
+ ngx.timer.at(retry_interval, timer_runner)
+ end
+ ngx.timer.at(0, timer_runner)
end
-function _M.init_worker()
- endpoint_dict = ngx.shared.kubernetes
+local function single_mode_init(conf)
+ local endpoint_dict = ngx.shared.kubernetes
if not endpoint_dict then
- error("failed to get lua_shared_dict: kubernetes, please check your APISIX version")
+ error("failed to get lua_shared_dict: ngx.shared.kubernetes, " ..
+ "please check your APISIX version")
end
if process.type() ~= "privileged agent" then
+ ctx = endpoint_dict
return
end
- local discovery_conf = local_conf.discovery.kubernetes
-
- default_weight = discovery_conf.default_weight
-
- local apiserver, err = get_apiserver(discovery_conf)
+ local apiserver, err = get_apiserver(conf)
if err then
error(err)
return
end
- local endpoints_informer, err = informer_factory.new("", "v1",
- "Endpoints", "endpoints", "")
+ local default_weight = conf.default_weight
+
+ local endpoints_informer, err = informer_factory.new("", "v1", "Endpoints", "endpoints", "")
if err then
error(err)
return
end
- setup_namespace_selector(discovery_conf, endpoints_informer)
- setup_label_selector(discovery_conf, endpoints_informer)
+ setup_namespace_selector(conf, endpoints_informer)
+ setup_label_selector(conf, endpoints_informer)
endpoints_informer.on_added = on_endpoint_modified
endpoints_informer.on_modified = on_endpoint_modified
endpoints_informer.on_deleted = on_endpoint_deleted
endpoints_informer.pre_list = pre_list
endpoints_informer.post_list = post_list
- local timer_runner
- timer_runner = function(premature)
- if premature then
+ ctx = setmetatable({
+ endpoint_dict = endpoint_dict,
+ apiserver = apiserver,
+ default_weight = default_weight
+ }, { __index = endpoints_informer })
+
+ start_fetch(ctx)
+end
+
+
+local function single_mode_nodes(service_name)
+ local pattern = "^(.*):(.*)$" -- namespace/name:port_name
+ local match = ngx.re.match(service_name, pattern, "jo")
+ if not match then
+ core.log.info("get unexpected upstream service_name: ", service_name)
+ return nil
+ end
+
+ local endpoint_dict = ctx
+ local endpoint_key = match[1]
+ local endpoint_port = match[2]
+ local endpoint_version = endpoint_dict:get_stale(endpoint_key .. "#version")
+ if not endpoint_version then
+ core.log.info("get empty endpoint version from discovery DICT ", endpoint_key)
+ return nil
+ end
+
+ return endpoint_lrucache(service_name, endpoint_version,
+ create_endpoint_lrucache, endpoint_dict, endpoint_key, endpoint_port)
+end
+
+
+local function multi_mode_worker_init(confs)
+ for _, conf in ipairs(confs) do
+
+ local id = conf.id
+ if ctx[id] then
+ error("duplicate id value")
+ end
+
+ local endpoint_dict = ngx.shared["kubernetes-" .. id]
+ if not endpoint_dict then
+ error(core.table.concat {
+ "failed to get lua_shared_dict: ngx.shared.",
+ "kubernetes-" .. id,
+ ", please check your APISIX version"
+ })
+ end
+
+ ctx[id] = endpoint_dict
+ end
+end
+
+
+local function multi_mode_init(confs)
+ ctx = core.table.new(#confs, 0)
+
+ if process.type() ~= "privileged agent" then
+ multi_mode_worker_init(confs)
+ return
+ end
+
+ for _, conf in ipairs(confs) do
+ local id = conf.id
+
+ if ctx[id] then
+ error("duplicate id value")
+ end
+
+ local endpoint_dict = ngx.shared["kubernetes-" .. id]
+ if not endpoint_dict then
+ error(core.table.concat {
Review Comment:
I would recommend using `string.format` which is more common
##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -298,88 +301,227 @@ local function create_endpoint_lrucache(endpoint_key, endpoint_port)
return endpoint[endpoint_port]
end
+
local _M = {
version = "0.0.1"
}
-function _M.nodes(service_name)
- local pattern = "^(.*):(.*)$" -- namespace/name:port_name
- local match = ngx.re.match(service_name, pattern, "jo")
- if not match then
- core.log.info("get unexpected upstream service_name: ", service_name)
- return nil
- end
- local endpoint_key = match[1]
- local endpoint_port = match[2]
- local endpoint_version = endpoint_dict:get_stale(endpoint_key .. "#version")
- if not endpoint_version then
- core.log.info("get empty endpoint version from discovery DICT ", endpoint_key)
- return nil
- end
+local function start_fetch(handle)
+ local timer_runner
+ timer_runner = function(premature)
+ if premature then
+ return
+ end
- return endpoint_lrucache(service_name, endpoint_version,
- create_endpoint_lrucache, endpoint_key, endpoint_port)
+ local ok, status = pcall(handle.list_watch, handle, handle.apiserver)
+
+ local retry_interval = 0
+ if not ok then
+ core.log.error("list_watch failed, kind: ", handle.kind,
+ ", reason: ", "RuntimeException", ", message : ", status)
+ retry_interval = 40
+ elseif not status then
+ retry_interval = 40
+ end
+
+ ngx.timer.at(retry_interval, timer_runner)
+ end
+ ngx.timer.at(0, timer_runner)
end
-function _M.init_worker()
- endpoint_dict = ngx.shared.kubernetes
+local function single_mode_init(conf)
+ local endpoint_dict = ngx.shared.kubernetes
if not endpoint_dict then
- error("failed to get lua_shared_dict: kubernetes, please check your APISIX version")
+ error("failed to get lua_shared_dict: ngx.shared.kubernetes, " ..
+ "please check your APISIX version")
end
if process.type() ~= "privileged agent" then
+ ctx = endpoint_dict
return
end
- local discovery_conf = local_conf.discovery.kubernetes
-
- default_weight = discovery_conf.default_weight
-
- local apiserver, err = get_apiserver(discovery_conf)
+ local apiserver, err = get_apiserver(conf)
if err then
error(err)
return
end
- local endpoints_informer, err = informer_factory.new("", "v1",
- "Endpoints", "endpoints", "")
+ local default_weight = conf.default_weight
+
+ local endpoints_informer, err = informer_factory.new("", "v1", "Endpoints", "endpoints", "")
if err then
error(err)
return
end
- setup_namespace_selector(discovery_conf, endpoints_informer)
- setup_label_selector(discovery_conf, endpoints_informer)
+ setup_namespace_selector(conf, endpoints_informer)
+ setup_label_selector(conf, endpoints_informer)
endpoints_informer.on_added = on_endpoint_modified
endpoints_informer.on_modified = on_endpoint_modified
endpoints_informer.on_deleted = on_endpoint_deleted
endpoints_informer.pre_list = pre_list
endpoints_informer.post_list = post_list
- local timer_runner
- timer_runner = function(premature)
- if premature then
+ ctx = setmetatable({
+ endpoint_dict = endpoint_dict,
+ apiserver = apiserver,
+ default_weight = default_weight
+ }, { __index = endpoints_informer })
+
+ start_fetch(ctx)
+end
+
+
+local function single_mode_nodes(service_name)
+ local pattern = "^(.*):(.*)$" -- namespace/name:port_name
+ local match = ngx.re.match(service_name, pattern, "jo")
+ if not match then
+ core.log.info("get unexpected upstream service_name: ", service_name)
+ return nil
+ end
+
+ local endpoint_dict = ctx
+ local endpoint_key = match[1]
+ local endpoint_port = match[2]
+ local endpoint_version = endpoint_dict:get_stale(endpoint_key .. "#version")
+ if not endpoint_version then
+ core.log.info("get empty endpoint version from discovery DICT ", endpoint_key)
+ return nil
+ end
+
+ return endpoint_lrucache(service_name, endpoint_version,
+ create_endpoint_lrucache, endpoint_dict, endpoint_key, endpoint_port)
+end
+
+
+local function multi_mode_worker_init(confs)
+ for _, conf in ipairs(confs) do
+
+ local id = conf.id
+ if ctx[id] then
+ error("duplicate id value")
+ end
+
+ local endpoint_dict = ngx.shared["kubernetes-" .. id]
+ if not endpoint_dict then
+ error(core.table.concat {
+ "failed to get lua_shared_dict: ngx.shared.",
+ "kubernetes-" .. id,
+ ", please check your APISIX version"
+ })
+ end
+
+ ctx[id] = endpoint_dict
+ end
+end
+
+
+local function multi_mode_init(confs)
+ ctx = core.table.new(#confs, 0)
+
+ if process.type() ~= "privileged agent" then
+ multi_mode_worker_init(confs)
+ return
+ end
+
+ for _, conf in ipairs(confs) do
+ local id = conf.id
+
+ if ctx[id] then
+ error("duplicate id value")
+ end
+
+ local endpoint_dict = ngx.shared["kubernetes-" .. id]
+ if not endpoint_dict then
+ error(core.table.concat {
+ "failed to get lua_shared_dict: ngx.shared.",
+ "kubernetes-" .. id,
+ ", please check your APISIX version"
+ })
+ end
+
+ local apiserver, err = get_apiserver(conf)
+ if err then
+ error(err)
return
end
- local ok, status = pcall(endpoints_informer.list_watch, endpoints_informer, apiserver)
+ local default_weight = conf.default_weight
- local retry_interval = 0
- if not ok then
- core.log.error("list_watch failed, kind: ", endpoints_informer.kind,
- ", reason: ", "RuntimeException", ", message : ", status)
- retry_interval = 40
- elseif not status then
- retry_interval = 40
+ local endpoints_informer, err = informer_factory.new("", "v1", "Endpoints", "endpoints", "")
+ if err then
+ error(err)
+ return
end
- ngx.timer.at(retry_interval, timer_runner)
+ setup_namespace_selector(conf, endpoints_informer)
+ setup_label_selector(conf, endpoints_informer)
+
+ endpoints_informer.on_added = on_endpoint_modified
+ endpoints_informer.on_modified = on_endpoint_modified
+ endpoints_informer.on_deleted = on_endpoint_deleted
+ endpoints_informer.pre_list = pre_list
+ endpoints_informer.post_list = post_list
+
+ core.log.debug("get informer ", core.json.encode(endpoints_informer, true))
+
+ ctx[id] = setmetatable({
+ endpoint_dict = endpoint_dict,
+ apiserver = apiserver,
+ default_weight = default_weight
+ }, { __index = endpoints_informer })
end
- ngx.timer.at(0, timer_runner)
+ for id, item in pairs(ctx) do
+ core.log.debug("start fetch ", id, " ", core.json.encode(item, true), item.kind)
+ start_fetch(item)
+ end
+end
+
+
+local function multi_mode_nodes(service_name)
+ local pattern = "^(.*)/(.*/.*):(.*)$" -- id/namespace/name:port_name
+ local match = ngx.re.match(service_name, pattern, "jo")
+ if not match then
+ core.log.info("get unexpected upstream service_name: ", service_name)
Review Comment:
We should use `error` level log?
##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -29,10 +29,9 @@ local core = require("apisix.core")
local util = require("apisix.cli.util")
local local_conf = require("apisix.core.config_local").local_conf()
local informer_factory = require("apisix.discovery.kubernetes.informer_factory")
+local setmetatable = setmetatable
Review Comment:
Better to move the `setmetatable` together with `pcall` and others.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org