Skip to content
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

fix: add missing labels after merging route and service #6177

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ local function merge_service_route(service_conf, route_conf)
new_conf.value.host = route_conf.value.host
end

if route_conf.value.labels then
new_conf.value.labels = route_conf.value.labels
end

-- core.log.info("merged conf : ", core.json.delay_encode(new_conf))
return new_conf
end
Expand Down
123 changes: 123 additions & 0 deletions t/node/merge-route.t
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,126 @@ GET /t
passed
--- no_error_log
[error]



=== TEST 18: labels exist if only route
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"plugins": {
"serverless-pre-function": {
"phase": "rewrite",
"functions" : ["return function(conf, ctx)
local core = require(\"apisix.core\");
ngx.say(core.json.encode(ctx.matched_route.value.labels));
end"]
}
},
"labels": {
"version": "v2"
},
"uri": "/hello"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 19: hit routes
--- request
GET /hello
--- response_body
{"version":"v2"}
--- no_error_log
[error]



=== TEST 20: labels exist if merge route and service
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/services/1',
ngx.HTTP_PUT,
[[{
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)

if code >= 300 then
ngx.status = code
end

ngx.sleep(0.6) -- wait for sync

code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"serverless-pre-function": {
"phase": "rewrite",
"functions" : ["return function(conf, ctx)
local core = require(\"apisix.core\");
ngx.say(core.json.encode(ctx.matched_route.value.labels));
end"]
}
},
"labels": {
"version": "v2"
},
"uri": "/hello",
"service_id": 1
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 21: hit routes
--- request
GET /hello
--- response_body
{"version":"v2"}
--- no_error_log
[error]