Skip to content

Commit 4a9e8d8

Browse files
Fix config not be refreshed some times
1 parent b9d7da4 commit 4a9e8d8

File tree

1 file changed

+35
-41
lines changed

1 file changed

+35
-41
lines changed

go/plugin/coredns/pfdns/pfconfig.go

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,78 +30,72 @@ type pfdnsRefreshableConfig struct {
3030
}
3131

3232
func newPfconfigRefreshableConfig(ctx context.Context) *pfdnsRefreshableConfig {
33-
p := &pfdnsRefreshableConfig{
33+
rc := &pfdnsRefreshableConfig{
3434
DNSFilter: cache.New(300*time.Second, 10*time.Second),
3535
IpsetCache: cache.New(1*time.Hour, 10*time.Second),
3636
}
37-
pfconfigdriver.FetchDecodeSocket(ctx, &p.registration)
38-
pfconfigdriver.FetchDecodeSocket(ctx, &p.isolation)
39-
pfconfigdriver.FetchDecodeSocket(ctx, &p.PfConfDns)
40-
p.PassthroughsInit(ctx)
41-
p.PassthroughsIsolationInit(ctx)
42-
p.recordDNS = p.PfConfDns.RecordDNS == "enabled"
43-
return p
37+
pfconfigdriver.FetchDecodeSocket(ctx, &rc.registration)
38+
pfconfigdriver.FetchDecodeSocket(ctx, &rc.isolation)
39+
pfconfigdriver.FetchDecodeSocket(ctx, &rc.PfConfDns)
40+
rc.PassthroughsInit(ctx)
41+
rc.PassthroughsIsolationInit(ctx)
42+
rc.recordDNS = rc.PfConfDns.RecordDNS == "enabled"
43+
return rc
4444
}
4545

46-
func (pf *pfdnsRefreshableConfig) PassthroughsInit(ctx context.Context) error {
47-
pfconfigdriver.FetchDecodeSocket(ctx, &pf.registration)
46+
func (rc *pfdnsRefreshableConfig) PassthroughsInit(ctx context.Context) error {
47+
rc.FqdnPort = make(map[*regexp.Regexp][]string)
4848

49-
pf.FqdnPort = make(map[*regexp.Regexp][]string)
50-
51-
for k, v := range pf.registration.Wildcard {
49+
for k, v := range rc.registration.Wildcard {
5250
rgx, _ := regexp.Compile(".*" + k)
53-
pf.FqdnPort[rgx] = v
51+
rc.FqdnPort[rgx] = v
5452
}
5553

56-
for k, v := range pf.registration.Normal {
54+
for k, v := range rc.registration.Normal {
5755
rgx, _ := regexp.Compile("^" + k + ".$")
58-
pf.FqdnPort[rgx] = v
56+
rc.FqdnPort[rgx] = v
5957
}
6058

6159
return nil
6260
}
6361

64-
func (pf *pfdnsRefreshableConfig) PassthroughsIsolationInit(ctx context.Context) error {
65-
pfconfigdriver.FetchDecodeSocket(ctx, &pf.isolation)
66-
67-
pf.FqdnIsolationPort = make(map[*regexp.Regexp][]string)
62+
func (rc *pfdnsRefreshableConfig) PassthroughsIsolationInit(ctx context.Context) error {
63+
rc.FqdnIsolationPort = make(map[*regexp.Regexp][]string)
6864

69-
for k, v := range pf.isolation.Wildcard {
65+
for k, v := range rc.isolation.Wildcard {
7066
rgx, _ := regexp.Compile(".*" + k)
71-
pf.FqdnIsolationPort[rgx] = v
67+
rc.FqdnIsolationPort[rgx] = v
7268
}
7369

74-
for k, v := range pf.isolation.Normal {
70+
for k, v := range rc.isolation.Normal {
7571
rgx, _ := regexp.Compile("^" + k + ".$")
76-
pf.FqdnIsolationPort[rgx] = v
72+
rc.FqdnIsolationPort[rgx] = v
7773
}
7874

7975
return nil
8076
}
8177

82-
func (p *pfdnsRefreshableConfig) IsValid(ctx context.Context) bool {
83-
return pfconfigdriver.IsValid(ctx, &p.registration) && pfconfigdriver.IsValid(ctx, &p.isolation) && pfconfigdriver.IsValid(ctx, &p.PfConfDns)
78+
func (rc *pfdnsRefreshableConfig) IsValid(ctx context.Context) bool {
79+
return pfconfigdriver.IsValid(ctx, &rc.registration) && pfconfigdriver.IsValid(ctx, &rc.isolation) && pfconfigdriver.IsValid(ctx, &rc.PfConfDns)
8480
}
8581

86-
func (p *pfdnsRefreshableConfig) Refresh(ctx context.Context) {
87-
if !pfconfigdriver.IsValid(ctx, &p.registration) || !pfconfigdriver.IsValid(ctx, &p.isolation) {
88-
p.PassthroughsInit(ctx)
89-
p.PassthroughsIsolationInit(ctx)
90-
p.DNSFilter = cache.New(300*time.Second, 10*time.Second)
91-
p.IpsetCache = cache.New(1*time.Hour, 10*time.Second)
92-
}
82+
func (rc *pfdnsRefreshableConfig) Refresh(ctx context.Context) {
83+
pfconfigdriver.FetchDecodeSocket(ctx, &rc.registration)
84+
pfconfigdriver.FetchDecodeSocket(ctx, &rc.isolation)
85+
pfconfigdriver.FetchDecodeSocket(ctx, &rc.PfConfDns)
86+
rc.PassthroughsInit(ctx)
87+
rc.PassthroughsIsolationInit(ctx)
9388

94-
pfconfigdriver.FetchDecodeSocket(ctx, &p.PfConfDns)
95-
p.recordDNS = p.PfConfDns.RecordDNS == "enabled"
89+
rc.recordDNS = rc.PfConfDns.RecordDNS == "enabled"
9690
}
9791

98-
func (p *pfdnsRefreshableConfig) Clone() pfconfigdriver.Refresh {
92+
func (rc *pfdnsRefreshableConfig) Clone() pfconfigdriver.Refresh {
9993
return &pfdnsRefreshableConfig{
100-
registration: p.registration,
101-
isolation: p.isolation,
102-
PfConfDns: p.PfConfDns,
103-
DNSFilter: p.DNSFilter,
104-
IpsetCache: p.IpsetCache,
94+
registration: rc.registration,
95+
isolation: rc.isolation,
96+
PfConfDns: rc.PfConfDns,
97+
DNSFilter: rc.DNSFilter,
98+
IpsetCache: rc.IpsetCache,
10599
}
106100
}
107101

0 commit comments

Comments
 (0)