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

@@ -0,0 +1,49 @@
package node
import (
"context"
"errors"
"fmt"
"strings"
"time"
"k8s.io/klog/v2"
system "example.com/monok8s/pkg/system"
)
func RunKubeadmUpgradeApply(ctx context.Context, nctx *NodeContext) error {
if nctx.BootstrapState == nil {
return errors.New("BootstrapState is nil. Please run earlier steps first")
}
if nctx.BootstrapState.Action != BootstrapActionUpgradeControlPlane {
klog.V(4).Infof("skipped for %s", nctx.BootstrapState.Action)
return nil
}
if strings.TrimSpace(tmpKubeadmInitConf) == "" {
return fmt.Errorf("tmp kubeadm config path is empty")
}
_, err := nctx.SystemRunner.RunWithOptions(
ctx,
"kubeadm",
[]string{"upgrade", "apply", "-y", nctx.Config.Spec.KubernetesVersion},
system.RunOptions{
Timeout: 15 * time.Minute,
OnStdoutLine: func(line string) {
klog.Infof("[kubeadm] %s", line)
},
OnStderrLine: func(line string) {
klog.Infof("[kubeadm] %s", line)
},
},
)
if err != nil {
return fmt.Errorf("run kubeadm upgrade apply: %w", err)
}
return nil
}