-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: kubernetes discovery readiness check #12852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2b36fb0
就绪标识
ChuanFF 8b10706
Merge remote-tracking branch 'origin/master' into k8s-discovery-healt…
ChuanFF e7d4fa5
check_ready 支持k8s服务发现
ChuanFF 76f618c
auto test
ChuanFF 4d3cf0c
Merge remote-tracking branch 'origin/master' into k8s-discovery-healt…
ChuanFF 0de96f1
auto test
ChuanFF c9cb6c2
code lint
ChuanFF e0c4674
code lint
ChuanFF bfafc63
Merge remote-tracking branch 'origin/master' into k8s-discovery-healt…
ChuanFF 2e6ad09
code review modify
ChuanFF 550e240
ready flag should set after data clean
ChuanFF 40d10e3
Merge remote-tracking branch 'origin/master' into k8s-discovery-healt…
ChuanFF 6b54416
code lint
ChuanFF bbb6a55
fix test case
ChuanFF 5715977
test case
ChuanFF 4013749
code review fix
ChuanFF ed33511
Merge remote-tracking branch 'origin/master' into k8s-discovery-healt…
ChuanFF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ local debug = require("apisix.debug") | |
| local pubsub_kafka = require("apisix.pubsub.kafka") | ||
| local resource = require("apisix.resource") | ||
| local trusted_addresses_util = require("apisix.utils.trusted-addresses") | ||
| local discovery = require("apisix.discovery.init").discovery | ||
| local ngx = ngx | ||
| local get_method = ngx.req.get_method | ||
| local ngx_exit = ngx.exit | ||
|
|
@@ -121,7 +122,6 @@ function _M.http_init_worker() | |
|
|
||
| core.lrucache.init_worker() | ||
|
|
||
| local discovery = require("apisix.discovery.init").discovery | ||
| if discovery and discovery.init_worker then | ||
| discovery.init_worker() | ||
| end | ||
|
|
@@ -976,54 +976,78 @@ function _M.status() | |
| core.response.exit(200, core.json.encode({ status = "ok" })) | ||
| end | ||
|
|
||
| function _M.status_ready() | ||
| local local_conf = core.config.local_conf() | ||
| local role = core.table.try_read_attr(local_conf, "deployment", "role") | ||
| local provider = core.table.try_read_attr(local_conf, "deployment", "role_" .. | ||
| role, "config_provider") | ||
| if provider == "yaml" or provider == "etcd" then | ||
| local status_shdict = ngx.shared["status-report"] | ||
| local ids = status_shdict:get_keys() | ||
| local error | ||
| local worker_count = ngx.worker.count() | ||
| if #ids ~= worker_count then | ||
| core.log.warn("worker count: ", worker_count, " but status report count: ", #ids) | ||
| error = "worker count: " .. ngx.worker.count() .. | ||
| " but status report count: " .. #ids | ||
| end | ||
| if error then | ||
| core.response.exit(503, core.json.encode({ | ||
| status = "error", | ||
| error = error | ||
| })) | ||
| return | ||
| end | ||
| for _, id in ipairs(ids) do | ||
| local ready = status_shdict:get(id) | ||
|
|
||
| local function discovery_ready_check() | ||
| local discovery_type = local_conf.discovery | ||
| if not discovery_type then | ||
| return true | ||
| end | ||
| for discovery_name, _ in pairs(discovery_type) do | ||
| local dis_module = discovery[discovery_name] | ||
| if dis_module.check_discovery_ready then | ||
| local ready, message = dis_module.check_discovery_ready() | ||
| if not ready then | ||
| core.log.warn("worker id: ", id, " has not received configuration") | ||
| error = "worker id: " .. id .. | ||
| " has not received configuration" | ||
| break | ||
| return false, message | ||
| end | ||
| end | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| if error then | ||
| core.response.exit(503, core.json.encode({ | ||
| status = "error", | ||
| error = error | ||
| })) | ||
| return | ||
| local function config_ready_check() | ||
| local role = core.table.try_read_attr(local_conf, "deployment", "role") | ||
| local provider = core.table.try_read_attr(local_conf, "deployment", | ||
| "role_" .. role, "config_provider") | ||
| if provider ~= "yaml" and provider ~= "etcd" then | ||
| return false, "unknown config provider: " .. tostring(provider) | ||
| end | ||
|
|
||
| local status_shdict = ngx.shared["status-report"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we may get
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| if not status_shdict then | ||
| core.log.error("failed to get ngx.shared dict status-report") | ||
| return false, "failed to get ngx.shared dict status-report" | ||
| end | ||
| local ids = status_shdict:get_keys() | ||
|
|
||
| local worker_count = ngx.worker.count() | ||
| if #ids ~= worker_count then | ||
| local error = "worker count: " .. worker_count .. " but status report count: " .. #ids | ||
| core.log.error(error) | ||
| return false, error | ||
| end | ||
| for _, id in ipairs(ids) do | ||
| local ready = status_shdict:get(id) | ||
| if not ready then | ||
| local error = "worker id: " .. id .. " has not received configuration" | ||
| core.log.error(error) | ||
| return false, error | ||
| end | ||
| end | ||
|
|
||
| return true | ||
| end | ||
|
|
||
| core.response.exit(200, core.json.encode({ status = "ok" })) | ||
| function _M.status_ready() | ||
| local ready, message = config_ready_check() | ||
| if not ready then | ||
| core.response.exit(503, core.json.encode({ | ||
| status = "error", | ||
| error = message | ||
| })) | ||
| return | ||
| end | ||
|
|
||
| core.response.exit(503, core.json.encode({ | ||
| status = "error", | ||
| message = "unknown config provider: " .. tostring(provider) | ||
| }), { ["Content-Type"] = "application/json" }) | ||
| ready, message = discovery_ready_check() | ||
| if not ready then | ||
| core.response.exit(503, core.json.encode({ | ||
| status = "error", | ||
| error = message | ||
| })) | ||
| return | ||
| end | ||
|
|
||
| core.response.exit(200, core.json.encode({ status = "ok" })) | ||
| return | ||
| end | ||
|
|
||
|
|
||
|
|
@@ -1182,7 +1206,6 @@ function _M.stream_init_worker() | |
| -- for admin api of standalone mode, we need to startup background timer and patch schema etc. | ||
| require("apisix.admin.init").init_worker() | ||
|
|
||
| local discovery = require("apisix.discovery.init").discovery | ||
| if discovery and discovery.init_worker then | ||
| discovery.init_worker() | ||
| end | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.