mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
cancel reload /etc/resolv.conf before restore dns setting up
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
miekgdns "github.com/miekg/dns"
|
||||
@@ -15,6 +16,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var cancel context.CancelFunc
|
||||
|
||||
func SetupDNS(ip string, namespace string) error {
|
||||
/*var err error
|
||||
_ = os.RemoveAll(filepath.Join("/", "etc", "resolver"))
|
||||
@@ -29,6 +32,8 @@ func SetupDNS(ip string, namespace string) error {
|
||||
fileContent = "nameserver " + ip + "\nsearch " + namespace + ".svc.cluster.local svc.cluster.local cluster.local\noptions ndots:5"
|
||||
_ = ioutil.WriteFile(filename, []byte(fileContent), fs.ModePerm)*/
|
||||
networkSetup(ip, namespace)
|
||||
var ctx context.Context
|
||||
ctx, cancel = context.WithCancel(context.TODO())
|
||||
go func() {
|
||||
resolv := "/etc/resolv.conf"
|
||||
ticker := time.NewTicker(time.Second * 10)
|
||||
@@ -58,6 +63,8 @@ func SetupDNS(ip string, namespace string) error {
|
||||
rc.Timeout = 1
|
||||
_ = ioutil.WriteFile(resolv, []byte(toString(*rc)), 0644)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -95,6 +102,7 @@ func toString(config miekgdns.ClientConfig) string {
|
||||
}
|
||||
|
||||
func CancelDNS() {
|
||||
cancel()
|
||||
networkCancel()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user