mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
refactor: refactor dns (#218)
* refactor: refactor dns * refactor: optimize forward dns server * refactor: add short domain test * refactor: fix remove nameserver from resolver bug --------- Co-authored-by: wencaiwulue <895703375@qq.com>
This commit is contained in:
@@ -195,7 +195,7 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
|
||||
flags.Var(&copts.groupAdd, "group-add", "Add additional groups to join")
|
||||
flags.StringVarP(&copts.hostname, "hostname", "h", "", "Container host name")
|
||||
flags.StringVar(&copts.domainname, "domainname", "", "Container NIS domain name")
|
||||
flags.BoolVarP(&copts.stdin, "interactive", "i", false, "Keep STDIN open even if not attached")
|
||||
flags.BoolVarP(&copts.stdin, "interactive", "i", true, "Keep STDIN open even if not attached")
|
||||
flags.VarP(&copts.labels, "label", "l", "Set meta data on a container")
|
||||
flags.Var(&copts.labelsFile, "label-file", "Read in a line delimited file of labels")
|
||||
flags.BoolVar(&copts.readonlyRootfs, "read-only", false, "Mount the container's root filesystem as read only")
|
||||
@@ -204,16 +204,16 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
|
||||
flags.IntVar(&copts.stopTimeout, "stop-timeout", 0, "Timeout (in seconds) to stop a container")
|
||||
flags.SetAnnotation("stop-timeout", "version", []string{"1.25"})
|
||||
flags.Var(copts.sysctls, "sysctl", "Sysctl options")
|
||||
flags.BoolVarP(&copts.tty, "tty", "t", false, "Allocate a pseudo-TTY")
|
||||
flags.BoolVarP(&copts.tty, "tty", "t", true, "Allocate a pseudo-TTY")
|
||||
flags.Var(copts.ulimits, "ulimit", "Ulimit options")
|
||||
flags.StringVarP(&copts.user, "user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
|
||||
flags.StringVarP(&copts.workingDir, "workdir", "w", "", "Working directory inside the container")
|
||||
flags.BoolVar(&copts.autoRemove, "rm", false, "Automatically remove the container when it exits")
|
||||
flags.BoolVar(&copts.autoRemove, "rm", true, "Automatically remove the container when it exits")
|
||||
|
||||
// Security
|
||||
flags.Var(&copts.capAdd, "cap-add", "Add Linux capabilities")
|
||||
flags.Var(&copts.capDrop, "cap-drop", "Drop Linux capabilities")
|
||||
flags.BoolVar(&copts.privileged, "privileged", false, "Give extended privileges to this container")
|
||||
flags.BoolVar(&copts.privileged, "privileged", true, "Give extended privileges to this container")
|
||||
flags.Var(&copts.securityOpt, "security-opt", "Security Options")
|
||||
flags.StringVar(&copts.usernsMode, "userns", "", "User namespace to use")
|
||||
flags.StringVar(&copts.cgroupnsMode, "cgroupns", "", `Cgroup namespace to use (host|private)
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package dev
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/v2/pkg/util"
|
||||
)
|
||||
|
||||
@@ -86,5 +90,20 @@ func mergeDockerOptions(r ConfigList, copts *Options, tempContainerConfig *conta
|
||||
}
|
||||
}
|
||||
|
||||
var hosts []string
|
||||
for _, domain := range copts.ExtraRouteInfo.ExtraDomain {
|
||||
ips, err := net.LookupIP(domain)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, ip := range ips {
|
||||
if ip.To4() != nil {
|
||||
hosts = append(hosts, fmt.Sprintf("%s:%s", domain, ip.To4().String()))
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
config.hostConfig.ExtraHosts = hosts
|
||||
|
||||
config.config = c
|
||||
}
|
||||
|
||||
@@ -265,7 +265,6 @@ func (option *Options) connect(ctx context.Context, f cmdutil.Factory, conf *uti
|
||||
Headers: connect.Headers,
|
||||
Workloads: connect.Workloads,
|
||||
ExtraRoute: connect.ExtraRouteInfo.ToRPC(),
|
||||
UseLocalDNS: connect.UseLocalDNS,
|
||||
Engine: string(connect.Engine),
|
||||
OriginKubeconfigPath: util.GetKubeConfigPath(f),
|
||||
TransferImage: transferImage,
|
||||
@@ -273,7 +272,7 @@ func (option *Options) connect(ctx context.Context, f cmdutil.Factory, conf *uti
|
||||
Level: int32(logLevel),
|
||||
SshJump: conf.ToRPC(),
|
||||
}
|
||||
cancel := disconnect(ctx, daemonCli, &rpc.DisconnectRequest{
|
||||
cancel := disconnect(ctx, daemonCli, &rpc.LeaveRequest{Workloads: connect.Workloads}, &rpc.DisconnectRequest{
|
||||
KubeconfigBytes: ptr.To(string(kubeConfigBytes)),
|
||||
Namespace: ptr.To(ns),
|
||||
SshJump: conf.ToRPC(),
|
||||
@@ -358,15 +357,28 @@ func (option *Options) connect(ctx context.Context, f cmdutil.Factory, conf *uti
|
||||
}
|
||||
}
|
||||
|
||||
func disconnect(ctx context.Context, daemonClient rpc.DaemonClient, req *rpc.DisconnectRequest) func() {
|
||||
func disconnect(ctx context.Context, daemonClient rpc.DaemonClient, leaveReq *rpc.LeaveRequest, req *rpc.DisconnectRequest) func() {
|
||||
return func() {
|
||||
resp, err := daemonClient.Disconnect(ctx, req)
|
||||
resp, err := daemonClient.Leave(ctx, leaveReq)
|
||||
if err == nil {
|
||||
for {
|
||||
msg, err := resp.Recv()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
log.Errorf("leave resource %s error: %v", strings.Join(leaveReq.Workloads, " "), err)
|
||||
break
|
||||
}
|
||||
fmt.Fprint(os.Stdout, msg.Message)
|
||||
}
|
||||
}
|
||||
resp1, err := daemonClient.Disconnect(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("disconnect error: %v", err)
|
||||
return
|
||||
}
|
||||
for {
|
||||
msg, err := resp.Recv()
|
||||
msg, err := resp1.Recv()
|
||||
if err == io.EOF {
|
||||
return
|
||||
} else if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user