diff --git a/tool/tctl/common/autoupdate_command.go b/tool/tctl/common/autoupdate_command.go index c9c0211e236ea..6ee5c60da8a0d 100644 --- a/tool/tctl/common/autoupdate_command.go +++ b/tool/tctl/common/autoupdate_command.go @@ -65,7 +65,7 @@ func (c *AutoupdateCommand) Initialize(app *kingpin.Application, config *service autoupdateCmd := app.Command("autoupdate", "Teleport autoupdate commands.") c.updateCmd = autoupdateCmd.Command("update", "Edit autoupdate configuration.") - c.updateCmd.Flag("set-tools-auto-update", `Enable or disable tools autoupdate in cluster.`).EnumVar(&c.toolsAutoupdate, "on", "off") + c.updateCmd.Flag("set-tools-autoupdate", `Enable or disable tools autoupdate in cluster.`).EnumVar(&c.toolsAutoupdate, "on", "off") c.updateCmd.Flag("set-tools-version", `Defines client tools version required to be force updated.`).StringVar(&c.toolsAutoupdateVersion) c.getCmd = autoupdateCmd.Command("get", "Receive tools autoupdate version.") @@ -155,33 +155,34 @@ func (c *AutoupdateCommand) Get(ctx context.Context, client *authclient.Client) func (c *AutoupdateCommand) Watch(ctx context.Context, client *authclient.Client) error { current := teleport.SemVersion ticker := interval.New(interval.Config{ - Duration: time.Minute, - FirstDuration: time.Second, + Duration: time.Minute, }) + defer ticker.Stop() for { + response, err := c.get(ctx, client) + if err != nil { + return trace.Wrap(err) + } + if response.ToolsVersion == "" { + continue + } + + semVersion, err := semver.NewVersion(response.ToolsVersion) + if err != nil { + return trace.Wrap(err) + } + if !semVersion.Equal(*current) { + if err := utils.WriteJSON(os.Stdout, response); err != nil { + return trace.Wrap(err) + } + current = semVersion + } + select { case <-ctx.Done(): return nil case <-ticker.Next(): - response, err := c.get(ctx, client) - if err != nil { - return trace.Wrap(err) - } - if response.ToolsVersion == "" { - continue - } - - semVersion, err := semver.NewVersion(response.ToolsVersion) - if err != nil { - return trace.Wrap(err) - } - if !semVersion.Equal(*current) { - if err := utils.WriteJSON(os.Stdout, response); err != nil { - return trace.Wrap(err) - } - current = semVersion - } } } }