-
Notifications
You must be signed in to change notification settings - Fork 230
USHIFT-6796: C2CC: DNS forwarding between clusters #6638
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
b15a453
94b5de7
1a5258b
e4d674b
541281b
efdf50b
c7702e3
7fd9db8
850b285
1dca8ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| apiVersion: v1 | ||
| data: | ||
| Corefile: | | ||
| {{- .C2CCDNSBlocks }} | ||
| .:5353 { | ||
| bufsize 1232 | ||
| errors | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ type ResolvedRemoteCluster struct { | |
| ClusterNetwork []*net.IPNet | ||
| ServiceNetwork []*net.IPNet | ||
| Domain string | ||
| DNSIP string // 10th IP of ServiceNetwork[0], computed during validation when Domain is set | ||
| } | ||
|
|
||
| func (rc *ResolvedRemoteCluster) AllCIDRs() []*net.IPNet { | ||
|
|
@@ -264,6 +265,14 @@ func validateRemoteCluster( | |
| } else { | ||
| seenRemoteDomains[rc.Domain] = i | ||
| } | ||
| if len(rc.ServiceNetwork) > 0 { | ||
| dnsIP, err := getClusterDNS(rc.ServiceNetwork[0]) | ||
| if err != nil { | ||
| errs = append(errs, fmt.Errorf("%s: failed to compute DNS IP from serviceNetwork[0] %q: %w", label, rc.ServiceNetwork[0], err)) | ||
| } else { | ||
| res.DNSIP = dnsIP | ||
| } | ||
| } | ||
| } | ||
|
|
||
| errs = append(errs, validateIPFamilyConsistencyNets(res.ClusterNetwork, label+".clusterNetwork")...) | ||
|
|
@@ -345,3 +354,33 @@ func checkCIDRConflicts(cidr *net.IPNet, cidrStr, label string, seenCIDRs []labe | |
| func cidrsOverlap(a, b *net.IPNet) bool { | ||
| return a.Contains(b.IP) || b.Contains(a.IP) | ||
| } | ||
|
|
||
| // RenderC2CCDNSBlocks generates CoreDNS server blocks for cross-cluster DNS. | ||
| func RenderC2CCDNSBlocks(resolved []ResolvedRemoteCluster) string { | ||
| var blocks []string | ||
| for _, rc := range resolved { | ||
| if rc.Domain == "" { | ||
| continue | ||
| } | ||
| blocks = append(blocks, formatDNSBlock(rc.Domain, rc.DNSIP)) | ||
| } | ||
| if len(blocks) == 0 { | ||
| return "" | ||
| } | ||
| return "\n" + strings.Join(blocks, "\n") | ||
| } | ||
|
|
||
| func formatDNSBlock(domain, dnsIP string) string { | ||
| return fmt.Sprintf(` %s:5353 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make this a constant at the top of the file?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's only used in single place so I'd rather not move it to a place almost 400 lines away. |
||
| bufsize 1232 | ||
| errors | ||
| log . { | ||
| class error | ||
| } | ||
| rewrite stop name suffix .%s .cluster.local answer auto | ||
| forward . %s | ||
| cache 10 { | ||
| denial 9984 10 | ||
| } | ||
| }`, domain, domain, dnsIP) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to mask out the next server block by setting up a special domain?
Say you configure
cluster.localas domain. That would renderWhich is more specific than the catch all, and would route all the
cluster.localrequests to remote cluster.This is a bit of a stretch because no real use case configures a remote cluster with the same domain than the local one, but should we validate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, good catch