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

feat: add support for passing resolv.conf in dns discovery #9770

Merged
merged 14 commits into from
Sep 26, 2023
Merged
4 changes: 2 additions & 2 deletions apisix/discovery/dns/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ end
function _M.init_worker()
local local_conf = config_local.local_conf()
local servers = local_conf.discovery.dns.servers

local resolvconf = local_conf.discovery.dns.resolvconf
local default_order = {"last", "SRV", "A", "AAAA", "CNAME"}
local order = core.table.try_read_attr(local_conf, "discovery", "dns", "order")
order = order or default_order

local opts = {
hosts = {},
resolvConf = {},
resolvConf = resolvconf,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use resolv_conf to replace all variables

Copy link
Contributor Author

@Revolyssup Revolyssup Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay except for the resolveConf key inside opts because that field is in the lua-resty-dns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

nameservers = servers,
order = order,
}
Expand Down
12 changes: 11 additions & 1 deletion apisix/discovery/dns/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ return {
type = "string",
},
},
resolvconf = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add this to config-default.yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config-default already has servers

# servers:

and only one of servers or resolvconf is needed. Should I add it anyways?

Copy link
Contributor

@monkeyDluffy6017 monkeyDluffy6017 Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add the resolv_conf to the config-default.yaml, or nobody will find this attribute, add comments to clarify that servers or resolvconf is mutual exclusive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sounds good. Adding it..

type = "string",
},
order = {
type = "array",
minItems = 1,
Expand All @@ -34,5 +37,12 @@ return {
},
},
},
required = {"servers"}
oneOf = {
{
required = {"servers"},
},
{
required = {"resolvconf"},
}
}
}
8 changes: 0 additions & 8 deletions t/discovery/dns/mix.t
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,3 @@ upstreams:
}
--- request
GET /t
--- grep_error_log eval
qr/connect to 127.0.0.1:1053/
--- grep_error_log_out
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
connect to 127.0.0.1:1053
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you delete this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must have been done by mistake while testing something. Pushed the latest commit

17 changes: 17 additions & 0 deletions t/discovery/dns/resolv.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
nameserver 127.0.0.1:1053
Copy link
Contributor

@monkeyDluffy6017 monkeyDluffy6017 Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could create the file in build-cache dynamically like the function set_coredns

27 changes: 27 additions & 0 deletions t/discovery/dns/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,30 @@ upstreams:
--- must_die
--- error_log
matches none of the enum values



=== TEST 20: use resolv.conf
--- yaml_config
apisix:
node_listen: 1984
enable_admin: false
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
discovery: # service discovery center
dns:
resolvconf: t/discovery/dns/resolv.conf
--- apisix_yaml
upstreams:
- service_name: "sd.test.local:1980"
discovery_type: dns
type: roundrobin
id: 1
--- grep_error_log eval
qr/upstream nodes: \{[^}]+\}/
--- grep_error_log_out eval
qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
--- response_body
hello world