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

Refactor dns #1247

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

LiZhenCheng9527
Copy link
Collaborator

What type of PR is this?
/kind enhancement

What this PR does / why we need it:
Refactored the DNS resolution module to decouple it from the CDS in Kernel-Native mode. This facilitates the reuse of the DNS resolution module in Dual-Engine mode.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@LiZhenCheng9527 LiZhenCheng9527 added this to the v1.1 milestone Feb 21, 2025
@kmesh-bot kmesh-bot added the kind/enhancement New feature or request label Feb 21, 2025
@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from lizhencheng9527. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 66.01307% with 104 lines in your changes missing coverage. Please review.

Project coverage is 44.89%. Comparing base (726da17) to head (b9ce631).
Report is 50 commits behind head on main.

Files with missing lines Patch % Lines
pkg/dns/dns.go 33.33% 53 Missing and 5 partials ⚠️
pkg/controller/ads/dns.go 81.33% 17 Missing and 11 partials ⚠️
pkg/dns/utils.go 78.46% 10 Missing and 4 partials ⚠️
pkg/controller/controller.go 0.00% 4 Missing ⚠️

❌ Your patch check has failed because the patch coverage (66.01%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Files with missing lines Coverage Δ
pkg/controller/controller.go 0.00% <0.00%> (ø)
pkg/dns/utils.go 78.46% <78.46%> (ø)
pkg/controller/ads/dns.go 81.33% <81.33%> (ø)
pkg/dns/dns.go 51.54% <33.33%> (-22.66%) ⬇️

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 938599d...b9ce631. Read the comment docs.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LiZhenCheng9527
Copy link
Collaborator Author

LiZhenCheng9527 commented Feb 24, 2025

PTAL
/cc @hzxuzhonghu

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest we do provide a dns pkg fundamental capability and make ads/workload bussiness related part in their own pkg

}

