Skip to content

Commit 1940cf4

Browse files
committed
Merge branch 'master' into fix/consumer-credential-modifiedIndex
2 parents 417144e + 3cb191a commit 1940cf4

File tree

8 files changed

+322
-53
lines changed

8 files changed

+322
-53
lines changed

apisix/schema_def.lua

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,15 @@ local private_key_schema = {
383383
local upstream_schema = {
384384
type = "object",
385385
properties = {
386+
-- metadata
387+
id = id_schema,
388+
name = rule_name_def,
389+
desc = desc_def,
390+
labels = labels_def,
386391
create_time = timestamp_def,
387392
update_time = timestamp_def,
393+
394+
-- properties
388395
nodes = nodes_schema,
389396
retries = {
390397
type = "integer",
@@ -466,7 +473,6 @@ local upstream_schema = {
466473
" For L4 proxy, it can be one of tcp/tls/udp." ..
467474
" For specific protocols, it can be kafka."
468475
},
469-
labels = labels_def,
470476
discovery_type = {
471477
description = "discovery type",
472478
type = "string",
@@ -491,14 +497,11 @@ local upstream_schema = {
491497
default = "pass"
492498
},
493499
upstream_host = host_def,
494-
name = rule_name_def,
495-
desc = desc_def,
496500
service_name = {
497501
type = "string",
498502
maxLength = 256,
499503
minLength = 1
500504
},
501-
id = id_schema,
502505
},
503506
oneOf = {
504507
{required = {"nodes"}},
@@ -542,8 +545,15 @@ _M.method_schema = method_schema
542545
_M.route = {
543546
type = "object",
544547
properties = {
548+
-- metadata
549+
id = id_schema,
550+
name = rule_name_def,
551+
desc = desc_def,
552+
labels = labels_def,
545553
create_time = timestamp_def,
546554
update_time = timestamp_def,
555+
556+
-- properties
547557
uri = {type = "string", minLength = 1, maxLength = 4096},
548558
uris = {
549559
type = "array",
@@ -554,8 +564,6 @@ _M.route = {
554564
minItems = 1,
555565
uniqueItems = true,
556566
},
557-
name = rule_name_def,
558-
desc = desc_def,
559567
priority = {type = "integer", default = 0},
560568

561569
methods = {
@@ -596,8 +604,6 @@ _M.route = {
596604

597605
upstream = upstream_schema,
598606

599-
labels = labels_def,
600-
601607
service_id = id_schema,
602608
upstream_id = id_schema,
603609

@@ -606,8 +612,6 @@ _M.route = {
606612
type = "boolean",
607613
},
608614

609-
id = id_schema,
610-
611615
status = {
612616
description = "route status, 1 to enable, 0 to disable",
613617
type = "integer",
@@ -672,16 +676,19 @@ _M.route = {
672676
_M.service = {
673677
type = "object",
674678
properties = {
679+
-- metadata
675680
id = id_schema,
676-
plugins = plugins_schema,
677-
upstream = upstream_schema,
678-
upstream_id = id_schema,
679681
name = rule_name_def,
680682
desc = desc_def,
681683
labels = labels_def,
682-
script = {type = "string", minLength = 10, maxLength = 102400},
683684
create_time = timestamp_def,
684685
update_time = timestamp_def,
686+
687+
-- properties
688+
plugins = plugins_schema,
689+
upstream = upstream_schema,
690+
upstream_id = id_schema,
691+
script = {type = "string", minLength = 10, maxLength = 102400},
685692
enable_websocket = {
686693
description = "enable websocket for request",
687694
type = "boolean",
@@ -700,16 +707,19 @@ _M.service = {
700707
_M.consumer = {
701708
type = "object",
702709
properties = {
710+
-- metadata
703711
username = {
704712
type = "string", minLength = 1, maxLength = rule_name_def.maxLength,
705713
pattern = [[^[a-zA-Z0-9_]+$]]
706714
},
707-
group_id = id_schema,
708-
plugins = plugins_schema,
715+
desc = desc_def,
709716
labels = labels_def,
710717
create_time = timestamp_def,
711718
update_time = timestamp_def,
712-
desc = desc_def,
719+
720+
-- properties
721+
group_id = id_schema,
722+
plugins = plugins_schema,
713723
},
714724
required = {"username"},
715725
additionalProperties = false,
@@ -718,6 +728,7 @@ _M.consumer = {
718728
_M.credential = {
719729
type = "object",
720730
properties = {
731+
-- metadata
721732
id = {
722733
oneOf = {
723734
id_schema,
@@ -730,15 +741,19 @@ _M.credential = {
730741
}
731742
}
732743
},
744+
name = rule_name_def,
745+
desc = desc_def,
746+
labels = labels_def,
747+
create_time = timestamp_def,
748+
update_time = timestamp_def,
749+
750+
-- properties
733751
plugins = {
734752
type = "object",
735753
maxProperties = 1,
736754
},
737-
labels = labels_def,
738-
create_time = timestamp_def,
739-
update_time = timestamp_def,
740-
desc = desc_def,
741755
},
756+
additionalProperties = false,
742757
}
743758

744759
_M.upstream = upstream_schema
@@ -753,7 +768,14 @@ local secret_uri_schema = {
753768
_M.ssl = {
754769
type = "object",
755770
properties = {
771+
-- metadata
756772
id = id_schema,
773+
desc = desc_def,
774+
labels = labels_def,
775+
create_time = timestamp_def,
776+
update_time = timestamp_def,
777+
778+
-- properties
757779
type = {
758780
description = "ssl certificate type, " ..
759781
"server to server certificate, " ..
@@ -825,7 +847,6 @@ _M.ssl = {
825847
},
826848
required = {"ca"},
827849
},
828-
labels = labels_def,
829850
status = {
830851
description = "ssl status, 1 to enable, 0 to disable",
831852
type = "integer",
@@ -841,8 +862,6 @@ _M.ssl = {
841862
enum = {"TLSv1.1", "TLSv1.2", "TLSv1.3"}
842863
},
843864
},
844-
create_time = timestamp_def,
845-
update_time = timestamp_def
846865
},
847866
["if"] = {
848867
properties = {
@@ -863,13 +882,20 @@ _M.ssl = {
863882

864883

865884

885+
-- TODO: Design a plugin resource registration framework used by plugins and move the proto
886+
-- resource to grpc-transcode plugin, which should not be an APISIX core resource
866887
_M.proto = {
867888
type = "object",
868889
properties = {
890+
-- metadata
869891
id = id_schema,
892+
name = rule_name_def,
870893
desc = desc_def,
894+
labels = labels_def,
871895
create_time = timestamp_def,
872896
update_time = timestamp_def,
897+
898+
-- properties
873899
content = {
874900
type = "string", minLength = 1, maxLength = 1024*1024
875901
}
@@ -882,10 +908,13 @@ _M.proto = {
882908
_M.global_rule = {
883909
type = "object",
884910
properties = {
911+
-- metadata
885912
id = id_schema,
886-
plugins = plugins_schema,
887913
create_time = timestamp_def,
888-
update_time = timestamp_def
914+
update_time = timestamp_def,
915+
916+
-- properties
917+
plugins = plugins_schema,
889918
},
890919
required = {"id", "plugins"},
891920
additionalProperties = false,
@@ -934,12 +963,16 @@ local xrpc_protocol_schema = {
934963
_M.stream_route = {
935964
type = "object",
936965
properties = {
966+
-- metadata
937967
id = id_schema,
968+
name = rule_name_def,
938969
desc = desc_def,
970+
labels = labels_def,
939971
create_time = timestamp_def,
940972
update_time = timestamp_def,
973+
974+
-- properties
941975
remote_addr = remote_addr_def,
942-
labels = labels_def, -- The ingress project need this field
943976
server_addr = {
944977
description = "server IP",
945978
type = "string",
@@ -988,15 +1021,18 @@ _M.plugins = {
9881021
_M.plugin_config = {
9891022
type = "object",
9901023
properties = {
1024+
-- metadata
1025+
id = id_schema,
9911026
name = {
9921027
type = "string",
9931028
},
994-
id = id_schema,
9951029
desc = desc_def,
996-
plugins = plugins_schema,
9971030
labels = labels_def,
9981031
create_time = timestamp_def,
999-
update_time = timestamp_def
1032+
update_time = timestamp_def,
1033+
1034+
-- properties
1035+
plugins = plugins_schema,
10001036
},
10011037
required = {"id", "plugins"},
10021038
additionalProperties = false,
@@ -1006,12 +1042,16 @@ _M.plugin_config = {
10061042
_M.consumer_group = {
10071043
type = "object",
10081044
properties = {
1045+
-- metadata
10091046
id = id_schema,
1047+
name = rule_name_def,
10101048
desc = desc_def,
1011-
plugins = plugins_schema,
10121049
labels = labels_def,
10131050
create_time = timestamp_def,
1014-
update_time = timestamp_def
1051+
update_time = timestamp_def,
1052+
1053+
-- properties
1054+
plugins = plugins_schema,
10151055
},
10161056
required = {"id", "plugins"},
10171057
additionalProperties = false,

apisix/upstream.lua

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ local function create_checker(upstream)
108108
end
109109

110110
local healthcheck_parent = upstream.parent
111-
if healthcheck_parent.checker and healthcheck_parent.checker_upstream == upstream then
111+
if healthcheck_parent.checker and healthcheck_parent.checker_upstream == upstream
112+
and healthcheck_parent.checker_nodes_ver == upstream._nodes_ver then
112113
return healthcheck_parent.checker
113114
end
114115

@@ -175,6 +176,7 @@ local function create_checker(upstream)
175176

176177
healthcheck_parent.checker = checker
177178
healthcheck_parent.checker_upstream = upstream
179+
healthcheck_parent.checker_nodes_ver = upstream._nodes_ver
178180
healthcheck_parent.checker_idx = check_idx
179181

180182
upstream.is_creating_checker = nil
@@ -302,35 +304,30 @@ function _M.set_by_route(route, api_ctx)
302304

303305
local same = upstream_util.compare_upstream_node(up_conf, new_nodes)
304306
if not same then
307+
if not up_conf._nodes_ver then
308+
up_conf._nodes_ver = 0
309+
end
310+
up_conf._nodes_ver = up_conf._nodes_ver + 1
311+
305312
local pass, err = core.schema.check(core.schema.discovery_nodes, new_nodes)
306313
if not pass then
307314
return HTTP_CODE_UPSTREAM_UNAVAILABLE, "invalid nodes format: " .. err
308315
end
309316

310-
local new_up_conf = core.table.clone(up_conf)
311-
new_up_conf.nodes = new_nodes
312-
new_up_conf.original_nodes = up_conf.nodes
317+
up_conf.nodes = new_nodes
313318

314319
core.log.info("discover new upstream from ", up_conf.service_name, ", type ",
315320
up_conf.discovery_type, ": ",
316-
core.json.delay_encode(new_up_conf, true))
317-
318-
local parent = up_conf.parent
319-
if parent.value.upstream then
320-
-- the up_conf comes from route or service
321-
parent.value.upstream = new_up_conf
322-
else
323-
parent.value = new_up_conf
324-
end
325-
up_conf = new_up_conf
321+
core.json.delay_encode(up_conf, true))
326322
end
327323
end
328324

329325
local id = up_conf.parent.value.id
330326
local conf_version = up_conf.parent.modifiedIndex
331327
-- include the upstream object as part of the version, because the upstream will be changed
332328
-- by service discovery or dns resolver.
333-
set_directly(api_ctx, id, conf_version .. "#" .. tostring(up_conf), up_conf)
329+
set_directly(api_ctx, id, conf_version .. "#" .. tostring(up_conf) .. "#"
330+
.. tostring(up_conf._nodes_ver or ''), up_conf)
334331

335332
local nodes_count = up_conf.nodes and #up_conf.nodes or 0
336333
if nodes_count == 0 then

apisix/utils/upstream.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ local function compare_upstream_node(up_conf, new_t)
3535
end
3636

3737
local old_t = up_conf.original_nodes or up_conf.nodes
38+
if old_t == new_t then
39+
return true
40+
end
41+
3842
if type(old_t) ~= "table" then
3943
return false
4044
end

0 commit comments

Comments
 (0)