Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions incus-osd/cmd/incus-osd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,19 @@ func startup(ctx context.Context, s *state.State, t *tui.TUI) error { //nolint:r
return err
}

// Sometimes the system may not be able to immediately check the provider for any updates.
// One such example is when Operations Center is installed and the underlying IncusOS system
// is registered to it as the provider. We need to wait until the Operations Center
// application has started, otherwise any update check will fail.
delayInitialUpdateCheck, err := checkDelayInitialUpdate(ctx, s)
if err != nil {
return err
}

// Perform network configuration.
slog.InfoContext(ctx, "Bringing up the network")

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

// Sometimes the system may not be able to immediately check the provider for any updates.
// One such example is when Operations Center is installed and the underlying IncusOS system
// is registered to it as the provider. We need to wait until the Operations Center
// application has started, otherwise any update check will fail.
delayInitialUpdateCheck, err := checkDelayInitialUpdate(ctx, s)
if err != nil {
return err
}

if !delayInitialUpdateCheck {
// Perform an initial blocking check for updates before proceeding.
updateChecker(ctx, s, t, p, true, false)
Expand Down
2 changes: 1 addition & 1 deletion incus-osd/internal/rest/api_system_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *Server) apiSystemNetwork(w http.ResponseWriter, r *http.Request) {

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

err = systemd.ApplyNetworkConfiguration(r.Context(), s.state, newConfig.Config, 30*time.Second, false, providers.Refresh)
err = systemd.ApplyNetworkConfiguration(r.Context(), s.state, newConfig.Config, 30*time.Second, false, providers.Refresh, false)
if err != nil {
slog.ErrorContext(r.Context(), "Failed to update network configuration: "+err.Error())
_ = response.InternalError(err).Render(w)
Expand Down
19 changes: 13 additions & 6 deletions incus-osd/internal/systemd/networkd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type networkdConfigFile struct {
}

// ApplyNetworkConfiguration instructs systemd-networkd to apply the supplied network configuration.
func ApplyNetworkConfiguration(ctx context.Context, s *state.State, networkCfg *api.SystemNetworkConfig, timeout time.Duration, allowPartialConfig bool, refresh func(context.Context, *state.State) error) error {
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 {
// If a timezone is specified, apply it before doing any network configuration.
if networkCfg.Time != nil && networkCfg.Time.Timezone != "" {
_, err := subprocess.RunCommandContext(ctx, "timedatectl", "set-timezone", networkCfg.Time.Timezone)
Expand Down Expand Up @@ -136,12 +136,19 @@ func ApplyNetworkConfiguration(ctx context.Context, s *state.State, networkCfg *
return err
}

// Refresh registration.
// Refresh registration, delaying by 30 seconds if needed to allow the provider to become available,
// such as when IncusOS is self-hosting Operations Center.
if refresh != nil {
err := refresh(ctx, s)
if err != nil {
slog.WarnContext(ctx, "Failed to refresh provider registration", "err", err)
}
go func() {
if delayRefreshCheck {
time.Sleep(30 * time.Second)
}

err := refresh(ctx, s)
if err != nil {
slog.WarnContext(ctx, "Failed to refresh provider registration", "err", err)
}
}()
}

return nil
Expand Down
Loading