func (adsResolver *AdsDnsResolver) refreshAdsWorker() {
for adsResolver.refreshAdsDns() {
Copy link
Member

Choose a reason for hiding this comment

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

I do believe such arch should be shared with workload

pkg/dns/dns.go Outdated
}

return ready
type PendingResolveDomain struct {
Copy link
Member

Choose a reason for hiding this comment

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

How do you plean to support dual-engine then?
If you are going to add another struct here, wouldn't that still coupling

)

// adsDnsResolver is DNS resolver of Kernel Native
type AdsDnsResolver struct {
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
type AdsDnsResolver struct {
type DnsResolver struct {

dnsRefreshQueue workqueue.TypedDelayingInterface[any]
}

func NewAdsDnsResolver(adsCache *AdsCache) (*AdsDnsResolver, error) {
Copy link
Member

Choose a reason for hiding this comment

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

It is under ads pkg, so we can remove the redundant

Suggested change
func NewAdsDnsResolver(adsCache *AdsCache) (*AdsDnsResolver, error) {
func NewDnsResolver(adsCache *AdsCache) (*DnsResolver, error) {

@hzxuzhonghu hzxuzhonghu requested review from Copilot and removed request for Copilot February 27, 2025 06:36

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@hzxuzhonghu hzxuzhonghu requested review from Copilot and removed request for Copilot February 27, 2025 07:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR refactors and decouples the DNS resolution module from the CDS in Kernel-Native mode to support reuse in Dual-Engine mode. The changes introduce a fake DNS server for testing, a new ADS DNS Resolver, controller updates to use the new resolver, and significant refactoring in the DNS resolver implementation.

  • Added a fakeDNSServer implementation in pkg/dns/utils.go.
  • Created a new AdsDnsResolver in pkg/controller/ads/dns.go and updated the controller to utilize it.
  • Refactored pkg/dns/dns.go by cleaning up internal structures and updating locking and resolution logic.

Reviewed Changes

File Description
pkg/dns/utils.go Introduces a fake DNS server for testing purposes.
pkg/controller/ads/dns.go Implements a new ADS DNS Resolver for Kernel-Native mode.
pkg/controller/controller.go Updates the controller to use the new ADS DNS Resolver.
pkg/dns/dns.go Refactors the DNS resolver implementation, updating locks and API.

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment on lines +95 to +98
func (s *fakeDNSServer) SetHosts(domain string, surfix int) {
s.mu.Lock()
defer s.mu.Unlock()
s.hosts[dns.Fqdn(domain)] = surfix
Copy link
Preview

Copilot AI Feb 27, 2025

Choose a reason for hiding this comment

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

The parameter name 'surfix' appears to be a typo. It should likely be renamed to 'suffix' for clarity.

Suggested change
func (s *fakeDNSServer) SetHosts(domain string, surfix int) {
s.mu.Lock()
defer s.mu.Unlock()
s.hosts[dns.Fqdn(domain)] = surfix
func (s *fakeDNSServer) SetHosts(domain string, suffix int) {
s.mu.Lock()
defer s.mu.Unlock()
s.hosts[dns.Fqdn(domain)] = suffix

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
pkg/dns/dns.go Outdated
Comment on lines 113 to 146
r.RLock()
_, exist := r.cache[dr.domainName]
entry.addresses = addrs
r.RUnlock()
// if the domain is no longer watched, no need to refresh it
if !exist {
return true
}
r.resolve(dr)
r.adsCache.ClusterCache.Flush()
return true
}

Copy link
Preview

Copilot AI Feb 27, 2025

Choose a reason for hiding this comment

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

A write operation is performed under a read lock, which can lead to race conditions. Consider acquiring a full write lock when updating 'entry.addresses'.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR refactors the DNS resolution module to decouple it from the CDS for Kernel-Native mode, enabling reuse in Dual-Engine mode. Key changes include:

  • Addition of a fake DNS server in pkg/dns/utils.go for testing and simulation.
  • Introduction of an Ads DNS resolver and its integration in pkg/controller/ads/dns.go and pkg/controller/controller.go.
  • Updates to the DNS resolver implementation in pkg/dns/dns.go to simplify the interface and remove dependencies on AdsCache.

Reviewed Changes

File Description
pkg/dns/utils.go Adds a fake DNS server implementation for testing DNS responses and host mapping.
pkg/controller/ads/dns_test.go Includes tests verifying DNS cluster overwrite, concurrent cache updates, and domain handling.
pkg/controller/ads/dns.go Introduces the Ads DNS resolver that integrates with the cluster cache and DNS module.
pkg/controller/controller.go Modifies controller start-up to use the new Ads DNS resolver for Kernel-Native mode.
pkg/dns/dns.go Refactors the DNS resolver to remove unused parameters and adjust the refresh loop handling.

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines +95 to +98
func (s *fakeDNSServer) SetHosts(domain string, surfix int) {
s.mu.Lock()
defer s.mu.Unlock()
s.hosts[dns.Fqdn(domain)] = surfix
Copy link
Preview

Copilot AI Feb 28, 2025

Choose a reason for hiding this comment

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

The parameter name 'surfix' appears to be a misspelling; consider renaming it to 'suffix' for clarity.

Suggested change
func (s *fakeDNSServer) SetHosts(domain string, surfix int) {
s.mu.Lock()
defer s.mu.Unlock()
s.hosts[dns.Fqdn(domain)] = surfix
func (s *fakeDNSServer) SetHosts(domain string, suffix int) {
s.mu.Lock()
defer s.mu.Unlock()
s.hosts[dns.Fqdn(domain)] = suffix

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
pkg/dns/dns.go Outdated
Comment on lines 119 to 125
_, ttl, err := r.resolve(e.Domain)
if err != nil {
log.Errorf("failed to dns resolve: %v", err)
return false
}
if ttl > e.RefreshRate {
ttl = e.RefreshRate
}
if ttl == 0 {
ttl = DeRefreshInterval
}
r.RefreshQueue.AddAfter(e, ttl)
r.AdsDnsChan <- e.Domain

Copy link
Preview

Copilot AI Feb 28, 2025

Choose a reason for hiding this comment

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

In the refreshDns function, returning false upon a DNS resolution error stops the resolver loop. Consider handling errors with a retry mechanism instead of terminating the refresh loop.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
pkg/dns/dns.go Outdated
ttl = DeRefreshInterval
}
r.RefreshQueue.AddAfter(e, ttl)
r.AdsDnsChan <- e.Domain
Copy link
Member

Choose a reason for hiding this comment

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

what does this mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Notify adsDnsResolver that the domain has completed dns resolution


func (adsResolver *AdsDnsResolver) StartAdsDnsResolver(stopCh <-chan struct{}) {
go adsResolver.startAdsResolver()
go adsResolver.dnsResolver.StartDnsResolver()
Copy link
Member

Choose a reason for hiding this comment

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

I feel this is messy cand confusing, it is unclear what is AdsResolver and what is dns resolver

@YaoZengzeng
Copy link
Member

@LiZhenCheng9527 add a design doc first would be better for review.

Signed-off-by: LiZhenCheng9527 <[email protected]>
Signed-off-by: LiZhenCheng9527 <[email protected]>
Signed-off-by: LiZhenCheng9527 <[email protected]>
Signed-off-by: LiZhenCheng9527 <[email protected]>
Signed-off-by: LiZhenCheng9527 <[email protected]>
}
r.dnsResolver.AddDomainIntoRefreshQueue(domainInfo, 0)
}
go r.refreshAdsWorker(domains)
Copy link
Member

Choose a reason for hiding this comment

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

when will this thread exit?

func (r *dnsController) startDnsController() {
rateLimiter := make(chan struct{}, dns.MaxConcurrency)
for clusters := range r.Clusters {
rateLimiter <- struct{}{}
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure how does the ratelimiter effect, because in the dns pkg, it always run in order

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants