client/local,types/netmap: modify services format in local api

Updates the format of the service map that is served over
the local api to be keyed without the "svc:" prefix. This
change is backwards incompatible, this is OK because there
is only one tailnet with the services-in-nodecapmap feature
flag enabled, and the client side changes that start showing
services over local api have not been released. (These were
added in 4fcce6000d).

Updates tailscale/corp#40052

Signed-off-by: Adriano Sela Aviles <adriano@tailscale.com>
This commit is contained in:
Adriano Sela Aviles
2026-04-17 12:23:13 -07:00
committed by Adriano Sela Aviles
parent 514d7d28e7
commit 618dfd4081
2 changed files with 11 additions and 9 deletions
+4 -3
View File
@@ -1424,11 +1424,12 @@ func (lc *Client) GetAppConnectorRouteInfo(ctx context.Context) (appctype.RouteI
} }
// GetServices returns the Services visible to this node, // GetServices returns the Services visible to this node,
// including their names, IP addresses, and ports, keyed by service name. // including their names, IP addresses, and ports, keyed by service name
func (lc *Client) GetServices(ctx context.Context) (map[tailcfg.ServiceName]tailcfg.ServiceDetails, error) { // without the "svc:" prefix.
func (lc *Client) GetServices(ctx context.Context) (map[string]tailcfg.ServiceDetails, error) {
body, err := lc.get200(ctx, "/localapi/v0/services") body, err := lc.get200(ctx, "/localapi/v0/services")
if err != nil { if err != nil {
return nil, err return nil, err
} }
return decodeJSON[map[tailcfg.ServiceName]tailcfg.ServiceDetails](body) return decodeJSON[map[string]tailcfg.ServiceDetails](body)
} }
+7 -6
View File
@@ -148,17 +148,16 @@ func (nm *NetworkMap) GetIPVIPServiceMap() IPServiceMappings {
// Services returns the Services visible (accessible) to this node, // Services returns the Services visible (accessible) to this node,
// decoded from [tailcfg.NodeAttrPrefixServices] entries in the self node's // decoded from [tailcfg.NodeAttrPrefixServices] entries in the self node's
// CapMap. The returned map is keyed by [tailcfg.ServiceDetails.Name], which is // CapMap. The returned map is keyed by service name without the "svc:" prefix.
// the canonical service name; the NodeCapMap key suffix is opaque and must not // It returns nil if nm is nil or SelfNode is invalid.
// be parsed or relied upon. It returns nil if nm is nil or SelfNode is invalid.
// //
// TODO(adrianosela): cache the result of decoding the capmap so // TODO(adrianosela): cache the result of decoding the capmap so
// we don't have to decode it multiple times after each netmap update. // we don't have to decode it multiple times after each netmap update.
func (nm *NetworkMap) Services() map[tailcfg.ServiceName]tailcfg.ServiceDetails { func (nm *NetworkMap) Services() map[string]tailcfg.ServiceDetails {
if nm == nil || !nm.SelfNode.Valid() { if nm == nil || !nm.SelfNode.Valid() {
return nil return nil
} }
result := make(map[tailcfg.ServiceName]tailcfg.ServiceDetails) result := make(map[string]tailcfg.ServiceDetails)
for cap := range nm.SelfNode.CapMap().All() { for cap := range nm.SelfNode.CapMap().All() {
if !strings.HasPrefix(string(cap), string(tailcfg.NodeAttrPrefixServices)) { if !strings.HasPrefix(string(cap), string(tailcfg.NodeAttrPrefixServices)) {
continue continue
@@ -167,7 +166,9 @@ func (nm *NetworkMap) Services() map[tailcfg.ServiceName]tailcfg.ServiceDetails
if err != nil || len(svcs) < 1 { if err != nil || len(svcs) < 1 {
continue continue
} }
result[svcs[0].Name] = svcs[0] // NOTE(adrianosela): the NodeCapMap key suffix is opaque and MUST not
// be parsed or relied upon (so we extract name from the inner field).
result[svcs[0].Name.WithoutPrefix()] = svcs[0]
} }
return result return result
} }