Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sclevine committed Feb 6, 2025
1 parent e10884f commit 2a15809
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
37 changes: 19 additions & 18 deletions lib/autoupdate/agent/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func NewLocalUpdater(cfg LocalUpdaterConfig, ns *Namespace) (*Updater, error) {
Ready: debugClient,
Log: cfg.Log,
},
ExecSetup: func(ctx context.Context, restart bool) error {
ReexecSetup: func(ctx context.Context, reload bool) error {
name := ns.updaterBinFile
if cfg.SelfSetup && runtime.GOOS == constants.LinuxOS {
name = "/proc/self/exe"
Expand All @@ -138,8 +138,8 @@ func NewLocalUpdater(cfg LocalUpdaterConfig, ns *Namespace) (*Updater, error) {
args = append(args, "--debug")
}
args = append(args, "setup")
if restart {
args = append(args, "--restart")
if reload {
args = append(args, "--reload")
}
cmd := exec.CommandContext(ctx, name, args...)
cmd.Stderr = os.Stderr
Expand All @@ -148,8 +148,8 @@ func NewLocalUpdater(cfg LocalUpdaterConfig, ns *Namespace) (*Updater, error) {
defer cfg.Log.InfoContext(ctx, "Finished executing new teleport-update binary.")
return trace.Wrap(cmd.Run())
},
SetupConfig: ns.Setup,
TeardownConfig: ns.Teardown,
SetupNamespace: ns.Setup,
TeardownNamespace: ns.Teardown,
}, nil
}

Expand Down Expand Up @@ -187,12 +187,13 @@ type Updater struct {
Installer Installer
// Process manages a running instance of Teleport.
Process Process
// ExecSetup execs teleport-update to verify and reload the installation.
ExecSetup func(ctx context.Context, restart bool) error
// SetupConfig installs the Teleport updater service using the running installation.
SetupConfig func(ctx context.Context) error
// TeardownConfig removes all traces of the updater and all managed installations.
TeardownConfig func(ctx context.Context) error
// ReexecSetup re-execs teleport-update with the setup command.
// This configures the updater service, verifies the installation, and optionally reloads Teleport.
ReexecSetup func(ctx context.Context, reload bool) error
// SetupNamespace configures the Teleport updater service for the current Namespace.
SetupNamespace func(ctx context.Context) error
// TeardownNamespace removes all traces of the updater service in the current Namespace, including Teleport.
TeardownNamespace func(ctx context.Context) error
}

// Installer provides an API for installing Teleport agents.
Expand Down Expand Up @@ -371,7 +372,7 @@ func (u *Updater) Remove(ctx context.Context) error {
active := cfg.Status.Active
if active.Version == "" {
u.Log.InfoContext(ctx, "No installation of Teleport managed by the updater. Removing updater configuration.")
if err := u.TeardownConfig(ctx); err != nil {
if err := u.TeardownNamespace(ctx); err != nil {
return trace.Wrap(err)
}
u.Log.InfoContext(ctx, "Automatic update configuration for Teleport successfully uninstalled.")
Expand All @@ -392,7 +393,7 @@ func (u *Updater) Remove(ctx context.Context) error {
return trace.Wrap(err)
}
u.Log.InfoContext(ctx, "Teleport uninstalled.", "version", active)
if err := u.TeardownConfig(ctx); err != nil {
if err := u.TeardownNamespace(ctx); err != nil {
return trace.Wrap(err)
}
u.Log.InfoContext(ctx, "Automatic update configuration for Teleport successfully uninstalled.")
Expand Down Expand Up @@ -456,7 +457,7 @@ func (u *Updater) Remove(ctx context.Context) error {
return trace.Wrap(err, "failed to start system package version of Teleport")
}
u.Log.InfoContext(ctx, "Auto-updating Teleport removed and replaced by Teleport packaged.", "version", active)
if err := u.TeardownConfig(ctx); err != nil {
if err := u.TeardownNamespace(ctx); err != nil {
return trace.Wrap(err)
}
u.Log.InfoContext(ctx, "Auto-update configuration for Teleport successfully uninstalled.")
Expand Down Expand Up @@ -733,15 +734,15 @@ func (u *Updater) update(ctx context.Context, cfg *UpdateConfig, target Revision
u.Log.ErrorContext(ctx, "Failed to revert Teleport symlinks. Installation likely broken.")
return false
}
if err := u.SetupConfig(ctx); err != nil {
if err := u.SetupNamespace(ctx); err != nil {
u.Log.ErrorContext(ctx, "Failed to revert configuration after failed restart.", errorKey, err)
return false
}
return true
}

if cfg.Status.Active != target {
err := u.ExecSetup(ctx, true)
err := u.ReexecSetup(ctx, true)
if errors.Is(err, context.Canceled) {
return trace.Errorf("check canceled")
}
Expand All @@ -764,7 +765,7 @@ func (u *Updater) update(ctx context.Context, cfg *UpdateConfig, target Revision
}
cfg.Status.Active = target
} else {
err := u.ExecSetup(ctx, false)
err := u.ReexecSetup(ctx, false)
if errors.Is(err, context.Canceled) {
return trace.Errorf("check canceled")
}
Expand Down Expand Up @@ -793,7 +794,7 @@ func (u *Updater) update(ctx context.Context, cfg *UpdateConfig, target Revision
func (u *Updater) Setup(ctx context.Context, restart bool) error {
// Setup teleport-updater configuration and sync systemd.

err := u.SetupConfig(ctx)
err := u.SetupNamespace(ctx)
if errors.Is(err, context.Canceled) {
return trace.Errorf("sync canceled")
}
Expand Down
12 changes: 6 additions & 6 deletions lib/autoupdate/agent/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,12 @@ func TestUpdater_Update(t *testing.T) {
},
}
var restarted bool
updater.ExecSetup = func(_ context.Context, restart bool) error {
updater.ReexecSetup = func(_ context.Context, restart bool) error {
restarted = restart
setupCalls++
return tt.setupErr
}
updater.SetupConfig = func(_ context.Context) error {
updater.SetupNamespace = func(_ context.Context) error {
revertSetupCalls++
return nil
}
Expand Down Expand Up @@ -1117,7 +1117,7 @@ func TestUpdater_Remove(t *testing.T) {
return false, nil
},
}
updater.TeardownConfig = func(_ context.Context) error {
updater.TeardownNamespace = func(_ context.Context) error {
teardownCalls++
return nil
}
Expand Down Expand Up @@ -1504,12 +1504,12 @@ func TestUpdater_Install(t *testing.T) {
},
}
var restarted bool
updater.ExecSetup = func(_ context.Context, restart bool) error {
updater.ReexecSetup = func(_ context.Context, restart bool) error {
setupCalls++
restarted = restart
return tt.setupErr
}
updater.SetupConfig = func(_ context.Context) error {
updater.SetupNamespace = func(_ context.Context) error {
revertSetupCalls++
return nil
}
Expand Down Expand Up @@ -1646,7 +1646,7 @@ func TestUpdater_Setup(t *testing.T) {
return tt.present, tt.presentErr
},
}
updater.SetupConfig = func(_ context.Context) error {
updater.SetupNamespace = func(_ context.Context) error {
return tt.setupErr
}

Expand Down
10 changes: 5 additions & 5 deletions tool/teleport-update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ type cliConfig struct {
SelfSetup bool
// UpdateNow forces an immediate update.
UpdateNow bool
// Restart forces Teleport to restart
Restart bool
// Reload reloads Teleport.
Reload bool
}

func Run(args []string) int {
Expand Down Expand Up @@ -151,8 +151,8 @@ func Run(args []string) int {

setupCmd := app.Command("setup", "Write configuration files that run the update subcommand on a timer and verify the Teleport installation.").
Hidden()
setupCmd.Flag("restart", "Restart the Teleport agent.").
Short('r').BoolVar(&ccfg.Restart)
setupCmd.Flag("reload", "Reload the Teleport agent. If not set, Teleport is not reloaded or restarted.").
Short('r').BoolVar(&ccfg.Reload)

statusCmd := app.Command("status", "Show Teleport agent auto-update status.")

Expand Down Expand Up @@ -432,7 +432,7 @@ func cmdSetup(ctx context.Context, ccfg *cliConfig) error {
if err != nil {
return trace.Wrap(err)
}
err = updater.Setup(ctx, ccfg.Restart)
err = updater.Setup(ctx, ccfg.Reload)
if err != nil {
return trace.Wrap(err)
}
Expand Down

0 comments on commit 2a15809

Please sign in to comment.