mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-10-07 08:11:01 +08:00
feat: support service type externalName (#464)
This commit is contained in:
@@ -39,6 +39,8 @@ type Config struct {
|
|||||||
Hosts []Entry
|
Hosts []Entry
|
||||||
Lock *sync.Mutex
|
Lock *sync.Mutex
|
||||||
|
|
||||||
|
HowToGetExternalName func(name string) (string, error)
|
||||||
|
|
||||||
// only set it on linux
|
// only set it on linux
|
||||||
OSConfigurator dns.OSConfigurator
|
OSConfigurator dns.OSConfigurator
|
||||||
}
|
}
|
||||||
@@ -278,10 +280,19 @@ func (c *Config) generateAppendHosts(serviceList []v12.Service, hosts []Entry) [
|
|||||||
if strings.EqualFold(service.Name, ServiceKubernetes) {
|
if strings.EqualFold(service.Name, ServiceKubernetes) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if net.ParseIP(service.Spec.ClusterIP) == nil {
|
var ip net.IP
|
||||||
|
if service.Spec.ClusterIP != "" {
|
||||||
|
ip = net.ParseIP(service.Spec.ClusterIP)
|
||||||
|
}
|
||||||
|
if service.Spec.ExternalName != "" {
|
||||||
|
name, _ := c.HowToGetExternalName(service.Spec.ExternalName)
|
||||||
|
ip = net.ParseIP(name)
|
||||||
|
}
|
||||||
|
if ip == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var e = Entry{IP: service.Spec.ClusterIP, Domain: service.Name}
|
|
||||||
|
var e = Entry{IP: ip.String(), Domain: service.Name}
|
||||||
if !sets.New[Entry]().Insert(entryList...).Has(e) {
|
if !sets.New[Entry]().Insert(entryList...).Has(e) {
|
||||||
entryList = append([]Entry{e}, entryList...)
|
entryList = append([]Entry{e}, entryList...)
|
||||||
}
|
}
|
||||||
|
@@ -622,6 +622,22 @@ func (c *ConnectOptions) setupDNS(ctx context.Context) error {
|
|||||||
TunName: c.tunName,
|
TunName: c.tunName,
|
||||||
Hosts: c.extraHost,
|
Hosts: c.extraHost,
|
||||||
Lock: c.Lock,
|
Lock: c.Lock,
|
||||||
|
HowToGetExternalName: func(domain string) (string, error) {
|
||||||
|
podList, err := c.GetRunningPodList(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
pod := podList[0]
|
||||||
|
return util.Shell(
|
||||||
|
ctx,
|
||||||
|
c.clientset,
|
||||||
|
c.config,
|
||||||
|
pod.GetName(),
|
||||||
|
config.ContainerSidecarVPN,
|
||||||
|
c.Namespace,
|
||||||
|
[]string{"dig", "+short", domain},
|
||||||
|
)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
log.Debugf("Setup DNS...")
|
log.Debugf("Setup DNS...")
|
||||||
if err = c.dnsConfig.SetupDNS(ctx); err != nil {
|
if err = c.dnsConfig.SetupDNS(ctx); err != nil {
|
||||||
|
Reference in New Issue
Block a user