Skip to content

Conversation

Flying-Tom
Copy link
Contributor

@Flying-Tom Flying-Tom commented Jul 10, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

Supprort Dns resolve for workload generated by ServiceEntry in Dual-Engine mode.

Which issue(s) this PR fixes:
Fixes #1407

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@Copilot Copilot AI review requested due to automatic review settings July 10, 2025 08:48
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Flying-Tom, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new DNS resolution capability for workloads, primarily targeting ServiceEntry configurations in a Dual-Engine environment. The core change involves adding a dedicated DnsController that asynchronously resolves hostnames to IP addresses, ensuring that workloads can be correctly processed even if their addresses are not immediately available upon initial discovery. This enhances the system's adaptability to dynamic service discovery scenarios.

Highlights

  • New DNS Controller for Workloads: I've introduced a new DnsController within the pkg/controller/workload package. This controller is specifically designed to handle DNS resolution for workloads, particularly those originating from ServiceEntry configurations in Dual-Engine mode.
  • Integration with Workload Processing Pipeline: The new DnsController is now integrated into the WorkloadController and Processor. Workloads received from ServiceEntry that initially lack resolved IP addresses are now channeled to this DnsController for asynchronous DNS lookup. The Processor includes a retry mechanism to ensure these workloads are fully processed once their addresses are resolved.
  • Dynamic Address Resolution for ServiceEntry Workloads: The WorkloadProcessor has been enhanced to identify ServiceEntry workloads that arrive without pre-resolved IP addresses. It now queues these for DNS resolution via the new DnsResolverChan and includes a robust retry loop to wait for and then apply the resolved addresses, ensuring proper handling of dynamically discovered services.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copilot

This comment was marked as outdated.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a DnsController to support DNS resolution for ServiceEntry in Dual-Engine mode. There are several critical issues that could lead to panics or incorrect behavior. I've provided detailed comments and suggestions to address these points.

@Flying-Tom Flying-Tom force-pushed the dual-engine-dns branch 3 times, most recently from c7ce028 to 94ec7fa Compare July 14, 2025 02:38
@hzxuzhonghu
Copy link
Member

/assign @Kuromesi

@kmesh-bot
Copy link
Collaborator

@hzxuzhonghu: GitHub didn't allow me to assign the following users: Kuromesi.

Note that only kmesh-net members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @Kuromesi

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@hzxuzhonghu hzxuzhonghu requested a review from Copilot August 7, 2025 07:41
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.

Pull Request Overview

This PR adds DNS resolution capability for workloads generated by ServiceEntry in Dual-Engine mode, enabling proper address resolution for service entries that initially have nil addresses.

  • Implements a new DNS controller for workload address resolution
  • Adds retry logic for ServiceEntry workloads with unresolved addresses
  • Integrates DNS resolution workflow into the existing workload processing pipeline

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
pkg/controller/workload/workload_processor.go Adds DNS resolver channel, handles ServiceEntry workloads with retry logic, and includes various bug fixes
pkg/controller/workload/workload_controller.go Integrates DNS controller into workload controller lifecycle
pkg/controller/workload/dns.go New DNS controller implementation for workload address resolution
pkg/controller/controller.go Starts DNS controller in main controller flow

@Flying-Tom
Copy link
Contributor Author

The improvements mentioned in the review will be fixed.

@hzxuzhonghu
Copy link
Member

@Flying-Tom any update

if _, ok := r.pendingHostnames[workloadName]; !ok {
r.pendingHostnames[workloadName] = []string{}
}
r.pendingHostnames[workloadName] = append(r.pendingHostnames[workloadName], hostname)
Copy link
Member

Choose a reason for hiding this comment

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

not sure i understand, does a workload has multi hostnames?

if _, ok := r.pendingHostnames[workloadName]; !ok {
r.pendingHostnames[workloadName] = []string{}
}
r.pendingHostnames[workloadName] = append(r.pendingHostnames[workloadName], hostname)
Copy link
Member

Choose a reason for hiding this comment

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

another problem if this function is called multiple times with same workloads, this will store duplicate hostname

}
}
r.workloadCache[hostname].Workloads = append(
r.workloadCache[hostname].Workloads, workload,
Copy link
Member

Choose a reason for hiding this comment

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

same here, if processDomains called multitimes with same workloads, duplicate workload will be here

@hzxuzhonghu
Copy link
Member

Would like to see the ut

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.

Pull Request Overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Copilot Copilot AI review requested due to automatic review settings October 15, 2025 07:39
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.

Pull Request Overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +177 to +195
r.Lock()
ch, ok := r.ResolvedDomainChanMap[uid]
r.Unlock()

if ok {
r.cache.AddOrUpdateWorkload(newWorkload)
select {
case ch <- newWorkload:
log.Infof("workload %s/%s addresses resolved: %v", newWorkload.Namespace, newWorkload.Name, newWorkload.Addresses)
case <-time.After(WorkloadChannelSendTimeout):
log.Warnf("timeout sending resolved workload %s/%s", newWorkload.Namespace, newWorkload.Name)
}

r.Lock()
if _, stillExists := r.ResolvedDomainChanMap[uid]; stillExists {
close(r.ResolvedDomainChanMap[uid])
delete(r.ResolvedDomainChanMap, uid)
}
r.Unlock()
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

There's a potential race condition where the channel could be closed between the first unlock (line 180) and the second lock (line 191). Consider holding the lock across the entire operation or using a different synchronization approach.

Copilot uses AI. Check for mistakes.

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.

Pull Request Overview

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


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

if service.Waypoint != nil && service.GetWaypoint().GetAddress() != nil && len(service.Addresses) != 0 {
// Currently istiod only set the waypoint address to the first address of the service
// When waypoints of different granularities are deployed together, the only waypoint service to be determined
// when waypoints of different granularities are deployed together, the only waypoint service to be determined
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

The comment has inconsistent capitalization. It should start with a capital letter: 'When waypoints of different granularities are deployed together, the only waypoint service to be determined'.

Suggested change
// when waypoints of different granularities are deployed together, the only waypoint service to be determined
// When waypoints of different granularities are deployed together, the only waypoint service to be determined

Copilot uses AI. Check for mistakes.

func (p *Processor) handleAuthorizationTypeResponse(rsp *service_discovery_v3.DeltaDiscoveryResponse, rbac *auth.Rbac) error {
if rbac == nil {
return fmt.Errorf("Rbac module uninitialized")
return fmt.Errorf("rbac module uninitialized")
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

Error message capitalization is inconsistent with Go conventions. Error messages should start with lowercase unless they begin with a proper noun.

Copilot uses AI. Check for mistakes.

Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
Signed-off-by: Tom <yusencao@outlook.com>
@LiZhenCheng9527
Copy link
Contributor

/lgtm

@LiZhenCheng9527
Copy link
Contributor

/approve

@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: LiZhenCheng9527

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

The pull request process is described 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OSPP 2025] Verifying and Complementing Kmesh Feature

5 participants