This is an automated email from the ASF dual-hosted git repository.
guoqqqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 3b33a0347a Handle missing resource config in node version helpers
(#13986)
3b33a0347a is described below
commit 3b33a0347a164c37a4b3c8e50891923ab90acf80
Author: Nikolai <[email protected]>
AuthorDate: Thu Oct 29 07:33:49 2026 +0500
Handle missing resource config in node version helpers (#13986)
---
apisix/resource.lua | 8 +++++++
t/core/resource.t | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+)
diff --git a/apisix/resource.lua b/apisix/resource.lua
index f99672221c..d40dd3645e 100644
--- a/apisix/resource.lua
+++ b/apisix/resource.lua
@@ -94,6 +94,10 @@ end
function _M.get_nodes_ver(resource_path)
local res_conf = fetch_latest_conf(resource_path)
+ if not res_conf then
+ return nil
+ end
+
local upstream = res_conf.value.upstream or res_conf.value
return upstream._nodes_ver
end
@@ -101,6 +105,10 @@ end
function _M.set_nodes_ver_and_nodes(resource_path, nodes_ver, nodes)
local res_conf = fetch_latest_conf(resource_path)
+ if not res_conf then
+ return
+ end
+
local upstream = res_conf.value.upstream or res_conf.value
upstream._nodes_ver = nodes_ver
upstream.nodes = nodes
diff --git a/t/core/resource.t b/t/core/resource.t
new file mode 100644
index 0000000000..904ce62637
--- /dev/null
+++ b/t/core/resource.t
@@ -0,0 +1,61 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: get_nodes_ver returns nil when the resource does not exist
+--- config
+ location /t {
+ content_by_lua_block {
+ local resource = require("apisix.resource")
+
ngx.say(resource.get_nodes_ver("/apisix/upstreams/missing-resource"))
+ }
+ }
+--- request
+GET /t
+--- response_body
+nil
+--- error_log
+resource not found: missing-resource in /upstreams
+--- no_error_log
+[error]
+[alert]
+
+
+
+=== TEST 2: set_nodes_ver_and_nodes does not fail when the resource does not
exist
+--- config
+ location /t {
+ content_by_lua_block {
+ local resource = require("apisix.resource")
+
resource.set_nodes_ver_and_nodes("/apisix/upstreams/missing-resource", 1,
+ {["127.0.0.1:1980"] = 1})
+ ngx.say("passed")
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- error_log
+resource not found: missing-resource in /upstreams
+--- no_error_log
+[error]
+[alert]