Cleanup k8s states after upgrade

This commit is contained in:
2026-04-15 04:53:28 +08:00
parent 9225857db6
commit f1a7074528
4 changed files with 46 additions and 2 deletions

View File

@@ -326,6 +326,8 @@ func markProgressCompleted(
cur.Status.Phase = monov1alpha1.OSUpgradeProgressPhaseCompleted
cur.Status.Message = message
cur.Status.CurrentVersion = osup.Status.CurrentVersion
cur.Status.TargetVersion = osup.Status.TargetVersion
cur.Status.LastUpdatedAt = &now
cur.Status.CompletedAt = &now
})

View File

@@ -29,6 +29,31 @@ func ReleaseControlGate(ctx context.Context, nctx *NodeContext) error {
return fmt.Errorf("relate control gate: %w", err)
}
return WriteLastState(ctx, nctx)
}
// Required for detecting bootslot changes
func WriteLastState(ctx context.Context, nctx *NodeContext) error {
stBootPart := filepath.Join(monov1alpha1.EnvConfigDir, ".bootpart")
state, err := osimage.ReadBootState()
if err != nil {
return fmt.Errorf("read boot state: %w", err)
}
bootPart := state["BOOT_PART"]
if bootPart == "" {
return fmt.Errorf("BOOT_PART missing")
}
tmp := stBootPart + ".tmp"
if err := os.WriteFile(tmp, []byte(bootPart+"\n"), 0o644); err != nil {
return err
}
if err := os.Rename(tmp, stBootPart); err != nil {
return err
}
return nil
}