Can now reconcile
This commit is contained in:
@@ -2,6 +2,7 @@ package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
@@ -106,7 +107,85 @@ func ValidateNodeIPAndAPIServerReachability(ctx context.Context, nct *NodeContex
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckUpgradePrereqs(context.Context, *NodeContext) error {
|
||||
klog.Info("check_upgrade_prereqs: TODO implement kubeadm version / skew checks")
|
||||
func CheckForVersionSkew(ctx context.Context, nctx *NodeContext) error {
|
||||
if nctx.BootstrapState == nil {
|
||||
return errors.New("BootstrapState is nil, call ClassifyBootstrapAction() first")
|
||||
}
|
||||
|
||||
role := strings.TrimSpace(nctx.Config.Spec.ClusterRole)
|
||||
wantVersion := normalizeKubeVersion(strings.TrimSpace(nctx.Config.Spec.KubernetesVersion))
|
||||
if wantVersion == "" {
|
||||
return errors.New("spec.kubernetesVersion is required")
|
||||
}
|
||||
|
||||
switch nctx.LocalClusterState.MembershipKind {
|
||||
case LocalMembershipFresh:
|
||||
// Nothing to compare for fresh nodes.
|
||||
return nil
|
||||
case LocalMembershipPartial:
|
||||
return fmt.Errorf("cannot check version skew with partial local cluster state")
|
||||
}
|
||||
|
||||
versionKubeconfig := chooseVersionKubeconfig(nctx.LocalClusterState)
|
||||
if versionKubeconfig == "" {
|
||||
return fmt.Errorf("no kubeconfig available for version detection")
|
||||
}
|
||||
|
||||
currentVersion, err := getServerVersion(ctx, versionKubeconfig)
|
||||
if err != nil {
|
||||
if role == "control-plane" {
|
||||
return fmt.Errorf("existing control-plane state found, but cluster version could not be determined: %w", err)
|
||||
}
|
||||
|
||||
// Worker path stays permissive.
|
||||
nctx.BootstrapState.UnsupportedWorkerVersionSkew = true
|
||||
nctx.BootstrapState.VersionSkewReason = "cluster version could not be determined"
|
||||
|
||||
if nctx.BootstrapState.Action == BootstrapActionManageWorker {
|
||||
nctx.BootstrapState.Action = BootstrapActionReconcileWorker
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
nctx.BootstrapState.DetectedClusterVersion = currentVersion
|
||||
|
||||
switch role {
|
||||
case "control-plane":
|
||||
if !isSupportedControlPlaneSkew(currentVersion, wantVersion) {
|
||||
return fmt.Errorf(
|
||||
"unsupported control-plane version skew: cluster=%s node=%s",
|
||||
currentVersion, wantVersion,
|
||||
)
|
||||
}
|
||||
|
||||
if nctx.BootstrapState.Action == BootstrapActionManageControlPlane {
|
||||
if versionEq(currentVersion, wantVersion) {
|
||||
nctx.BootstrapState.Action = BootstrapActionReconcileControlPlane
|
||||
} else {
|
||||
nctx.BootstrapState.Action = BootstrapActionUpgradeControlPlane
|
||||
}
|
||||
}
|
||||
|
||||
case "worker":
|
||||
if !isSupportedWorkerSkew(currentVersion, wantVersion) {
|
||||
nctx.BootstrapState.UnsupportedWorkerVersionSkew = true
|
||||
nctx.BootstrapState.VersionSkewReason = fmt.Sprintf(
|
||||
"unsupported worker version skew: cluster=%s node=%s",
|
||||
currentVersion, wantVersion,
|
||||
)
|
||||
}
|
||||
|
||||
if nctx.BootstrapState.Action == BootstrapActionManageWorker {
|
||||
if versionEq(currentVersion, wantVersion) {
|
||||
nctx.BootstrapState.Action = BootstrapActionReconcileWorker
|
||||
} else {
|
||||
nctx.BootstrapState.Action = BootstrapActionUpgradeWorker
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unsupported cluster role %q", role)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user