You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by yo...@apache.org on 2025/08/28 07:06:24 UTC
(apisix) branch master updated: fix(discovery/kubernetes): adjust id length (#12536)
This is an automated email from the ASF dual-hosted git repository.
young 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 0d758a48c fix(discovery/kubernetes): adjust id length (#12536)
0d758a48c is described below
commit 0d758a48ca541c12391e4d78bb6679f848153552
Author: YYYoung <is...@outlook.com>
AuthorDate: Thu Aug 28 15:06:18 2025 +0800
fix(discovery/kubernetes): adjust id length (#12536)
---
apisix/discovery/kubernetes/schema.lua | 2 +-
t/discovery/kubernetes_schema.t | 94 ++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 1 deletion(-)
diff --git a/apisix/discovery/kubernetes/schema.lua b/apisix/discovery/kubernetes/schema.lua
index e18d06fb0..780aad255 100644
--- a/apisix/discovery/kubernetes/schema.lua
+++ b/apisix/discovery/kubernetes/schema.lua
@@ -176,7 +176,7 @@ return {
properties = {
id = {
type = "string",
- pattern = [[^[a-z0-9]{1,8}$]]
+ pattern = [[^[a-z0-9]{1,64}$]]
},
service = {
type = "object",
diff --git a/t/discovery/kubernetes_schema.t b/t/discovery/kubernetes_schema.t
new file mode 100644
index 000000000..3c7fdddf1
--- /dev/null
+++ b/t/discovery/kubernetes_schema.t
@@ -0,0 +1,94 @@
+#
+# 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';
+
+repeat_each(2);
+no_long_string();
+no_root_location();
+log_level("info");
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
+ if (!$block->error_log && !$block->no_error_log) {
+ $block->set_value("no_error_log", "[error]\n[alert]");
+ }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: id field validation
+--- config
+ location /t {
+ content_by_lua_block {
+ local k8s_schema = require("apisix.discovery.kubernetes.schema")
+ local core = require("apisix.core")
+
+ -- Valid id: lowercase alphanumeric
+ local config = {
+ {
+ id = "cluster1",
+ service = {
+ host = "k8s.example.com",
+ port = "6443"
+ },
+ client = {
+ token = "token123"
+ }
+ }
+ }
+ local ok, err = core.schema.check(k8s_schema, config)
+ assert(ok, err)
+ ngx.say("valid id: passed")
+
+ -- Valid id: 64 chars
+ config[1].id = string.rep("a", 64)
+ ok, err = core.schema.check(k8s_schema, config)
+ assert(ok, err)
+ ngx.say("valid id 64 chars: passed")
+
+ -- Invalid id: uppercase letters
+ config[1].id = "CLUSTER1"
+ ok, err = core.schema.check(k8s_schema, config)
+ assert(not ok)
+ ngx.say("invalid id uppercase: ", err)
+
+ -- Invalid id: special characters
+ config[1].id = "cluster-1"
+ ok, err = core.schema.check(k8s_schema, config)
+ assert(not ok)
+ ngx.say("invalid id special char: ", err)
+
+ -- Invalid id: too long (over 64 chars)
+ config[1].id = string.rep("a", 65)
+ ok, err = core.schema.check(k8s_schema, config)
+ assert(not ok)
+ ngx.say("invalid id too long: ", err)
+ }
+ }
+--- response_body_like
+valid id: passed
+valid id 64 chars: passed
+invalid id uppercase: .*
+invalid id special char: .*
+invalid id too long: .*