Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAPI changes for kubeadm cluster takeover #161

Open
wants to merge 1 commit into
base: spectro-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ const (
// instead of being a source of truth for eventual consistency.
// This annotation can be used to inform MachinePool status during in-progress scaling scenarios.
ReplicasManagedByAnnotation = "cluster.x-k8s.io/replicas-managed-by"

// TakeOverCluster is the label used to mark the nodes that run on takeover-cluster instances.
TakeOverCluster = "cluster.x-k8s.io/takeover-cluster"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}

// Note: can't use IsFalse here because we need to handle the absence of the condition as well as false.
if !conditions.IsTrue(cluster, clusterv1.ControlPlaneInitializedCondition) {
if !annotations.IsTakeOverCluster(cluster.GetObjectMeta()) && !conditions.IsTrue(cluster, clusterv1.ControlPlaneInitializedCondition) {
return r.handleClusterNotInitialized(ctx, scope)
}

Expand Down
4 changes: 2 additions & 2 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, cluster *
conditions.MarkFalse(controlPlane.KCP, controlplanev1.AvailableCondition, controlplanev1.WaitingForKubeadmInitReason, clusterv1.ConditionSeverityInfo, "")
return r.initializeControlPlane(ctx, cluster, kcp, controlPlane)
// We are scaling up
case numMachines < desiredReplicas && numMachines > 0:
case numMachines < desiredReplicas && numMachines >= 0:
// Create a new Machine w/ join
log.Info("Scaling up control plane", "Desired", desiredReplicas, "Existing", numMachines)
return r.scaleUpControlPlane(ctx, cluster, kcp, controlPlane)
Expand Down Expand Up @@ -568,7 +568,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileEtcdMembers(ctx context.Context
log := ctrl.LoggerFrom(ctx)

// If etcd is not managed by KCP this is a no-op.
if !controlPlane.IsEtcdManaged() {
if annotations.IsTakeOverCluster(controlPlane.Cluster.GetObjectMeta()) || !controlPlane.IsEtcdManaged() {
return ctrl.Result{}, nil
}

Expand Down
8 changes: 6 additions & 2 deletions controlplane/kubeadm/internal/controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ func (r *KubeadmControlPlaneReconciler) reconcileKubeconfig(ctx context.Context,
return ctrl.Result{}, errors.Wrap(err, "failed to retrieve kubeconfig Secret")
}

if err := r.adoptKubeconfigSecret(ctx, cluster, configSecret, kcp); err != nil {
return ctrl.Result{}, err
// Check if the kubeconfig secret was created by v1alpha2 controllers, and thus it has the Cluster as the owner instead of KCP;
// If yes, adopt it.
if util.IsOwnedByObject(configSecret, cluster) && !util.IsControlledBy(configSecret, kcp) {
if err := r.adoptKubeconfigSecret(ctx, cluster, configSecret, kcp); err != nil {
return ctrl.Result{}, err
}
}

// only do rotation on owned secrets
Expand Down
5 changes: 4 additions & 1 deletion internal/controllers/cluster/cluster_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, cluster *cluster
if err != nil {
return ctrl.Result{}, err
}
if initialized {

// TODO: PCP-22 set controlPlaneInitializedCondition to true for takeOver cluster
// as CP are already initialized in existing cluster
if annotations.IsTakeOverCluster(cluster.GetObjectMeta()) || initialized {
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
} else {
conditions.MarkFalse(cluster, clusterv1.ControlPlaneInitializedCondition, clusterv1.WaitingForControlPlaneProviderInitializedReason, clusterv1.ConditionSeverityInfo, "Waiting for control plane provider to indicate the control plane has been initialized")
Expand Down
5 changes: 5 additions & 0 deletions util/annotations/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func IsExternallyManaged(o metav1.Object) bool {
return hasAnnotation(o, clusterv1.ManagedByAnnotation)
}

// IsTakeOverCluster returns true if the object has the `managed-by` annotation.
func IsTakeOverCluster(o metav1.Object) bool {
return hasAnnotation(o, clusterv1.TakeOverCluster)
}

// HasPaused returns true if the object has the `paused` annotation.
func HasPaused(o metav1.Object) bool {
return hasAnnotation(o, clusterv1.PausedAnnotation)
Expand Down
Loading