Skip to content

fix DNS issues with unresolvable backends with ExternalName #12952

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
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
18 changes: 12 additions & 6 deletions rootfs/etc/nginx/lua/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ local function resolve_external_names(original_backend)
local endpoints = {}
for _, endpoint in ipairs(backend.endpoints) do
local ips = dns_lookup(endpoint.address)
for _, ip in ipairs(ips) do
table.insert(endpoints, { address = ip, port = endpoint.port })
if #ips ~= 1 or ips[1] ~= endpoint.address then
for _, ip in ipairs(ips) do
table.insert(endpoints, { address = ip, port = endpoint.port })
end
end
end
backend.endpoints = endpoints
Expand All @@ -104,15 +106,19 @@ local function is_backend_with_external_name(backend)
end

local function sync_backend(backend)
-- We resolve external names before checking if the endpoints are empty
-- because the behavior for resolve_external_names when the name was not
-- resolved is to return an empty table so we set the balancer to nil below
-- see https://github.com/kubernetes/ingress-nginx/pull/10989
if is_backend_with_external_name(backend) then
backend = resolve_external_names(backend)
end

if not backend.endpoints or #backend.endpoints == 0 then
balancers[backend.name] = nil
return
end

if is_backend_with_external_name(backend) then
backend = resolve_external_names(backend)
end

backend.endpoints = format_ipv6_endpoints(backend.endpoints)

local implementation = get_implementation(backend)
Expand Down