Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sclevine committed Dec 16, 2024
1 parent 7a590f9 commit e46c6f2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
6 changes: 5 additions & 1 deletion api/types/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/autoupdate/agent/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
42 changes: 22 additions & 20 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e46c6f2

Please sign in to comment.