Skip to content

Commit 9a38448

Browse files
sclevinegithub-actions
authored and
github-actions
committed
Use dedicated error for version incompat
1 parent f532741 commit 9a38448

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

lib/autoupdate/agent/process.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (s SystemdService) IsEnabled(ctx context.Context) (bool, error) {
415415
return false, trace.Wrap(err)
416416
}
417417
if hasSystemDBelow(ctx, 238) {
418-
return false, trace.Wrap(ErrNotSupported)
418+
return false, trace.Wrap(ErrNotAvailable)
419419
}
420420
code := s.systemctl(ctx, slog.LevelDebug, "is-enabled", "--quiet", s.ServiceName)
421421
switch {
@@ -448,7 +448,7 @@ func (s SystemdService) IsPresent(ctx context.Context) (bool, error) {
448448
return false, trace.Wrap(err)
449449
}
450450
if hasSystemDBelow(ctx, 246) {
451-
return false, trace.Wrap(ErrNotSupported)
451+
return false, trace.Wrap(ErrNotAvailable)
452452
}
453453
code := s.systemctl(ctx, slog.LevelDebug, "list-unit-files", "--quiet", s.ServiceName)
454454
if code < 0 {

lib/autoupdate/agent/setup.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (ns *Namespace) Setup(ctx context.Context, path string) error {
234234
// If the old teleport-upgrade script is detected, disable it to ensure they do not interfere.
235235
// Note that the schedule is also set to nop by the Teleport agent -- this just prevents restarts.
236236
present, err := oldTimer.IsPresent(ctx)
237-
if errors.Is(err, ErrNotSupported) { // systemd too old
237+
if errors.Is(err, ErrNotAvailable) { // systemd too old
238238
if err := oldTimer.Disable(ctx, true); err != nil {
239239
ns.log.DebugContext(ctx, "The deprecated teleport-ent-updater package is either missing, or could not be disabled.", errorKey, err)
240240
}
@@ -294,7 +294,7 @@ func (ns *Namespace) Teardown(ctx context.Context) error {
294294
}
295295
// If the old upgrader exists, attempt to re-enable it automatically
296296
present, err := oldTimer.IsPresent(ctx)
297-
if errors.Is(err, ErrNotSupported) { // systemd too old
297+
if errors.Is(err, ErrNotAvailable) { // systemd too old
298298
if err := oldTimer.Enable(ctx, true); err != nil {
299299
ns.log.DebugContext(ctx, "The deprecated teleport-ent-updater package is either missing, or could not be enabled.", errorKey, err)
300300
}

lib/autoupdate/agent/updater.go

+10-14
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,10 @@ func NewLocalUpdater(cfg LocalUpdaterConfig, ns *Namespace) (*Updater, error) {
114114
}
115115
validator := Validator{Log: cfg.Log}
116116
debugClient := debug.NewClient(filepath.Join(ns.dataDir, debugSocketFileName))
117-
ok, err := hasSystemD()
118-
systemdUnavailable := err == nil && !ok
119117
return &Updater{
120118
Log: cfg.Log,
121119
Pool: certPool,
122120
InsecureSkipVerify: cfg.InsecureSkipVerify,
123-
SystemDUnavailable: systemdUnavailable,
124121
UpdateConfigFile: filepath.Join(ns.Dir(), updateConfigName),
125122
TeleportConfigFile: ns.configFile,
126123
DefaultProxyAddr: ns.defaultProxyAddr,
@@ -203,8 +200,6 @@ type Updater struct {
203200
Pool *x509.CertPool
204201
// InsecureSkipVerify skips TLS verification.
205202
InsecureSkipVerify bool
206-
// SystemDUnavailable is true if SystemD is not available.
207-
SystemDUnavailable bool
208203
// UpdateConfigFile contains the path to the agent auto-updates configuration.
209204
UpdateConfigFile string
210205
// TeleportConfigFile contains the path to Teleport's configuration.
@@ -273,6 +268,8 @@ var (
273268
ErrNotNeeded = errors.New("not needed")
274269
// ErrNotSupported is returned when the operation is not supported on the platform.
275270
ErrNotSupported = errors.New("not supported on this platform")
271+
// ErrNotAvailable is returned when the operation is not available at the current version of the platform.
272+
ErrNotAvailable = errors.New("not available at this version")
276273
// ErrNoBinaries is returned when no binaries are available to be linked.
277274
ErrNoBinaries = errors.New("no binaries available to link")
278275
// ErrFilePresent is returned when a file is present.
@@ -892,16 +889,15 @@ func (u *Updater) Setup(ctx context.Context, path string, restart bool) error {
892889
return trace.Wrap(err, "failed to setup updater")
893890
}
894891

895-
if u.SystemDUnavailable {
896-
u.Log.WarnContext(ctx, "Skipping all systemd setup because systemd is not running.")
897-
return nil
898-
}
899-
900892
present, err := u.Process.IsPresent(ctx)
901893
if errors.Is(err, context.Canceled) {
902894
return trace.Errorf("config check canceled")
903895
}
904896
if errors.Is(err, ErrNotSupported) {
897+
u.Log.WarnContext(ctx, "Skipping all systemd setup because systemd is not running.")
898+
return nil
899+
}
900+
if errors.Is(err, ErrNotAvailable) {
905901
u.Log.DebugContext(ctx, "Systemd version is outdated. Skipping SELinux verification.")
906902
} else if err != nil {
907903
return trace.Wrap(err, "failed to determine if new version of Teleport has an installed systemd service")
@@ -926,13 +922,13 @@ func (u *Updater) Setup(ctx context.Context, path string, restart bool) error {
926922

927923
// notices displays final notices after install or update.
928924
func (u *Updater) notices(ctx context.Context) error {
929-
if u.SystemDUnavailable {
925+
enabled, err := u.Process.IsEnabled(ctx)
926+
if errors.Is(err, ErrNotSupported) {
930927
u.Log.WarnContext(ctx, "Teleport is installed, but systemd is not present to start it.")
931928
u.Log.WarnContext(ctx, "After configuring teleport.yaml, your system must also be configured to start Teleport.")
932929
return nil
933930
}
934-
enabled, err := u.Process.IsEnabled(ctx)
935-
if errors.Is(err, ErrNotSupported) {
931+
if errors.Is(err, ErrNotAvailable) {
936932
u.Log.WarnContext(ctx, "Remember to use systemctl to enable and start Teleport.")
937933
return nil
938934
}
@@ -1027,7 +1023,7 @@ func (u *Updater) LinkPackage(ctx context.Context) error {
10271023
return trace.Wrap(err, "failed to sync systemd configuration")
10281024
} else {
10291025
present, err := u.Process.IsPresent(ctx)
1030-
if errors.Is(err, ErrNotSupported) {
1026+
if errors.Is(err, ErrNotAvailable) {
10311027
u.Log.DebugContext(ctx, "Systemd version is outdated. Skipping SELinux verification.")
10321028
} else if err != nil {
10331029
return trace.Wrap(err, "failed to determine if Teleport has an installed systemd service")

lib/autoupdate/agent/updater_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,6 @@ func TestUpdater_Setup(t *testing.T) {
18931893
ns := &Namespace{}
18941894
updater, err := NewLocalUpdater(LocalUpdaterConfig{}, ns)
18951895
require.NoError(t, err)
1896-
updater.SystemDUnavailable = false
18971896

18981897
updater.Process = &testProcess{
18991898
FuncReload: func(_ context.Context) error {

0 commit comments

Comments
 (0)