Skip to content

Commit

Permalink
The DNS search path on Windows is now restored when Telepresence quits
Browse files Browse the repository at this point in the history
The DNS search path that Telepresence uses to simulate the DNS lookup
functionality in the connected cluster namespace was not removed by a
`telepresence quit`, resulting in connectivity problems from the
workstation. Telepresence will now remove the entries that it has added
to the search list when it quits.

Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Nov 25, 2023
1 parent 81cb2b1 commit fa73ab7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ items:
- version: 2.17.1
date: (TBD)
notes:
- type: bugfix
title: The DNS search path on Windows is now restored when Telepresence quits
body: The DNS search path that Telepresence uses to simulate the DNS lookup functionality in the connected
cluster namespace was not removed by a <code>telepresence quit</code>, resulting in connectivity problems
from the workstation. Telepresence will now remove the entries that it has added to the search list when
it quits.
- type: bugfix
title: Multiple services ports using the same target port would not get intercepted correctly.
body: Intercepts didn't work when multiple service ports were using the same container port. Telepresence would
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/rootd/dns/server_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func (s *Server) Worker(c context.Context, dev vif.Device, configureDNS func(net
g := dgroup.NewGroup(c, dgroup.GroupConfig{})
g.Go("Server", func(c context.Context) error {
// No need to close listener. It's closed by the dns server.
defer func() {
c, cancel := context.WithTimeout(context.WithoutCancel(c), 5*time.Second)
_ = dev.SetDNS(c, s.clusterDomain, s.config.RemoteIp, nil)
cancel()
}()
s.processSearchPaths(g, s.updateRouterDNS, dev)
return s.Run(c, make(chan struct{}), []net.PacketConn{listener}, nil, s.resolveInCluster)
})
Expand Down
18 changes: 12 additions & 6 deletions pkg/vif/device_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,26 @@ func (t *nativeDevice) setDNS(ctx context.Context, clusterDomain string, server
if err != nil {
return err
}
// Windows does not use a dot suffix in the search path.
clusterDomain = strings.TrimSuffix(clusterDomain, ".")

// Put our new search path in front of other entries. Then include those
// that don't end with our cluster domain (these are entries that aren't
// managed by Telepresence).
uniq := make(map[string]int, len(searchList)+len(gss))
i := 0
for _, gs := range searchList {
gs = strings.TrimSuffix(gs, ".")
if _, ok := uniq[gs]; !ok {
uniq[gs] = i
i++
}
}
clusterDomainDot := "." + clusterDomain
clusterDomain = strings.TrimSuffix(clusterDomainDot, ".")
ours := func(gs string) bool {
return strings.HasSuffix(gs, clusterDomain) || strings.HasSuffix(gs, clusterDomainDot) || gs == "tel2-search"
}

for _, gs := range gss {
if !strings.HasSuffix(gs, clusterDomain) {
if !ours(gs) {
if _, ok := uniq[gs]; !ok {
uniq[gs] = i
i++
Expand All @@ -241,7 +245,7 @@ func psList(values []string) string {
sb.WriteByte(',')
}
sb.WriteByte('"')
sb.WriteString(strings.TrimSuffix(gs, "."))
sb.WriteString(gs)
sb.WriteByte('"')
}
sb.WriteByte(')')
Expand Down Expand Up @@ -311,7 +315,9 @@ func (t *nativeDevice) setRegistryGlobalSearchList(ctx context.Context, gss []st
dlog.Errorf(ctx, `creating/opening registry value %s\%s failed: %v`, tcpParamKey, searchListKey, err)
} else {
defer rk.Close()
if err = rk.SetStringValue(searchListKey, strings.Join(gss, ",")); err != nil {
rv := strings.Join(gss, ",")
dlog.Debugf(ctx, `setting registry value %s\%s to %s`, tcpParamKey, searchListKey, rv)
if err = rk.SetStringValue(searchListKey, rv); err != nil {
dlog.Errorf(ctx, `setting registry value %s\%s failed: %v`, tcpParamKey, searchListKey, err)
}
}
Expand Down

0 comments on commit fa73ab7

Please sign in to comment.