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

Resolver: using Fully qualified names. #1235

Merged
merged 1 commit into from
Oct 29, 2020
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ to function correctly. [PR #1231](https://github.com/3scale/APIcast/pull/1231)
- Fixed issue with Camel service over HTTPs when Routing Policy [PR #1230](https://github.com/3scale/APIcast/pull/1230) [THREESCALE-5891](https://issues.redhat.com/browse/THREESCALE-5891)
- Fixed doc issue on SERVICES_FILTER parameter [PR #1233](https://github.com/3scale/APIcast/pull/1233) [THREESCALE-5421](https://issues.redhat.com/browse/THREESCALE-5421)
- Non-alphanumeric metric name in 3scale-batcher policy [PR #1234](https://github.com/3scale/APIcast/pull/1234) [THREESCALE-4913](https://issues.redhat.com/browse/THREESCALE-4913)

- Fixed issues when using fully qualified DNS query [PR #1235](https://github.com/3scale/APIcast/pull/1235) [THREESCALE-4752](https://issues.redhat.com/browse/THREESCALE-4752)


## [3.9.0] 2020-08-17
Expand Down
35 changes: 26 additions & 9 deletions gateway/src/resty/resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local next = next
local open = io.open
local gmatch = string.gmatch
local match = string.match
local sub = string.sub
local format = string.format
local find = string.find
local insert = table.insert
Expand Down Expand Up @@ -280,28 +281,44 @@ local function valid_answers(answers)
end

local function search_dns(self, qname, stale)

local search = self.search
local dns = self.dns
local options = self.options
local cache = self.cache

local answers, err

for i=1, #search do
local query = qname .. '.' .. search[i]
ngx.log(ngx.DEBUG, 'resolver query: ', qname, ' search: ', search[i], ' query: ', query)

local function get_answer(query)
local answers, err
answers, err = cache:get(query, stale)
if valid_answers(answers) then break end
if valid_answers(answers) then
return answers, err
end

answers, err = dns:query(query, options)
if valid_answers(answers) then
cache:save(answers)
break
return answers, err
end
return nil, err
end

return answers, err
if sub(qname, -1) == "." then
local query = sub(qname, 1 ,-2)
ngx.log(ngx.DEBUG, 'resolver query: ', qname, ' query: ', query)
return get_answer(query)
end

local answer, err
for i=1, #search do
local query = qname .. '.' .. search[i]
ngx.log(ngx.DEBUG, 'resolver query: ', qname, ' search: ', search[i], ' query: ', query)
answer, err = get_answer(query)
if answer then
return answer, err
end
end

return nil, err
end

local function resolve_upstream(qname)
Expand Down
26 changes: 25 additions & 1 deletion spec/resty/resolver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,31 @@ describe('resty.resolver', function()
end)

describe(':lookup', function()
pending('does query when cached cname missing address')
local resolver

before_each(function()
local dns = {
query = spy.new(function(_, name)
return {
{ name = name , address = '127.0.0.1' }
}
end)
}
resolver = resty_resolver.new(dns, { cache = resolver_cache.new(), search = {"foo.com"}})
end)

it("works when fully qualified name in private base_url", function()
local answer, err = resolver:lookup('test.service.ns.cluster.local.')
assert.same("test.service.ns.cluster.local", answer[1].name)
assert.same(err, nil)
end)

it("search domain is appended correctly", function()
local answer, err = resolver:lookup('test.service.ns.cluster.local')
assert.same("test.service.ns.cluster.local.foo.com", answer[1].name)
assert.same(err, nil)
end)

end)

describe('.parse_resolver', function()
Expand Down