Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maintenance window agent export logic #23062

Merged
merged 3 commits into from Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion e
Submodule e updated from 62efbb to e1cda9
43 changes: 43 additions & 0 deletions lib/service/service.go
Expand Up @@ -124,6 +124,7 @@ import (
usagereporter "github.com/gravitational/teleport/lib/usagereporter/teleport"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/utils/cert"
uw "github.com/gravitational/teleport/lib/versioncontrol/upgradewindow"
"github.com/gravitational/teleport/lib/web"
)

Expand Down Expand Up @@ -962,6 +963,34 @@ func NewTeleport(cfg *servicecfg.Config) (*TeleportProcess, error) {
}
})

// if an external upgrader is defined, we need to set up an appropriate upgrade window exporter.
if upgraderKind := os.Getenv("TELEPORT_EXT_UPGRADER"); upgraderKind != "" {
if process.Config.Auth.Enabled || process.Config.Proxy.Enabled {
process.log.Warnf("Use of external upgraders on control-plane instances is not recommended.")
}

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)
}

process.RegisterCriticalFunc("upgradeewindow.export", exporter.Run)
process.OnExit("upgradewindow.export.stop", func(_ interface{}) {
exporter.Close()
})

process.log.Infof("Configured upgrade window exporter for external upgrader. kind=%s", upgraderKind)
}

serviceStarted := false

if !cfg.DiagnosticAddr.IsEmpty() {
Expand Down Expand Up @@ -1228,6 +1257,20 @@ func (process *TeleportProcess) makeInventoryControlStream(ctx context.Context)
return clt.InventoryControlStream(ctx)
}

// exportUpgradeWindow is a helper for calling ExportUpgradeWindows either on the local in-memory auth server, or via the instance client, depending on
// which is available.
func (process *TeleportProcess) exportUpgradeWindows(ctx context.Context, req proto.ExportUpgradeWindowsRequest) (proto.ExportUpgradeWindowsResponse, error) {
if auth := process.getLocalAuth(); auth != nil {
return auth.ExportUpgradeWindows(ctx, req)
}

clt := process.getInstanceClient()
if clt == nil {
return proto.ExportUpgradeWindowsResponse{}, trace.Errorf("instance client not yet initialized")
}
return clt.ExportUpgradeWindows(ctx, req)
}

// adminCreds returns admin UID and GID settings based on the OS
func adminCreds() (*int, *int, error) {
if runtime.GOOS != constants.LinuxOS {
Expand Down