Skip to content

Commit e3728e5

Browse files
k8s-infra-cherrypick-robotneerfripierreozoux
authored andcommitted
fix DNS issues with unresolvable backends with ExternalName (kubernetes#12951)
Co-authored-by: Neer Friedman <[email protected]> Co-authored-by: Pierre Ozoux <[email protected]>
1 parent 60332bb commit e3728e5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

rootfs/etc/nginx/lua/balancer.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ local function resolve_external_names(original_backend)
7777
local endpoints = {}
7878
for _, endpoint in ipairs(backend.endpoints) do
7979
local ips = dns_lookup(endpoint.address)
80-
for _, ip in ipairs(ips) do
81-
table.insert(endpoints, { address = ip, port = endpoint.port })
80+
if #ips ~= 1 or ips[1] ~= endpoint.address then
81+
for _, ip in ipairs(ips) do
82+
table.insert(endpoints, { address = ip, port = endpoint.port })
83+
end
8284
end
8385
end
8486
backend.endpoints = endpoints
@@ -104,15 +106,19 @@ local function is_backend_with_external_name(backend)
104106
end
105107

106108
local function sync_backend(backend)
109+
-- We resolve external names before checking if the endpoints are empty
110+
-- because the behavior for resolve_external_names when the name was not
111+
-- resolved is to return an empty table so we set the balancer to nil below
112+
-- see https://github.com/kubernetes/ingress-nginx/pull/10989
113+
if is_backend_with_external_name(backend) then
114+
backend = resolve_external_names(backend)
115+
end
116+
107117
if not backend.endpoints or #backend.endpoints == 0 then
108118
balancers[backend.name] = nil
109119
return
110120
end
111121

112-
if is_backend_with_external_name(backend) then
113-
backend = resolve_external_names(backend)
114-
end
115-
116122
backend.endpoints = format_ipv6_endpoints(backend.endpoints)
117123

118124
local implementation = get_implementation(backend)

0 commit comments

Comments
 (0)