Skip to content

Commit 0756803

Browse files
Merge pull request #19950 from pravisankar/fix-ttl-handling
Do not throw spurious error when minTTL=0 for the domain in egress network policy
2 parents f62ffd8 + 5fa1323 commit 0756803

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/network/common/dns.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func (d *DNS) updateOne(dns string) (error, bool) {
112112

113113
ips, minTTL, err := d.getIPsAndMinTTL(dns)
114114
if err != nil {
115+
res.nextQueryTime = time.Now().Add(defaultTTL)
116+
d.dnsMap[dns] = res
115117
return err, false
116118
}
117119

@@ -128,6 +130,7 @@ func (d *DNS) updateOne(dns string) (error, bool) {
128130

129131
func (d *DNS) getIPsAndMinTTL(domain string) ([]net.IP, time.Duration, error) {
130132
ips := []net.IP{}
133+
ttlSet := false
131134
var minTTL uint32
132135

133136
for _, server := range d.nameservers {
@@ -154,16 +157,21 @@ func (d *DNS) getIPsAndMinTTL(domain string) ([]net.IP, time.Duration, error) {
154157
case *dns.A:
155158
ips = append(ips, t.A)
156159

157-
if minTTL == 0 || t.Hdr.Ttl < minTTL {
160+
if !ttlSet || t.Hdr.Ttl < minTTL {
158161
minTTL = t.Hdr.Ttl
162+
ttlSet = true
159163
}
160164
}
161165
}
162166
}
163167
}
164168

169+
if !ttlSet {
170+
return nil, defaultTTL, fmt.Errorf("IPv4 addr not found for domain: %q, nameservers: %v", domain, d.nameservers)
171+
}
172+
165173
ttl, err := time.ParseDuration(fmt.Sprintf("%ds", minTTL))
166-
if err != nil || minTTL == 0 {
174+
if err != nil {
167175
utilruntime.HandleError(fmt.Errorf("Invalid TTL value for domain: %q, err: %v, defaulting ttl=%s", domain, err, defaultTTL.String()))
168176
ttl = defaultTTL
169177
}

0 commit comments

Comments
 (0)