Can ctl init with index
This commit is contained in:
@@ -58,6 +58,7 @@ func DetectLocalClusterState(ctx context.Context, nctx *NodeContext) error {
|
||||
return fmt.Errorf("unreachable local cluster state")
|
||||
}
|
||||
|
||||
klog.V(4).Infof("Detected local state: %+v", state)
|
||||
nctx.LocalClusterState = &state
|
||||
return nil
|
||||
}
|
||||
@@ -164,6 +165,10 @@ func CheckForVersionSkew(ctx context.Context, nctx *NodeContext) error {
|
||||
func ClassifyBootstrapAction(ctx context.Context, nctx *NodeContext) error {
|
||||
_ = ctx
|
||||
|
||||
if nctx.LocalClusterState == nil {
|
||||
return errors.New("LocalClusterState is nil, call detect_local_cluster_state()")
|
||||
}
|
||||
|
||||
role := strings.TrimSpace(nctx.Config.Spec.ClusterRole)
|
||||
initControlPlane := nctx.Config.Spec.InitControlPlane
|
||||
wantVersion := normalizeKubeVersion(strings.TrimSpace(nctx.Config.Spec.KubernetesVersion))
|
||||
@@ -171,26 +176,27 @@ func ClassifyBootstrapAction(ctx context.Context, nctx *NodeContext) error {
|
||||
return errors.New("spec.kubernetesVersion is required")
|
||||
}
|
||||
|
||||
nctx.BootstrapState = &BootstrapState{}
|
||||
state := &BootstrapState{}
|
||||
|
||||
// Preserve already-detected info if earlier steps populated it.
|
||||
if nctx.BootstrapState != nil {
|
||||
state.DetectedClusterVersion = nctx.BootstrapState.DetectedClusterVersion
|
||||
}
|
||||
|
||||
switch role {
|
||||
case "worker":
|
||||
switch nctx.LocalClusterState.MembershipKind {
|
||||
case LocalMembershipFresh:
|
||||
nctx.BootstrapState.Action = BootstrapActionJoinWorker
|
||||
return nil
|
||||
state.Action = BootstrapActionJoinWorker
|
||||
|
||||
case LocalMembershipExistingWorker:
|
||||
if nctx.BootstrapState.DetectedClusterVersion == "" {
|
||||
nctx.BootstrapState.Action = BootstrapActionReconcileWorker
|
||||
return nil
|
||||
}
|
||||
|
||||
if versionEq(nctx.BootstrapState.DetectedClusterVersion, wantVersion) {
|
||||
nctx.BootstrapState.Action = BootstrapActionReconcileWorker
|
||||
if state.DetectedClusterVersion == "" {
|
||||
state.Action = BootstrapActionReconcileWorker
|
||||
} else if versionEq(state.DetectedClusterVersion, wantVersion) {
|
||||
state.Action = BootstrapActionReconcileWorker
|
||||
} else {
|
||||
nctx.BootstrapState.Action = BootstrapActionUpgradeWorker
|
||||
state.Action = BootstrapActionUpgradeWorker
|
||||
}
|
||||
return nil
|
||||
|
||||
case LocalMembershipExistingControlPlane, LocalMembershipPartial:
|
||||
return fmt.Errorf("local state %q is invalid for worker role", nctx.LocalClusterState.MembershipKind)
|
||||
@@ -203,23 +209,21 @@ func ClassifyBootstrapAction(ctx context.Context, nctx *NodeContext) error {
|
||||
switch nctx.LocalClusterState.MembershipKind {
|
||||
case LocalMembershipFresh:
|
||||
if initControlPlane {
|
||||
nctx.BootstrapState.Action = BootstrapActionInitControlPlane
|
||||
state.Action = BootstrapActionInitControlPlane
|
||||
} else {
|
||||
nctx.BootstrapState.Action = BootstrapActionJoinControlPlane
|
||||
state.Action = BootstrapActionJoinControlPlane
|
||||
}
|
||||
return nil
|
||||
|
||||
case LocalMembershipExistingControlPlane:
|
||||
if nctx.BootstrapState.DetectedClusterVersion == "" {
|
||||
if state.DetectedClusterVersion == "" {
|
||||
return errors.New("existing control-plane state found, but detected cluster version is empty")
|
||||
}
|
||||
|
||||
if versionEq(nctx.BootstrapState.DetectedClusterVersion, wantVersion) {
|
||||
nctx.BootstrapState.Action = BootstrapActionReconcileControlPlane
|
||||
if versionEq(state.DetectedClusterVersion, wantVersion) {
|
||||
state.Action = BootstrapActionReconcileControlPlane
|
||||
} else {
|
||||
nctx.BootstrapState.Action = BootstrapActionUpgradeControlPlane
|
||||
state.Action = BootstrapActionUpgradeControlPlane
|
||||
}
|
||||
return nil
|
||||
|
||||
case LocalMembershipExistingWorker:
|
||||
return fmt.Errorf("local state %q is invalid for control-plane role", nctx.LocalClusterState.MembershipKind)
|
||||
@@ -234,6 +238,10 @@ func ClassifyBootstrapAction(ctx context.Context, nctx *NodeContext) error {
|
||||
default:
|
||||
return fmt.Errorf("unsupported cluster role %q", role)
|
||||
}
|
||||
|
||||
nctx.BootstrapState = state
|
||||
klog.V(4).Infof("Bootstrap action: %+v", *state)
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitControlPlane(ctx context.Context, nctx *NodeContext) error {
|
||||
|
||||
Reference in New Issue
Block a user