From 931282a1376d475516194c6aef12ba94c1f5c2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marti=CC=81n=20Go=CC=81mez?= Date: Fri, 30 Oct 2026 15:46:30 +0100 Subject: [PATCH] cli: add nodes update-client command --- cmd/headscale/cli/nodes.go | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 2b3a0c5f8..c787bdb79 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -2,6 +2,7 @@ package cli import ( "context" + "errors" "fmt" "net/http" "net/netip" @@ -10,6 +11,7 @@ import ( "time" clientv1 "github.com/juanfont/headscale/gen/client/v1" + clientv2 "github.com/juanfont/headscale/gen/client/v2" "github.com/juanfont/headscale/hscontrol/util" "github.com/pterm/pterm" "github.com/samber/lo" @@ -17,6 +19,8 @@ import ( "tailscale.com/types/key" ) +var errClientUpdateNotStarted = errors.New("node did not start the client update") + func init() { rootCmd.AddCommand(nodeCmd) listNodesCmd.Flags().StringP("user", "u", "", "Filter by user") @@ -55,6 +59,11 @@ func init() { nodeCmd.AddCommand(approveRoutesCmd) nodeCmd.AddCommand(backfillNodeIPsCmd) + + updateClientCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)") + updateClientCmd.Flags().Bool("force", false, "Update even if the node has active Tailscale SSH sessions") + mustMarkRequired(updateClientCmd, "identifier") + nodeCmd.AddCommand(updateClientCmd) } var nodeCmd = &cobra.Command{ @@ -258,6 +267,50 @@ var renameNodeCmd = &cobra.Command{ }), } +var updateClientCmd = &cobra.Command{ + Use: "update-client", + Short: "Update the Tailscale client of a connected node", + Long: `Ask a connected node to update its Tailscale client to the latest stable release. + +The node only starts the update if it has auto-updates enabled +("tailscale set --auto-update") and its platform supports them. +The command returns once the update has started, not when it has finished.`, + RunE: func(cmd *cobra.Command, _ []string) error { + identifier, _ := cmd.Flags().GetUint64("identifier") + force, _ := cmd.Flags().GetBool("force") + + ctx, client, cancel, err := newV2Client() + if err != nil { + return err + } + defer cancel() + + resp, err := client.UpdateDeviceClientWithResponse(ctx, strconv.FormatUint(identifier, util.Base10), clientv2.UpdateDeviceClientRequest{ + Force: &force, + }) + if err != nil { + return fmt.Errorf("updating node client: %w", err) + } + + err = v2Error(resp.HTTPResponse.StatusCode, resp.Body) + if err != nil { + return err + } + + update := resp.JSON200 + if !update.Started { + reason := update.Error + if reason == "" { + reason = fmt.Sprintf("enabled=%t, supported=%t", update.Enabled, update.Supported) + } + + return fmt.Errorf("%w: %s", errClientUpdateNotStarted, reason) + } + + return printOutput(cmd, update, "Client update started") + }, +} + var deleteNodeCmd = &cobra.Command{ Use: cmdDelete, Short: "Delete a node",