Skip to content

Commit 8005eba

Browse files
authored
Merge branch 'apache:master' into master
2 parents 8864516 + 7d5aeaf commit 8005eba

27 files changed

+3888
-82
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Check Changelog
2+
3+
on:
4+
push:
5+
paths:
6+
- 'CHANGELOG.md'
7+
- 'ci/check_changelog_prs.ts'
8+
pull_request:
9+
paths:
10+
- 'CHANGELOG.md'
11+
- 'ci/check_changelog_prs.ts'
12+
13+
jobs:
14+
check-changelog:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
22+
- name: Run check_changelog_prs script
23+
working-directory: ci
24+
run: |
25+
curl -fsSL https://bun.sh/install | bash
26+
export PATH="$HOME/.bun/bin:$PATH"
27+
bun run check_changelog_prs.ts

.github/workflows/push-dev-image-on-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
5050
- name: Login to Docker Hub
5151
if: github.ref == 'refs/heads/master'
52-
uses: docker/login-action@v1
52+
uses: docker/login-action@v3
5353
with:
5454
username: ${{ secrets.DOCKERHUB_USER }}
5555
password: ${{ secrets.DOCKERHUB_TOKEN }}

apisix/cli/file.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ function _M.read_yaml_conf(apisix_home)
287287
default_conf.etcd = default_conf.deployment.etcd
288288
if default_conf.deployment.role_data_plane.config_provider == "yaml" then
289289
default_conf.deployment.config_provider = "yaml"
290+
elseif default_conf.deployment.role_data_plane.config_provider == "json" then
291+
default_conf.deployment.config_provider = "json"
290292
elseif default_conf.deployment.role_data_plane.config_provider == "xds" then
291293
default_conf.deployment.config_provider = "xds"
292294
end

