Skip to content

Commit

Permalink
Command flag naming adjustment
Browse files Browse the repository at this point in the history
Fix interval first duration
  • Loading branch information
vapopov committed Aug 22, 2024
1 parent 70b7c54 commit 0184ab6
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions tool/tctl/common/autoupdate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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
}
}
}
}
Expand Down

0 comments on commit 0184ab6

Please sign in to comment.