Skip to content

Commit

Permalink
feat:support set RecursionAvailable options (#66)
Browse files Browse the repository at this point in the history
* mod:update go.mod file

* fix:修复mesh模式服务名错误匹配问题

* fix:修复mesh模式服务名错误匹配问题

* fix:search name需要递归处理
  • Loading branch information
chuntaojun authored Feb 24, 2023
1 parent 441d806 commit 9bb8f49
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bootstrap/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (d *dnsHandler) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
for _, handler := range d.resolvers {
resp = handler.ServeDNS(ctx, question, qname)
if nil != resp {
log.Infof("[agent] response for %s is %v", question.Name, resp)
log.Infof("[agent] request %v, response for %s is %v", req, question.Name, resp)
d.sendDnsResponse(w, req, resp)
return
}
Expand Down
39 changes: 39 additions & 0 deletions deploy/k8s/configmap-polaris-sidecar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: polaris-sidecar-config
data:
polaris-sidecar.yaml: |-
bind: 0.0.0.0
port: 53
namespace: default
recurse:
enable: false
timeoutSec: 1
mtls:
enable: false
logger:
output_paths:
- stdout
error_output_paths:
- stderr
rotate_output_path: logs/polaris-sidecar.log
error_rotate_output_path: logs/polaris-sidecar-error.log
rotation_max_size: 100
rotation_max_backups: 10
rotation_max_age: 7
output_level: info
resolvers:
- name: dnsagent
dns_ttl: 10
enable: true
suffix: "."
# option:
# route_labels: "key:value,key:value"
- name: meshproxy
dns_ttl: 120
enable: false
option:
reload_interval_sec: 30
dns_answer_ip: 10.4.4.4
recursion_available: true
7 changes: 7 additions & 0 deletions deploy/k8s/deployment-dnsagent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ spec:
- mountPath: /data/polaris.yaml
name: polaris-client-config
subPath: polaris.yaml
- mountPath: /data/polaris-sidecar.yaml
name: polaris-sidecar-config
subPath: polaris-sidecar.yaml
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
restartPolicy: Always
Expand All @@ -82,3 +85,7 @@ spec:
defaultMode: 420
name: polaris-client-config
name: polaris-client-config
- configMap:
defaultMode: 420
name: polaris-sidecar-config
name: polaris-sidecar-config
3 changes: 2 additions & 1 deletion polaris-sidecar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ resolvers:
enable: false
option:
reload_interval_sec: 30
dns_answer_ip: 10.4.4.4
dns_answer_ip: 10.4.4.4
recursion_available: true
13 changes: 7 additions & 6 deletions resolver/meshproxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
)

type resolverConfig struct {
Namespace string `json:"namespace"`
RegistryHost string `json:"registry_host"`
RegistryPort int `json:"registry_port"`
ReloadIntervalSec int `json:"reload_interval_sec"`
DNSAnswerIp string `json:"dns_answer_ip"`
FilterByBusiness string `json:"filter_by_business"`
Namespace string `json:"namespace"`
RegistryHost string `json:"registry_host"`
RegistryPort int `json:"registry_port"`
ReloadIntervalSec int `json:"reload_interval_sec"`
DNSAnswerIp string `json:"dns_answer_ip"`
FilterByBusiness string `json:"filter_by_business"`
RecursionAvailable bool `json:"recursion_available"`
}

func parseOptions(options map[string]interface{}) (*resolverConfig, error) {
Expand Down
14 changes: 8 additions & 6 deletions resolver/meshproxy/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import (

type LocalDNSServer struct {
// dns look up table
lookupTable atomic.Value
dnsTtl uint32
lookupTable atomic.Value
dnsTtl uint32
recursionAvailable bool
}

func (h *LocalDNSServer) UpdateLookupTable(polarisServices map[string]struct{}, dnsResponseIp string) {
Expand Down Expand Up @@ -112,9 +113,10 @@ func (table *LookupTable) lookupHost(qtype uint16, questionHost string, hostname
return out, hostFound
}

func newLocalDNSServer(dnsTtl uint32) (*LocalDNSServer, error) {
func newLocalDNSServer(dnsTtl uint32, recursionAvailable bool) (*LocalDNSServer, error) {
h := &LocalDNSServer{
dnsTtl: dnsTtl,
dnsTtl: dnsTtl,
recursionAvailable: recursionAvailable,
}
return h, nil
}
Expand All @@ -135,11 +137,11 @@ func (h *LocalDNSServer) ServeDNS(ctx context.Context, question *dns.Question, q
if hostFound {
response = new(dns.Msg)
response.Authoritative = true
// https://github.com/coredns/coredns/issues/3835
response.RecursionAvailable = h.recursionAvailable
response.Answer = answers
response.Rcode = dns.RcodeSuccess
return response
} else {
log.Infof("[Mesh] host not found for name %s", hostname)
}
return nil
}
Expand Down
8 changes: 6 additions & 2 deletions resolver/meshproxy/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *resolverMesh) Initialize(c *resolver.ConfigEntry) error {
return err
}
r.suffix = c.Suffix
r.localDNSServer, err = newLocalDNSServer(uint32(c.DnsTtl))
r.localDNSServer, err = newLocalDNSServer(uint32(c.DnsTtl), r.config.RecursionAvailable)
if nil != err {
return err
}
Expand Down Expand Up @@ -100,7 +100,11 @@ func (r *resolverMesh) ServeDNS(ctx context.Context, question dns.Question, qnam
qname = qname[0 : len(qname)-1]
}
qname = qname + "." + r.config.Namespace + "."
return r.localDNSServer.ServeDNS(ctx, &question, qname)
ret = r.localDNSServer.ServeDNS(ctx, &question, qname)
if ret == nil {
log.Infof("[Mesh] host not found for name %s", qname)
}
return ret
}

func (r *resolverMesh) Start(ctx context.Context) {
Expand Down

0 comments on commit 9bb8f49

Please sign in to comment.