Skip to content

Commit e03a9a5

Browse files
committed
update DNS refresh rate
Signed-off-by: Tom <[email protected]>
1 parent 3f8e03e commit e03a9a5

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

pkg/controller/workload/dns.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The Kmesh Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package workload
218

319
import (
@@ -12,6 +28,10 @@ import (
1228
"kmesh.net/kmesh/pkg/dns"
1329
)
1430

31+
const (
32+
WorkloadDnsRefreshRate = 200 * time.Millisecond // 200ms, used for workload dns refresh rate
33+
)
34+
1535
type dnsController struct {
1636
workloadsChan chan []*workloadapi.Workload
1737
cache cache.WorkloadCache
@@ -70,7 +90,7 @@ func (r *dnsController) processDomains(workload []*workloadapi.Workload) {
7090
r.pendingHostnames[workloadName] = []string{hostname}
7191
r.workloadCache[hostname] = &pendingResolveDomain{
7292
Workloads: []*workloadapi.Workload{workload},
73-
RefreshRate: 15 * time.Second,
93+
RefreshRate: WorkloadDnsRefreshRate,
7494
}
7595
}
7696

@@ -116,7 +136,7 @@ func (r *dnsController) refreshWorker(stop <-chan struct{}) {
116136

117137
func (r *dnsController) updateWorkloads(pendingDomain *pendingResolveDomain, domain string, addrs []string) {
118138
isWorkerUpdate := false
119-
if pendingDomain == nil || addrs == nil{
139+
if pendingDomain == nil || addrs == nil {
120140
return
121141
}
122142
log.Infof("dnsController updateWorkloads: pendingDomain %v, domain %s, addrs %v", pendingDomain, domain, addrs)

pkg/controller/workload/workload_processor.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -898,23 +898,26 @@ func (p *Processor) handleServicesAndWorkloads(services []*workloadapi.Service,
898898
p.DnsResolverChan <- workloads
899899
}
900900
go func() {
901-
maxRetries := 30
901+
maxRetries := 50
902+
var address [][]byte
902903
for range maxRetries {
903904
workload := p.WorkloadCache.GetWorkloadByUid(uid)
904-
address := workload.GetAddresses()
905-
if address != nil {
906-
log.Infof("workload: %s/%s addresses resolved: %v", workload.Namespace, workload.Name, address)
907-
if err := p.handleWorkload(workload); err != nil {
908-
log.Errorf("handle workload %s failed, err: %v", workload.ResourceName(), err)
909-
}
905+
if address = workload.GetAddresses(); address != nil {
910906
break
911907
} else {
912-
log.Warnf("workload: %s/%s addresses is still nil, retrying...", workload.Namespace, workload.Name)
908+
time.Sleep(WorkloadDnsRefreshRate)
913909
}
914-
time.Sleep(1 * time.Second)
910+
}
911+
if address != nil {
912+
log.Infof("workload: %s/%s addresses resolved: %v", workload.Namespace, workload.Name, address)
913+
if err := p.handleWorkload(workload); err != nil {
914+
log.Errorf("handle workload %s failed, err: %v", workload.ResourceName(), err)
915+
}
916+
} else {
917+
log.Warnf("workload: %s/%s addresses is still nil after %d retries, skipping", workload.Namespace, workload.Name, maxRetries)
915918
}
916919
}()
917-
// wait for the service entry to be resolved
920+
918921
}
919922
}
920923
if err := p.handleWorkload(workload); err != nil {

0 commit comments

Comments
 (0)