Initial upgrade flow for control-plane

This commit is contained in:
2026-04-06 23:49:39 +08:00
parent c6f89651ce
commit 578b3e6a6f
19 changed files with 563 additions and 42 deletions

View File

@@ -1,5 +1,20 @@
package osimage
import (
"fmt"
"os"
"strings"
"sync"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
)
var (
bootStateOnce sync.Once
bootState map[string]string
bootStateErr error
)
func PercentOf(done, total int64) int64 {
if total <= 0 {
return 0
@@ -13,3 +28,34 @@ func PercentOf(done, total int64) int64 {
}
return p
}
func ReadBootState() (map[string]string, error) {
bootStateOnce.Do(func() {
data, err := os.ReadFile(monov1alpha1.BootStateFile)
if err != nil {
bootStateErr = err
return
}
out := make(map[string]string)
for _, line := range strings.Split(string(data), "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") {
continue
}
k, v, ok := strings.Cut(line, "=")
if !ok {
bootStateErr = fmt.Errorf("invalid line: %q", line)
return
}
out[strings.TrimSpace(k)] = strings.TrimSpace(v)
}
bootState = out
})
return bootState, bootStateErr
}

View File

@@ -111,7 +111,7 @@ func handleOSUpgradeLocked(ctx context.Context, clients *kube.Clients,
"resolvedTarget", plan.ResolvedTarget,
"steps", len(plan.Path),
"currentVersion", buildinfo.KubeVersion,
"fSHA256irstVersion", first.Version,
"firstVersion", first.Version,
"firstURL", first.URL,
"size", first.Size,
)
@@ -126,7 +126,7 @@ func handleOSUpgradeLocked(ctx context.Context, clients *kube.Clients,
imageOptions := osimage.ApplyOptions{
URL: first.URL,
TargetPath: "/dev/mksaltpart",
TargetPath: monov1alpha1.AltPartDeviceLink,
ExpectedRawSHA256: imageSHA,
ExpectedRawSize: first.Size,
BufferSize: 6 * 1024 * 1024,