Skip to content

Commit 5936035

Browse files
committed
takeover related changes for CAPI v1.3.2
1 parent 8aaab60 commit 5936035

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

api/v1beta1/common_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
)
2323

2424
const (
25+
// TakeOverCluster is the label used to mark the nodes that run on takeover-cluster instances.
26+
TakeOverCluster = "cluster.x-k8s.io/takeover-cluster"
27+
2528
// ClusterLabelName is the label set on machines linked to a cluster and
2629
// external objects(bootstrap and infrastructure providers).
2730
ClusterLabelName = "cluster.x-k8s.io/cluster-name"

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
279279
}
280280

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

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, cluster *
394394
switch {
395395
// We are creating the first replica
396396
case numMachines < desiredReplicas && numMachines == 0:
397+
if annotations.IsTakeOverCluster(controlPlane.Cluster.GetObjectMeta()) {
398+
// Create a new Machine w/ join
399+
log.Info("Scaling up control plane for TakeOverCluster", "Desired", desiredReplicas, "Existing", numMachines)
400+
return r.scaleUpControlPlane(ctx, cluster, kcp, controlPlane)
401+
}
397402
// Create new Machine w/ init
398403
log.Info("Initializing control plane", "Desired", desiredReplicas, "Existing", numMachines)
399404
conditions.MarkFalse(controlPlane.KCP, controlplanev1.AvailableCondition, controlplanev1.WaitingForKubeadmInitReason, clusterv1.ConditionSeverityInfo, "")
@@ -568,7 +573,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileEtcdMembers(ctx context.Context
568573
log := ctrl.LoggerFrom(ctx)
569574

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

controlplane/kubeadm/internal/controllers/helpers.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ func (r *KubeadmControlPlaneReconciler) reconcileKubeconfig(ctx context.Context,
7373
case err != nil:
7474
return ctrl.Result{}, errors.Wrap(err, "failed to retrieve kubeconfig Secret")
7575
}
76-
77-
if err := r.adoptKubeconfigSecret(ctx, cluster, configSecret, kcp); err != nil {
78-
return ctrl.Result{}, err
76+
77+
if util.IsOwnedByObject(configSecret, cluster) && !util.IsControlledBy(configSecret, kcp) {
78+
if err := r.adoptKubeconfigSecret(ctx, cluster, configSecret, kcp); err != nil {
79+
return ctrl.Result{}, err
80+
}
7981
}
8082

8183
// only do rotation on owned secrets

internal/controllers/cluster/cluster_controller_phases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, cluster *cluster
245245
if err != nil {
246246
return ctrl.Result{}, err
247247
}
248-
if initialized {
248+
if annotations.IsTakeOverCluster(cluster.GetObjectMeta()) || initialized {
249249
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
250250
} else {
251251
conditions.MarkFalse(cluster, clusterv1.ControlPlaneInitializedCondition, clusterv1.WaitingForControlPlaneProviderInitializedReason, clusterv1.ConditionSeverityInfo, "Waiting for control plane provider to indicate the control plane has been initialized")

util/annotations/helpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import (
2525
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2626
)
2727

28+
// IsTakeOverCluster returns true if the object has the `managed-by` annotation.
29+
func IsTakeOverCluster(o metav1.Object) bool {
30+
return hasAnnotation(o, clusterv1.TakeOverCluster)
31+
}
32+
2833
// IsPaused returns true if the Cluster is paused or the object has the `paused` annotation.
2934
func IsPaused(cluster *clusterv1.Cluster, o metav1.Object) bool {
3035
if cluster.Spec.Paused {

0 commit comments

Comments
 (0)