cmd/containerboot: refresh DNS config on SelfChange (#20236)
364b952d6 switched containerboot to partial netmap fetching, but
stopped refreshing `DNS.ExtraRecords`, so Tailscale Services created
after pod boot were invisible to resolveTailnetFQDN. To fix we watch
for SelfChange ipn bus notifies, and refetch dns-config via LocalAPI
to get a fresh set of `DNS.ExtraRecords`.
Fixes #20233
Signed-off-by: chaosinthecrd <tom@tmlabs.co.uk>
This commit is contained in:
@@ -139,6 +139,7 @@ import (
|
||||
"github.com/benbjohnson/immutable"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"tailscale.com/client/local"
|
||||
"tailscale.com/health"
|
||||
"tailscale.com/ipn"
|
||||
"tailscale.com/ipn/ipnstate"
|
||||
@@ -212,6 +213,23 @@ func (s netmapState) updateFromNotify(n ipn.Notify) netmapState {
|
||||
return s
|
||||
}
|
||||
|
||||
// processNotify updates the netmap state from an IPN bus Notify. On
|
||||
// SelfChange it also refetches DNS via the LocalAPI dns-config
|
||||
// endpoint; the bus carries no DNS delta.
|
||||
func (s netmapState) processNotify(ctx context.Context, client *local.Client, n ipn.Notify) netmapState {
|
||||
s = s.updateFromNotify(n)
|
||||
if n.SelfChange != nil {
|
||||
dns, err := client.DNSConfig(ctx)
|
||||
if err != nil {
|
||||
log.Printf("error refreshing DNS config from tailscaled: %v", err)
|
||||
} else if dns != nil {
|
||||
s.dnsExtraRecords = views.SliceOf(dns.ExtraRecords)
|
||||
s.certDomains = views.SliceOf(dns.CertDomains)
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s netmapState) updateFromStatus(st *ipnstate.Status) netmapState {
|
||||
s.certDomains = views.SliceOf(st.CertDomains)
|
||||
s.dnsExtraRecords = views.SliceOf(st.ExtraRecords)
|
||||
@@ -703,7 +721,7 @@ runLoop:
|
||||
case err := <-cfgWatchErrChan:
|
||||
return fmt.Errorf("failed to watch tailscaled config: %w", err)
|
||||
case n := <-notifyChan:
|
||||
nmState = nmState.updateFromNotify(n)
|
||||
nmState = nmState.processNotify(ctx, client, n)
|
||||
if state, ok := notifyState(n); ok && state != ipn.Running {
|
||||
// Something's gone wrong and we've left the authenticated state.
|
||||
// Our container image never recovered gracefully from this, and the
|
||||
|
||||
Reference in New Issue
Block a user