From e46c6f278de624ffafda97c43357309a54755855 Mon Sep 17 00:00:00 2001 From: Stephen Levine Date: Sun, 15 Dec 2024 23:18:19 -0500 Subject: [PATCH] fix --- api/types/maintenance.go | 6 ++++- lib/auth/auth.go | 2 +- lib/autoupdate/agent/telemetry.go | 4 ++- lib/service/service.go | 42 ++++++++++++++++--------------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/api/types/maintenance.go b/api/types/maintenance.go index 65d2f7271c6fc..afef1c98188bb 100644 --- a/api/types/maintenance.go +++ b/api/types/maintenance.go @@ -26,13 +26,17 @@ import ( ) const ( - // UpgraderKindKuberController is a short name used to identify the kube-controller-based + // UpgraderKindKubeController is a short name used to identify the kube-controller-based // external upgrader variant. UpgraderKindKubeController = "kube" // UpgraderKindSystemdUnit is a short name used to identify the systemd-unit-based // external upgrader variant. UpgraderKindSystemdUnit = "unit" + + // UpgraderKindTeleportUpdate is a short name used to identify the teleport-update + // external upgrader variant. + UpgraderKindTeleportUpdate = "updater" ) var validWeekdays = [7]time.Weekday{ diff --git a/lib/auth/auth.go b/lib/auth/auth.go index befe2993f38d2..f283cb614a769 100644 --- a/lib/auth/auth.go +++ b/lib/auth/auth.go @@ -6564,7 +6564,7 @@ func (a *Server) ExportUpgradeWindows(ctx context.Context, req proto.ExportUpgra } switch req.UpgraderKind { - case "": + case "", types.UpgraderKindTeleportUpdate: rsp.CanonicalSchedule = cached.CanonicalSchedule.Clone() case types.UpgraderKindKubeController: rsp.KubeControllerSchedule = cached.KubeControllerSchedule diff --git a/lib/autoupdate/agent/telemetry.go b/lib/autoupdate/agent/telemetry.go index b671132c679ac..df321f6c791cf 100644 --- a/lib/autoupdate/agent/telemetry.go +++ b/lib/autoupdate/agent/telemetry.go @@ -26,7 +26,9 @@ import ( "github.com/gravitational/trace" ) -func IsEnabled() (bool, error) { +// IsActive returns true if the local Teleport binary is managed by teleport-update. +// Note that true may be returned even if auto-updates is disabled or the version is pinned. +func IsActive() (bool, error) { teleportPath, err := os.Readlink("/proc/self/exe") if err != nil { return false, trace.Wrap(err, "cannot find Teleport binary") diff --git a/lib/service/service.go b/lib/service/service.go index 583c120584366..b53d24dd61889 100644 --- a/lib/service/service.go +++ b/lib/service/service.go @@ -1233,8 +1233,8 @@ func NewTeleport(cfg *servicecfg.Config) (*TeleportProcess, error) { upgraderKind = "" } - // If the new auto-updater is enabled, it superceeds the old one. - ok, err := autoupdate.IsEnabled() + // If the installation is managed by teleport-update, it supersedes the teleport-upgrader script. + ok, err := autoupdate.IsActive() if err != nil { process.logger.WarnContext(process.ExitContext(), "Failed to determine if auto-updates are enabled.", "error", err) } else if ok { @@ -1282,7 +1282,7 @@ func NewTeleport(cfg *servicecfg.Config) (*TeleportProcess, error) { process.logger.WarnContext(process.ExitContext(), "Use of external upgraders on control-plane instances is not recommended.") } - if upgraderKind == "unit" { + if upgraderKind == types.UpgraderKindSystemdUnit { process.RegisterFunc("autoupdates.endpoint.export", func() error { conn, err := waitForInstanceConnector(process, process.logger) if err != nil { @@ -1312,26 +1312,28 @@ func NewTeleport(cfg *servicecfg.Config) (*TeleportProcess, error) { }) } - driver, err := uw.NewDriver(upgraderKind) - if err != nil { - return nil, trace.Wrap(err) - } + if upgraderKind != types.UpgraderKindTeleportUpdate { + driver, err := uw.NewDriver(upgraderKind) + if err != nil { + return nil, trace.Wrap(err) + } - exporter, err := uw.NewExporter(uw.ExporterConfig[inventory.DownstreamSender]{ - Driver: driver, - ExportFunc: process.exportUpgradeWindows, - AuthConnectivitySentinel: process.inventoryHandle.Sender(), - }) - if err != nil { - return nil, trace.Wrap(err) - } + exporter, err := uw.NewExporter(uw.ExporterConfig[inventory.DownstreamSender]{ + Driver: driver, + ExportFunc: process.exportUpgradeWindows, + AuthConnectivitySentinel: process.inventoryHandle.Sender(), + }) + if err != nil { + return nil, trace.Wrap(err) + } - process.RegisterCriticalFunc("upgradeewindow.export", exporter.Run) - process.OnExit("upgradewindow.export.stop", func(_ interface{}) { - exporter.Close() - }) + process.RegisterCriticalFunc("upgradeewindow.export", exporter.Run) + process.OnExit("upgradewindow.export.stop", func(_ interface{}) { + exporter.Close() + }) - process.logger.InfoContext(process.ExitContext(), "Configured upgrade window exporter for external upgrader.", "kind", upgraderKind) + process.logger.InfoContext(process.ExitContext(), "Configured upgrade window exporter for external upgrader.", "kind", upgraderKind) + } } serviceStarted := false