apisix/cli/schema.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ local deployment_schema = {
405405
role_data_plane = {
406406
properties = {
407407
config_provider = {
408-
enum = {"etcd", "yaml", "xds"}
408+
enum = {"etcd", "yaml", "json", "xds"}
409409
},
410410
},
411411
required = {"config_provider"}

apisix/core.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ end
2424
local config_provider = local_conf.deployment and local_conf.deployment.config_provider
2525
or "etcd"
2626
log.info("use config_provider: ", config_provider)
27-
local config = require("apisix.core.config_" .. config_provider)
27+
28+
local config
29+
-- Currently, we handle JSON parsing in config_yaml, so special processing is needed here.
30+
if config_provider == "json" then
31+
config = require("apisix.core.config_yaml")
32+
config.file_type = "json"
33+
else
34+
config = require("apisix.core.config_" .. config_provider)
35+
end
36+
2837
config.type = config_provider
2938

3039

apisix/core/config_yaml.lua

Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ local ngx = ngx
4646
local re_find = ngx.re.find
4747
local process = require("ngx.process")
4848
local worker_id = ngx.worker.id
49-
local apisix_yaml_path = profile:yaml_path("apisix")
5049
local created_obj = {}
5150
local shared_dict
5251
local status_report_shared_dict_name = "status-report"
@@ -56,6 +55,9 @@ local _M = {
5655
local_conf = config_local.local_conf,
5756
clear_local_cache = config_local.clear_cache,
5857

58+
-- yaml or json
59+
file_type = "yaml",
60+
5961
ERR_NO_SHARED_DICT = "failed prepare standalone config shared dict, this will degrade "..
6062
"to event broadcasting, and if a worker crashes, the configuration "..
6163
"cannot be restored from other workers and shared dict"
@@ -69,10 +71,68 @@ local mt = {
6971
end
7072
}
7173

72-
7374
local apisix_yaml
7475
local apisix_yaml_mtime
7576

77+
local config_yaml = {
78+
path = profile:yaml_path("apisix"),
79+
type = "yaml",
80+
parse = function(self)
81+
local f, err = io.open(self.path, "r")
82+
if not f then
83+
return nil, "failed to open file " .. self.path .. " : " .. err
84+
end
85+
86+
f:seek('end', -10)
87+
local end_flag = f:read("*a")
88+
local found_end_flag = re_find(end_flag, [[#END\s*$]], "jo")
89+
90+
if not found_end_flag then
91+
f:close()
92+
return nil, "missing valid end flag in file " .. self.path
93+
end
94+
95+
f:seek('set')
96+
local raw_config = f:read("*a")
97+
f:close()
98+
99+
return yaml.load(raw_config), nil
100+
end
101+
}
102+
103+
local config_json = {
104+
-- `-5` to remove the "yaml" suffix
105+
path = config_yaml.path:sub(1, -5) .. "json",
106+
type = "json",
107+
parse = function(self)
108+
local f, err = io.open(self.path, "r")
109+
if not f then
110+
return nil, "failed to open file " .. self.path .. " : " .. err
111+
end
112+
local raw_config = f:read("*a")
113+
f:close()
114+
115+
local config, err = json.decode(raw_config)
116+
if err then
117+
return nil, "failed to decode json: " .. err
118+
end
119+
return config, nil
120+
end
121+
}
122+
123+
local config_file_table = {
124+
yaml = config_yaml,
125+
json = config_json
126+
}
127+
128+
129+
local config_file = setmetatable({}, {
130+
__index = function(_, key)
131+
return config_file_table[_M.file_type][key]
132+
end
133+
})
134+
135+
76136
local function sync_status_to_shdict(status)
77137
if process.type() ~= "worker" then
78138
return
@@ -112,13 +172,13 @@ local function is_use_admin_api()
112172
end
113173

114174

115-
local function read_apisix_yaml(premature, pre_mtime)
175+
local function read_apisix_config(premature, pre_mtime)
116176
if premature then
117177
return
118178
end
119-
local attributes, err = lfs.attributes(apisix_yaml_path)
179+
local attributes, err = lfs.attributes(config_file.path)
120180
if not attributes then
121-
log.error("failed to fetch ", apisix_yaml_path, " attributes: ", err)
181+
log.error("failed to fetch ", config_file.path, " attributes: ", err)
122182
return
123183
end
124184

@@ -127,36 +187,15 @@ local function read_apisix_yaml(premature, pre_mtime)
127187
return
128188
end
129189

130-
local f, err = io.open(apisix_yaml_path, "r")
131-
if not f then
132-
log.error("failed to open file ", apisix_yaml_path, " : ", err)
133-
return
134-
end
135-
136-
f:seek('end', -10)
137-
local end_flag = f:read("*a")
138-
-- log.info("flag: ", end_flag)
139-
local found_end_flag = re_find(end_flag, [[#END\s*$]], "jo")
140-
141-
if not found_end_flag then
142-
f:close()
143-
log.warn("missing valid end flag in file ", apisix_yaml_path)
144-
return
145-
end
146-
147-
f:seek('set')
148-
local yaml_config = f:read("*a")
149-
f:close()
150-
151-
local apisix_yaml_new = yaml.load(yaml_config)
152-
if not apisix_yaml_new then
153-
log.error("failed to parse the content of file " .. apisix_yaml_path)
190+
local config_new, err = config_file:parse()
191+
if err then
192+
log.error("failed to parse the content of file ", config_file.path, ": ", err)
154193
return
155194
end
156195

157-
update_config(apisix_yaml_new, last_modification_time)
196+
update_config(config_new, last_modification_time)
158197

159-
log.warn("config file ", apisix_yaml_path, " reloaded.")
198+
log.warn("config file ", config_file.path, " reloaded.")
160199
end
161200

162201

@@ -171,7 +210,7 @@ local function sync_data(self)
171210
else
172211
if not apisix_yaml_mtime then
173212
log.warn("wait for more time")
174-
return nil, "failed to read local file " .. apisix_yaml_path
213+
return nil, "failed to read local file " .. config_file.path
175214
end
176215
conf_version = apisix_yaml_mtime
177216
end
@@ -395,15 +434,15 @@ local function _automatic_fetch(premature, self)
395434
local ok, ok2, err = pcall(sync_data, self)
396435
if not ok then
397436
err = ok2
398-
log.error("failed to fetch data from local file " .. apisix_yaml_path .. ": ",
437+
log.error("failed to fetch data from local file " .. config_file.path .. ": ",
399438
err, ", ", tostring(self))
400439
ngx_sleep(3)
401440
break
402441

403442
elseif not ok2 and err then
404443
if err ~= "timeout" and err ~= "Key not found"
405444
and self.last_err ~= err then
406-
log.error("failed to fetch data from local file " .. apisix_yaml_path .. ": ",
445+
log.error("failed to fetch data from local file " .. config_file.path .. ": ",
407446
err, ", ", tostring(self))
408447
end
409448

@@ -477,7 +516,7 @@ function _M.new(key, opts)
477516
end
478517

479518
if err then
480-
log.error("failed to fetch data from local file ", apisix_yaml_path, ": ",
519+
log.error("failed to fetch data from local file ", config_file.path, ": ",
481520
err, ", ", key)
482521
end
483522

@@ -517,7 +556,7 @@ function _M.init()
517556
return true
518557
end
519558

520-
read_apisix_yaml()
559+
read_apisix_config()
521560
return true
522561
end
523562

@@ -531,7 +570,7 @@ function _M.init_worker()
531570
end
532571

533572
-- sync data in each non-master process
534-
ngx.timer.every(1, read_apisix_yaml)
573+
ngx.timer.every(1, read_apisix_config)
535574

536575
return true
537576
end

apisix/discovery/kubernetes/init.lua

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -633,44 +633,61 @@ function _M.init_worker()
633633
end
634634

635635

636-
function _M.dump_data()
636+
local function dump_endpoints_from_dict(endpoint_dict)
637+
local keys, err = endpoint_dict:get_keys()
638+
if err then
639+
core.log.error("get keys from discovery dict failed: ", err)
640+
return
641+
end
637642

638-
local eps = {}
639-
for _, conf in ipairs(local_conf.discovery.kubernetes) do
643+
if not keys or #keys == 0 then
644+
return
645+
end
640646

641-
local id = conf.id
642-
local endpoint_dict = get_endpoint_dict(id)
643-
local keys, err = endpoint_dict:get_keys()
644-
if err then
645-
error(err)
646-
break
647+
local endpoints = {}
648+
for i = 1, #keys do
649+
local key = keys[i]
650+
-- skip key with suffix #version
651+
if key:sub(-#"#version") ~= "#version" then
652+
local value = endpoint_dict:get(key)
653+
core.table.insert(endpoints, {
654+
name = key,
655+
value = value
656+
})
647657
end
658+
end
648659

649-
if keys then
650-
local k8s = {}
651-
for i = 1, #keys do
652-
653-
local key = keys[i]
654-
--skip key with suffix #version
655-
if key:sub(-#"#version") ~= "#version" then
656-
local value = endpoint_dict:get(key)
660+
return endpoints
661+
end
657662

658-
core.table.insert(k8s, {
659-
name = key,
660-
value = value
661-
})
662-
end
663-
end
663+
function _M.dump_data()
664+
local discovery_conf = local_conf.discovery.kubernetes
665+
local eps = {}
664666

667+
if #discovery_conf == 0 then
668+
-- Single mode: discovery_conf is a single configuration object
669+
local endpoint_dict = get_endpoint_dict()
670+
local endpoints = dump_endpoints_from_dict(endpoint_dict)
671+
if endpoints then
665672
core.table.insert(eps, {
666-
id = conf.id,
667-
endpoints = k8s
673+
endpoints = endpoints
668674
})
669-
675+
end
676+
else
677+
-- Multiple mode: discovery_conf is an array of configuration objects
678+
for _, conf in ipairs(discovery_conf) do
679+
local endpoint_dict = get_endpoint_dict(conf.id)
680+
local endpoints = dump_endpoints_from_dict(endpoint_dict)
681+
if endpoints then
682+
core.table.insert(eps, {
683+
id = conf.id,
684+
endpoints = endpoints
685+
})
686+
end
670687
end
671688
end
672689

673-
return {config = local_conf.discovery.kubernetes, endpoints = eps}
690+
return {config = discovery_conf, endpoints = eps}
674691
end
675692

676693

0 commit comments

Comments
 (0)