mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-06 20:56:24 +02:00
Add two narrow LocalAPI accessors so callers don't have to subscribe to
the IPN bus and pull a full *netmap.NetworkMap just to read DNS-shaped
fields:
- GET /localapi/v0/cert-domains returns DNS.CertDomains.
- GET /localapi/v0/dns-config returns the full tailcfg.DNSConfig.
Migrate in-tree callers off the netmap-on-the-bus pattern:
- kube/certs.waitForCertDomain still wakes on the IPN bus but now
queries CertDomains via LocalClient.CertDomains rather than
reading n.NetMap.DNS.CertDomains. The kube LocalClient interface
and FakeLocalClient gain a CertDomains method.
- cmd/tailscale dns status calls LocalClient.DNSConfig directly
instead of opening a NotifyInitialNetMap watcher.
- cmd/tailscale configure kubeconfig switches from a netmap watcher
+ serviceDNSRecordFromNetMap to LocalClient.DNSConfig +
serviceDNSRecordFromDNSConfig.
This is part of a series moving callers away from depending on the
netmap traveling on the IPN bus, so the bus payload can shrink in a
later change.
Updates #12542
Change-Id: Ie10204e141d085fbac183b4cfe497226b670ad6c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package localclient
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"tailscale.com/ipn"
|
|
)
|
|
|
|
type FakeLocalClient struct {
|
|
FakeIPNBusWatcher
|
|
SetServeCalled bool
|
|
EditPrefsCalls []*ipn.MaskedPrefs
|
|
GetPrefsResult *ipn.Prefs
|
|
CertDomainsResult []string
|
|
}
|
|
|
|
func (m *FakeLocalClient) SetServeConfig(ctx context.Context, cfg *ipn.ServeConfig) error {
|
|
m.SetServeCalled = true
|
|
return nil
|
|
}
|
|
|
|
func (m *FakeLocalClient) EditPrefs(ctx context.Context, mp *ipn.MaskedPrefs) (*ipn.Prefs, error) {
|
|
m.EditPrefsCalls = append(m.EditPrefsCalls, mp)
|
|
if m.GetPrefsResult == nil {
|
|
return &ipn.Prefs{}, nil
|
|
}
|
|
return m.GetPrefsResult, nil
|
|
}
|
|
|
|
func (m *FakeLocalClient) GetPrefs(ctx context.Context) (*ipn.Prefs, error) {
|
|
if m.GetPrefsResult == nil {
|
|
return &ipn.Prefs{}, nil
|
|
}
|
|
return m.GetPrefsResult, nil
|
|
}
|
|
|
|
func (f *FakeLocalClient) WatchIPNBus(ctx context.Context, mask ipn.NotifyWatchOpt) (IPNBusWatcher, error) {
|
|
return &f.FakeIPNBusWatcher, nil
|
|
}
|
|
|
|
func (f *FakeLocalClient) CertPair(ctx context.Context, domain string) ([]byte, []byte, error) {
|
|
return nil, nil, fmt.Errorf("CertPair not implemented")
|
|
}
|
|
|
|
func (f *FakeLocalClient) CertDomains(ctx context.Context) ([]string, error) {
|
|
return f.CertDomainsResult, nil
|
|
}
|
|
|
|
type FakeIPNBusWatcher struct {
|
|
NotifyChan chan ipn.Notify
|
|
}
|
|
|
|
func (f *FakeIPNBusWatcher) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (f *FakeIPNBusWatcher) Next() (ipn.Notify, error) {
|
|
return <-f.NotifyChan, nil
|
|
}
|