Refactor into RenderAgent and ApplyAgent
This commit is contained in:
@@ -257,3 +257,95 @@ func describeHealthCheckFailure(ctx context.Context, kubeClient kubernetes.Inter
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RunKubeadmUpgradeNode(ctx context.Context, nctx *NodeContext) error {
|
||||
if nctx == nil {
|
||||
return errors.New("node context is nil")
|
||||
}
|
||||
if nctx.Config == nil {
|
||||
return errors.New("node config is nil")
|
||||
}
|
||||
if nctx.LocalClusterState == nil {
|
||||
return errors.New("LocalClusterState is nil. Please run earlier steps first")
|
||||
}
|
||||
if nctx.BootstrapState == nil {
|
||||
return errors.New("BootstrapState is nil. Please run earlier steps first")
|
||||
}
|
||||
|
||||
switch nctx.BootstrapState.Action {
|
||||
case BootstrapActionUpgradeWorker:
|
||||
// continue
|
||||
default:
|
||||
klog.V(4).Infof("RunKubeadmUpgradeNode skipped for action %q", nctx.BootstrapState.Action)
|
||||
return nil
|
||||
}
|
||||
|
||||
wantVersion := normalizeKubeVersion(strings.TrimSpace(nctx.Config.Spec.KubernetesVersion))
|
||||
if wantVersion == "" {
|
||||
return errors.New("spec.kubernetesVersion is required")
|
||||
}
|
||||
|
||||
kubeconfigPath := chooseVersionKubeconfig(nctx.LocalClusterState)
|
||||
if kubeconfigPath == "" {
|
||||
return errors.New("no kubeconfig available for detecting cluster version")
|
||||
}
|
||||
|
||||
clusterVersion := strings.TrimSpace(nctx.BootstrapState.DetectedClusterVersion)
|
||||
if clusterVersion == "" {
|
||||
var err error
|
||||
clusterVersion, err = getServerVersion(ctx, kubeconfigPath)
|
||||
if err != nil {
|
||||
if nctx.BootstrapState.UnsupportedWorkerVersionSkew {
|
||||
klog.Warningf(
|
||||
"cluster version unavailable but worker skew was marked unsupported/permissive, continuing: reason=%s",
|
||||
nctx.BootstrapState.VersionSkewReason,
|
||||
)
|
||||
} else {
|
||||
return fmt.Errorf("get cluster version via %s: %w", kubeconfigPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if clusterVersion != "" && !isSupportedWorkerSkew(clusterVersion, wantVersion) {
|
||||
klog.Warningf(
|
||||
"unsupported worker version skew detected, continuing anyway: cluster=%s node=%s",
|
||||
clusterVersion,
|
||||
wantVersion,
|
||||
)
|
||||
}
|
||||
|
||||
klog.Infof(
|
||||
"running kubeadm upgrade node: role=%s clusterVersion=%s nodeVersion=%s kubeconfig=%s",
|
||||
strings.TrimSpace(nctx.Config.Spec.ClusterRole),
|
||||
clusterVersion,
|
||||
wantVersion,
|
||||
kubeconfigPath,
|
||||
)
|
||||
|
||||
args := []string{
|
||||
"upgrade",
|
||||
"node",
|
||||
"--kubeconfig",
|
||||
kubeconfigPath,
|
||||
}
|
||||
|
||||
_, err := nctx.SystemRunner.RunWithOptions(
|
||||
ctx,
|
||||
"kubeadm",
|
||||
args,
|
||||
system.RunOptions{
|
||||
Timeout: 10 * 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 node: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user