mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-09-27 03:36:09 +08:00
feat: support service type externalName (#464)
This commit is contained in:
@@ -39,6 +39,8 @@ type Config struct {
|
||||
Hosts []Entry
|
||||
Lock *sync.Mutex
|
||||
|
||||
HowToGetExternalName func(name string) (string, error)
|
||||
|
||||
// only set it on linux
|
||||
OSConfigurator dns.OSConfigurator
|
||||
}
|
||||
@@ -278,10 +280,19 @@ func (c *Config) generateAppendHosts(serviceList []v12.Service, hosts []Entry) [
|
||||
if strings.EqualFold(service.Name, ServiceKubernetes) {
|
||||
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
|
||||
}
|
||||
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) {
|
||||
entryList = append([]Entry{e}, entryList...)
|
||||
}
|
||||
|
@@ -622,6 +622,22 @@ func (c *ConnectOptions) setupDNS(ctx context.Context) error {
|
||||
TunName: c.tunName,
|
||||
Hosts: c.extraHost,
|
||||
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...")
|
||||
if err = c.dnsConfig.SetupDNS(ctx); err != nil {
|
||||
|
Reference in New Issue
Block a user