Skip to content

Commit c4cb113

Browse files
add more comments
Signed-off-by: LiZhenCheng9527 <[email protected]>
1 parent f4397ea commit c4cb113

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/controller/ads/dns.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ func NewDnsResolver(adsCache *AdsCache) (*dnsController, error) {
7070
}
7171

7272
func (r *dnsController) Run(stopCh <-chan struct{}) {
73-
// start dns resolver
73+
// Start dns resolver
7474
go r.dnsResolver.StartDnsResolver(stopCh)
75+
// Handle cds updates when a hostname completes resolution
7576
go r.refreshAdsWorker(stopCh)
77+
// Consumption of clusters to be resolved.
7678
go r.startDnsController()
7779
go func() {
7880
<-stopCh
@@ -92,20 +94,23 @@ func (r *dnsController) resolveDomains(cds []*clusterv3.Cluster) {
9294
// store all pending hostnames of clusters in r.hostInfo
9395
for _, cluster := range cds {
9496
clusterName := cluster.GetName()
95-
info := getHostInfo(cluster)
97+
info := getHostName(cluster)
9698
r.pendingClusterInfo[clusterName] = info
9799
}
98100

99101
// delete any scheduled re-resolve for domains we no longer care about
100102
r.dnsResolver.RemoveUnwatchDomain(hostNames)
101103

104+
// Update clusters based on the data in the dns cache.
102105
for k, v := range domains {
103106
addresses := r.dnsResolver.GetDNSAddresses(k)
104107
// Already have record in dns cache
105108
if addresses != nil {
106109
r.updateClusters(v, addresses)
107110
go r.cache.ClusterCache.Flush()
108111
} else {
112+
// Initialize the newly added hostname
113+
// and add it to the dns queue to be resolved.
109114
r.dnsResolver.InitializeDomainInCache(k)
110115
domainInfo := &dns.DomainInfo{
111116
Domain: v.DomainName,
@@ -116,6 +121,7 @@ func (r *dnsController) resolveDomains(cds []*clusterv3.Cluster) {
116121
}
117122
}
118123

124+
// Handle cds updates when a hostname completes resolution
119125
func (r *dnsController) refreshAdsWorker(stop <-chan struct{}) {
120126
for {
121127
select {
@@ -223,7 +229,8 @@ func buildLbEndpoints(port uint32, addrs []string) []*endpointv3.LbEndpoint {
223229
return lbEndpoints
224230
}
225231

226-
func getHostInfo(cluster *clusterv3.Cluster) []string {
232+
// Get the hostname to be resolved in Cluster
233+
func getHostName(cluster *clusterv3.Cluster) []string {
227234
info := []string{}
228235
for _, e := range cluster.LoadAssignment.Endpoints {
229236
for _, le := range e.LbEndpoints {

0 commit comments

Comments
 (0)