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

@@ -2,6 +2,7 @@ package uboot
import (
"context"
"errors"
"fmt"
"strings"
"time"
@@ -11,6 +12,8 @@ import (
"example.com/monok8s/pkg/system"
)
var ErrEnvNotFound = errors.New("fw env not found")
func NewFWEnvWriter(configPath string, ctlPath string) *FWEnvWriter {
return &FWEnvWriter{
Runner: system.NewRunner(system.RunnerConfig{
@@ -38,8 +41,12 @@ func (w *FWEnvWriter) GetEnv(ctx context.Context, key string) (string, error) {
res, err := w.Runner.RunWithOptions(ctx, w.CtlPath, args, system.RunOptions{Quiet: true})
if err != nil {
if res != nil {
return "", fmt.Errorf("fw-printenv %q: %w (stdout=%q stderr=%q)",
key, err, strings.TrimSpace(res.Stdout), strings.TrimSpace(res.Stderr))
if strings.Contains(res.Stderr, "not defined") {
return "", ErrEnvNotFound
} else {
return "", fmt.Errorf("fw-printenv %q: %w (stdout=%q stderr=%q)",
key, err, strings.TrimSpace(res.Stdout), strings.TrimSpace(res.Stderr))
}
}
return "", fmt.Errorf("fw-printenv %q: %w", key, err)
}