Skip to content

Commit 7c41dc7

Browse files
committed
takeover changes in latest branch
1 parent f0787e1 commit 7c41dc7

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

api/v1beta1/common_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525
)
2626

2727
const (
28+
// TakeOverCluster is the label used to mark the nodes that run on takeover-cluster instances.
29+
TakeOverCluster = "cluster.x-k8s.io/takeover-cluster"
30+
2831
// ClusterNameLabel is the label set on machines linked to a cluster and
2932
// external objects(bootstrap and infrastructure providers).
3033
ClusterNameLabel = "cluster.x-k8s.io/cluster-name"

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
"sigs.k8s.io/cluster-api/feature"
5656
"sigs.k8s.io/cluster-api/internal/util/taints"
5757
"sigs.k8s.io/cluster-api/util"
58+
"sigs.k8s.io/cluster-api/util/annotations"
5859
"sigs.k8s.io/cluster-api/util/conditions"
5960
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
6061
clog "sigs.k8s.io/cluster-api/util/log"
@@ -338,7 +339,7 @@ func (r *KubeadmConfigReconciler) reconcile(ctx context.Context, scope *Scope, c
338339
}
339340

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

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
"sigs.k8s.io/cluster-api/internal/contract"
5151
"sigs.k8s.io/cluster-api/internal/util/ssa"
5252
"sigs.k8s.io/cluster-api/util"
53+
"sigs.k8s.io/cluster-api/util/annotations"
5354
"sigs.k8s.io/cluster-api/util/collections"
5455
"sigs.k8s.io/cluster-api/util/conditions"
5556
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
@@ -489,6 +490,11 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, controlPl
489490
switch {
490491
// We are creating the first replica
491492
case numMachines < desiredReplicas && numMachines == 0:
493+
if annotations.IsTakeOverCluster(controlPlane.Cluster.GetObjectMeta()) {
494+
// Create a new Machine w/ join
495+
log.Info("Scaling up control plane for TakeOverCluster", "Desired", desiredReplicas, "Existing", numMachines)
496+
return r.scaleUpControlPlane(ctx, controlPlane)
497+
}
492498
// Create new Machine w/ init
493499
log.Info("Initializing control plane", "desired", desiredReplicas, "existing", numMachines)
494500
conditions.MarkFalse(controlPlane.KCP, controlplanev1.AvailableCondition, controlplanev1.WaitingForKubeadmInitReason, clusterv1.ConditionSeverityInfo, "")
@@ -1094,7 +1100,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileEtcdMembers(ctx context.Context
10941100
log := ctrl.LoggerFrom(ctx)
10951101

10961102
// If etcd is not managed by KCP this is a no-op.
1097-
if !controlPlane.IsEtcdManaged() {
1103+
if annotations.IsTakeOverCluster(controlPlane.Cluster.GetObjectMeta()) || !controlPlane.IsEtcdManaged() {
10981104
return nil
10991105
}
11001106

controlplane/kubeadm/internal/controllers/helpers.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ func (r *KubeadmControlPlaneReconciler) reconcileKubeconfig(ctx context.Context,
8686
return ctrl.Result{}, errors.Wrap(err, "failed to retrieve kubeconfig Secret")
8787
}
8888

89-
if err := r.adoptKubeconfigSecret(ctx, configSecret, controlPlane.KCP); err != nil {
90-
return ctrl.Result{}, err
89+
// if err := r.adoptKubeconfigSecret(ctx, configSecret, controlPlane.KCP); err != nil {
90+
// return ctrl.Result{}, err
91+
if util.IsOwnedByObject(configSecret, controlPlane.Cluster) && !util.IsControlledBy(configSecret, controlPlane.KCP) {
92+
if err := r.adoptKubeconfigSecret(ctx, configSecret, controlPlane.KCP); err != nil {
93+
return ctrl.Result{}, err
94+
}
9195
}
9296

9397
// only do rotation on owned secrets

internal/controllers/cluster/cluster_controller_phases.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"sigs.k8s.io/cluster-api/controllers/external"
3838
capierrors "sigs.k8s.io/cluster-api/errors"
3939
"sigs.k8s.io/cluster-api/util"
40+
"sigs.k8s.io/cluster-api/util/annotations"
4041
"sigs.k8s.io/cluster-api/util/conditions"
4142
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
4243
"sigs.k8s.io/cluster-api/util/kubeconfig"
@@ -313,7 +314,7 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, s *scope) (ctrl.
313314
if err != nil {
314315
return ctrl.Result{}, err
315316
}
316-
if initialized {
317+
if annotations.IsTakeOverCluster(cluster.GetObjectMeta()) || initialized {
317318
conditions.MarkTrue(cluster, clusterv1.ControlPlaneInitializedCondition)
318319
} else {
319320
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)