Skip to content

Commit 44b2525

Browse files
authored
Merge pull request kmesh-net#1436 from Flying-Tom/proposal-dual-engine-dns
Proposal: Dns support for Dual-Engine
2 parents 1296155 + bb6fe77 commit 44b2525

File tree

4 files changed

+245
-0
lines changed

4 files changed

+245
-0
lines changed

.markdownlint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ ol-prefix: false
66
no-duplicate-heading: false
77
single-h1: false
88
no-emphasis-as-heading: false
9+
no-hard-tabs:
10+
code_blocks: true
11+
spaces_per_tab: 2

docs/proposal/dual_engine_dns.md

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
---
2+
title: Support DNS Resolution in Dual Engine Mode
3+
authors:
4+
- "@Flying-Tom"
5+
reviewers:
6+
-
7+
approvers:
8+
-
9+
creation-date: 2025-07-09
10+
---
11+
12+
## Support DNS Resolution in Dual Engine Mode
13+
14+
<!--
15+
This is the title of your KEP. Keep it short, simple, and descriptive. A good
16+
title can help communicate what the KEP is and should be considered as part of
17+
any review.
18+
-->
19+
20+
### Summary
21+
22+
<!--
23+
This section is incredibly important for producing high-quality, user-focused
24+
documentation such as release notes or a development roadmap.
25+
A good summary is probably at least a paragraph in length.
26+
-->
27+
28+
This proposal adds DNS resolution support for Dual-Engine mode workloads, enabling seamless Istio migration by supporting ServiceEntry resources with DNS-based endpoints. Workloads dynamically resolve hostnames to IP addresses without static configuration.
29+
30+
### Motivation
31+
32+
<!--
33+
This section is for explicitly listing the motivation, goals, and non-goals of
34+
this KEP. Describe why the change is important and the benefits to users.
35+
-->
36+
37+
In Istio, [ExternalName services](https://kubernetes.io/docs/concepts/services-networking/service/#externalname) and DNS-typed [ServiceEntry](https://istio.io/latest/docs/reference/config/networking/service-entry/#ServiceEntry-Resolution) rely on client-side DNS resolution. When istiod processes these configurations, it generates workloads without pre-resolved IP addresses.
38+
39+
Example ServiceEntry:
40+
41+
```yaml
42+
apiVersion: networking.istio.io/v1
43+
kind: ServiceEntry
44+
metadata:
45+
name: external-svc-google
46+
namespace: default
47+
spec:
48+
hosts:
49+
- news.google.com
50+
ports:
51+
- number: 80
52+
name: http
53+
protocol: HTTP
54+
resolution: DNS
55+
```
56+
57+
In Release 1.1, Kmesh refactored the DNS module, extracting DNS logic from the kernel-native Ads controller into a standalone `AdsDnsController`. This decoupling enables reuse in Dual-Engine mode.
58+
59+
![](./pics/dns-evolution.png)
60+
61+
#### Goals
62+
63+
<!--
64+
List the specific goals of the KEP. What is it trying to achieve? How will we
65+
know that this has succeeded?
66+
-->
67+
68+
- Support DNS resolution for workloads generated from ServiceEntry resources in Dual-Engine mode
69+
- Implement asynchronous DNS resolution to avoid blocking workload processing
70+
- Provide automatic cleanup when workloads with DNS hostnames are removed
71+
- Support both IPv4 and IPv6 address resolution
72+
73+
#### Non-Goals
74+
75+
<!--
76+
What is out of scope for this KEP? Listing non-goals helps to focus discussion
77+
and make progress.
78+
-->
79+
80+
This KEP does not aim to implement or provide a DNS proxy or DNS server functionality. Specifically, we do not support resolving DNS names on behalf of client workloads. As a result, if a `ServiceEntry` uses a non-resolvable or fake DNS domain, client workloads may fail to resolve and access the intended service. Handling such DNS resolution scenarios is explicitly out of scope for this proposal.
81+
82+
### Proposal
83+
84+
<!--
85+
This is where we get down to the specifics of what the proposal actually is.
86+
This should have enough detail that reviewers can understand exactly what
87+
you're proposing, but should not include things like API designs or
88+
implementation. What is the desired outcome and how do we measure success?.
89+
The "Design Details" section below is for the real
90+
nitty-gritty.
91+
-->
92+
93+
Thanks to the `DNSResolver` in `pkg/dns` which extracted independent DNS resolution logic, we can reuse the DNS capabilities in Dual-engine mode. Inspired by the `AdsDnsController` in kernel-native mode, we implement a similar `WorkloadDnsController` to handle DNS resolution for workloads generated by `ServiceEntry` without address information.
94+
95+
The controller receives workloads needing DNS resolution from the Processor via a channel, handles the DNS resolution asynchronously, and sends the resolved results back to the Processor through per-workload result channels. This design ensures that DNS resolution does not block the workload processing pipeline.
96+
97+
### Design Details
98+
99+
<!--
100+
This section should contain enough information that the specifics of your
101+
change are understandable. This may include API specs (though not always
102+
required) or even code snippets. If there's any ambiguity about HOW your
103+
proposal will be implemented, this is the place to discuss them.
104+
-->
105+
106+
#### Architecture Overview
107+
108+
The DNS resolution flow in Dual-Engine mode follows this pattern:
109+
110+
```txt
111+
Processor → WorkloadDnsController → DNSResolver → Upstream DNS
112+
↑ ↓
113+
└────── Resolved Workload ────────────┘
114+
```
115+
116+
![](./pics/dual-engine-dns.png)
117+
118+
#### Key Components
119+
120+
##### WorkloadDnsController
121+
122+
The WorkloadDnsController manages asynchronous DNS resolution for ServiceEntry-generated workloads. Key data structures:
123+
124+
- **Resolution Queue**: Buffered channel receiving workloads from Processor for non-blocking submission
125+
- **Result Channel Registry**: Per-workload result channels (indexed by UID) for independent resolution tracking
126+
- **Domain Resolution Cache**: Bidirectional index between hostnames and pending workloads for batch resolution
127+
128+
The controller operates through three concurrent workers:
129+
130+
1. **Domain Processor**: Consumes workloads, groups by domain, delegates to DNS Resolver
131+
2. **Refresh Worker**: Receives resolved addresses, constructs workload objects, delivers via result channels
132+
3. **DNS Resolver**: Executes DNS queries (A/AAAA), maintains TTL-based cache (reused from `pkg/dns`)
133+
134+
##### Resolution Flow
135+
136+
The DNS resolution mechanism follows a producer-consumer pattern with timeout protection:
137+
138+
**Workload Submission**: When the Processor encounters a workload without addresses, it registers a result channel and enqueues the workload for resolution. The Processor blocks on the result channel with a 3-second timeout to prevent pipeline blocking.
139+
140+
**Domain Aggregation**: The Domain Processor maintains a hostname-indexed cache to aggregate workloads requiring the same domain, reducing redundant DNS queries. It checks for cached resolutions before initiating new queries.
141+
142+
**Address Resolution**: The DNS Resolver performs parallel IPv4 (A) and IPv6 (AAAA) queries, respecting DNS TTL values. Resolved addresses are stored in a protocol-agnostic format.
143+
144+
**Result Distribution**: The Refresh Worker reconstructs workload objects with resolved addresses and delivers them via result channels. Channel operations include a 100ms send timeout to prevent deadlocks. After delivery, the controller removes the result channel registration to prevent memory leaks.
145+
146+
##### Cleanup Mechanism
147+
148+
When a workload is deleted, the controller:
149+
150+
- Removes the workload from pending hostname tracking
151+
- Removes the workload from the hostname's pending domain cache
152+
- If no more workloads depend on the hostname, unwatches the domain from DNS resolver
153+
154+
This ensures no memory leaks and prevents unnecessary DNS queries.
155+
156+
##### Design Rationale
157+
158+
The WorkloadDnsController design diverges from AdsDnsController in several key aspects to better accommodate workload-level resolution requirements:
159+
160+
| Design Decision | Approach | Rationale |
161+
|----------------|----------|-----------|
162+
| **Result Delivery** | Dedicated per-workload channels | Eliminates result filtering overhead and spurious wake-ups; enables direct workload-specific blocking without cross-workload interference |
163+
| **Timeout Strategy** | Two-tier mechanism (3s processor + 100ms channel) | Processor-level timeout prevents indefinite pipeline blocking; channel-level timeout prevents deadlocks from abandoned consumers |
164+
| **Address Format** | `netip.ParseAddr().AsSlice()` byte representation | Provides protocol-agnostic representation supporting both IPv4 and IPv6 without conditional logic |
165+
| **Refresh Interval** | Fixed 200ms rate | Simplifies implementation while maintaining adequate freshness for typical ServiceEntry use cases; trades configurability for consistency |
166+
167+
#### Integration Points
168+
169+
The WorkloadDnsController integrates into the Kmesh control plane through two primary integration points:
170+
171+
| Component | Integration Method | Lifecycle |
172+
|-----------|-------------------|-----------|
173+
| **WorkloadController** | Instantiated during `NewController()` | Started via `Run()` context; shutdown via context cancellation |
174+
| **Processor** | Reference-based invocation | Synchronous blocking on resolution for address-less workloads; ensures data consistency before processing |
175+
176+
**Initialization Sequence**:
177+
178+
1. WorkloadController creates WorkloadDnsController instance
179+
2. DnsController reference stored in Processor
180+
3. DnsController goroutines started when WorkloadController.Run() is invoked
181+
4. Lifecycle bound to WorkloadController's context
182+
183+
**Runtime Interaction**:
184+
185+
1. Processor detects workload without addresses (ServiceEntry-originated)
186+
2. Processor registers result channel in DnsController
187+
3. Processor submits workload to resolution queue
188+
4. Processor blocks on result channel with timeout
189+
5. DnsController delivers resolved workload or timeout expires
190+
6. Processor continues with workload processing
191+
192+
#### Comparison with AdsDnsController
193+
194+
| Aspect | AdsDnsController | WorkloadDnsController |
195+
|--------|------------------|----------------------|
196+
| **Input** | Clusters with DNS endpoints | Workloads without addresses |
197+
| **Processing Unit** | Cluster | Workload |
198+
| **Result Delivery** | Shared channel | Per-workload channels |
199+
| **Timeout** | No processor timeout | 3s processor + 100ms channel |
200+
| **Refresh Rate** | From cluster config | Fixed 200ms |
201+
| **Cleanup** | On cluster removal | On workload removal |
202+
203+
#### Test Plan
204+
205+
<!--
206+
**Note:** *Not required until targeted at a release.*
207+
Consider the following in developing a test plan for this enhancement:
208+
- Will there be e2e and integration tests, in addition to unit tests?
209+
- How will it be tested in isolation vs with other components?
210+
No need to outline all test cases, just the general strategy. Anything
211+
that would count as tricky in the implementation, and anything particularly
212+
challenging to test, should be called out.
213+
-->
214+
215+
**Unit Tests**
216+
217+
DNS controller unit tests cover IPv4, IPv6, and dual-stack resolution scenarios, workload address overwriting logic, cleanup on workload deletion, and concurrent resolution of multiple workloads.
218+
219+
**E2E Tests**
220+
221+
E2E test validates the end-to-end ServiceEntry DNS resolution flow by creating a ServiceEntry with DNS resolution pointing to a fake hostname, creating a VirtualService routing the fake hostname to a real service, and verifying traffic flows successfully.
222+
223+
Note: DNS proxy is disabled in IPv6-only environments, so tests skip in that configuration.
224+
225+
### Alternatives
226+
227+
<!--
228+
What other approaches did you consider, and why did you rule them out? These do
229+
not need to be as detailed as the proposal, but should include enough
230+
information to express the idea and why it was not acceptable.
231+
-->
232+
233+
**Synchronous Resolution in Processor**: Embedding DNS resolution directly within the Processor's main workload handling loop would introduce blocking behavior, eliminating the possibility of batching concurrent resolutions for identical domains and complicating timeout implementation. This approach violates the separation of concerns principle by coupling network I/O with workload state management.
234+
235+
**Shared Result Channel**: Reusing AdsDnsController's single shared channel pattern would necessitate complex result filtering logic to match responses with their corresponding workload requests. The additional synchronization overhead and potential for spurious wake-ups make this approach less suitable for workload-level granularity.
236+
237+
**Kernel-Space DNS Resolution**: Implementing DNS resolution within eBPF programs would require reimplementing the DNS protocol stack in a constrained execution environment with strict complexity limits. This approach would duplicate existing userspace functionality, significantly increase maintenance burden, and provide minimal performance benefits given the infrequent nature of DNS lookups.
238+
239+
<!--
240+
Note: This is a simplified version of kubernetes enhancement proposal template.
241+
https://github.com/kubernetes/enhancements/tree/3317d4cb548c396a430d1c1ac6625226018adf6a/keps/NNNN-kep-template
242+
-->
589 KB
Loading
113 KB
Loading

0 commit comments

Comments
 (0)