Skip to content

Commit d472988

Browse files
committed
incus-osd/systemd: Add option to delay provider refresh when bringing up the network
Signed-off-by: Mathias Gibbens <mathias.gibbens@futurfusion.io>
1 parent 53cdc65 commit d472988

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

incus-osd/cmd/incus-osd/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,19 @@ func startup(ctx context.Context, s *state.State, t *tui.TUI) error { //nolint:r
349349
return err
350350
}
351351

352+
// Sometimes the system may not be able to immediately check the provider for any updates.
353+
// One such example is when Operations Center is installed and the underlying IncusOS system
354+
// is registered to it as the provider. We need to wait until the Operations Center
355+
// application has started, otherwise any update check will fail.
356+
delayInitialUpdateCheck, err := checkDelayInitialUpdate(ctx, s)
357+
if err != nil {
358+
return err
359+
}
360+
352361
// Perform network configuration.
353362
slog.InfoContext(ctx, "Bringing up the network")
354363

355-
err = systemd.ApplyNetworkConfiguration(ctx, s, s.System.Network.Config, 30*time.Second, s.OS.SuccessfulBoot, providers.Refresh)
364+
err = systemd.ApplyNetworkConfiguration(ctx, s, s.System.Network.Config, 30*time.Second, s.OS.SuccessfulBoot, providers.Refresh, delayInitialUpdateCheck)
356365
if err != nil {
357366
return err
358367
}
@@ -397,15 +406,6 @@ func startup(ctx context.Context, s *state.State, t *tui.TUI) error { //nolint:r
397406
return err
398407
}
399408

400-
// Sometimes the system may not be able to immediately check the provider for any updates.
401-
// One such example is when Operations Center is installed and the underlying IncusOS system
402-
// is registered to it as the provider. We need to wait until the Operations Center
403-
// application has started, otherwise any update check will fail.
404-
delayInitialUpdateCheck, err := checkDelayInitialUpdate(ctx, s)
405-
if err != nil {
406-
return err
407-
}
408-
409409
if !delayInitialUpdateCheck {
410410
// Perform an initial blocking check for updates before proceeding.
411411
updateChecker(ctx, s, t, p, true, false)

incus-osd/internal/rest/api_system_network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (s *Server) apiSystemNetwork(w http.ResponseWriter, r *http.Request) {
124124

125125
slog.InfoContext(r.Context(), "Applying new network configuration")
126126

127-
err = systemd.ApplyNetworkConfiguration(r.Context(), s.state, newConfig.Config, 30*time.Second, false, providers.Refresh)
127+
err = systemd.ApplyNetworkConfiguration(r.Context(), s.state, newConfig.Config, 30*time.Second, false, providers.Refresh, false)
128128
if err != nil {
129129
slog.ErrorContext(r.Context(), "Failed to update network configuration: "+err.Error())
130130
_ = response.InternalError(err).Render(w)

incus-osd/internal/systemd/networkd.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type networkdConfigFile struct {
3030
}
3131

3232
// ApplyNetworkConfiguration instructs systemd-networkd to apply the supplied network configuration.
33-
func ApplyNetworkConfiguration(ctx context.Context, s *state.State, networkCfg *api.SystemNetworkConfig, timeout time.Duration, allowPartialConfig bool, refresh func(context.Context, *state.State) error) error {
33+
func ApplyNetworkConfiguration(ctx context.Context, s *state.State, networkCfg *api.SystemNetworkConfig, timeout time.Duration, allowPartialConfig bool, refresh func(context.Context, *state.State) error, delayRefreshCheck bool) error {
3434
// If a timezone is specified, apply it before doing any network configuration.
3535
if networkCfg.Time != nil && networkCfg.Time.Timezone != "" {
3636
_, err := subprocess.RunCommandContext(ctx, "timedatectl", "set-timezone", networkCfg.Time.Timezone)
@@ -136,12 +136,19 @@ func ApplyNetworkConfiguration(ctx context.Context, s *state.State, networkCfg *
136136
return err
137137
}
138138

139-
// Refresh registration.
139+
// Refresh registration, delaying by 30 seconds if needed to allow the provider to become available,
140+
// such as when IncusOS is self-hosting Operations Center.
140141
if refresh != nil {
141-
err := refresh(ctx, s)
142-
if err != nil {
143-
slog.WarnContext(ctx, "Failed to refresh provider registration", "err", err)
144-
}
142+
go func() {
143+
if delayRefreshCheck {
144+
time.Sleep(30 * time.Second)
145+
}
146+
147+
err := refresh(ctx, s)
148+
if err != nil {
149+
slog.WarnContext(ctx, "Failed to refresh provider registration", "err", err)
150+
}
151+
}()
145152
}
146153

147154
return nil

0 commit comments

Comments
 (0)