Skip to content

Commit

Permalink
fix: upgrade stuck if TLS added (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdand-weka authored Feb 1, 2024
1 parent cc0bee1 commit 5cb6d1c
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions internal/local/k3s/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,36 @@ func Upgrade(ctx context.Context, c Config) (retErr error) {
}
logger.Warn().Err(err).Msg("Backing up old K3S failed, doing upgrade anyway...")
}
defer func() {
if retErr != nil && len(backupFiles) > 0 && !c.Debug {
retErr = errors.Join(retErr, restore(backupFiles))
}
if err := serviceCmd("start").Run(); err != nil {
retErr = errors.Join(retErr, fmt.Errorf("start K3S service: %w", err))
}
}()

logger.Info().Msg("Copying new k3s image...")
err = bundle.Tar(file).GetFiles(ctx, copyK3S(), copyAirgapImages(), runInstallScript(c))
if err != nil {
// restoring backup
if len(backupFiles) > 0 && !c.Debug {
err = errors.Join(err, restore(backupFiles))
if startErr := serviceCmd("start").Run(); err != nil {
err = errors.Join(err, fmt.Errorf("start K3S service: %w", startErr))
}
}

if errors.Is(err, context.Canceled) {
logger.Warn().Msg("Upgrade was cancelled")
return err
}
return fmt.Errorf("read bundle: %w", err)

return err
}

if err := serviceCmd("start").Run(); err != nil {
return fmt.Errorf("start K3S service: %w", err)
}

err = setupTLS(ctx, c.Configuration)
if err != nil && !errors.Is(err, ErrNoTLS) {
return err
}

logger.Info().Msg("Upgrade completed")
logger.Info().Msg("K3S upgrade completed")

return nil
}

0 comments on commit 5cb6d1c

Please sign in to comment.