Skip to content

Commit 6e15d77

Browse files
🌱 Add in-place to machineset controller (#12906)
* add-in-place-to-machineset-controller * Fix review findings Signed-off-by: Stefan Büringer buringerst@vmware.com * Address comments --------- Signed-off-by: Stefan Büringer buringerst@vmware.com Co-authored-by: Stefan Bueringer <buringerst@vmware.com>
1 parent d08a59d commit 6e15d77

File tree

12 files changed

+2110
-557
lines changed

12 files changed

+2110
-557
lines changed

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,12 +806,6 @@ func (r *KubeadmControlPlaneReconciler) ClusterToKubeadmControlPlane(_ context.C
806806
}
807807

808808
// syncMachines updates Machines, InfrastructureMachines and KubeadmConfigs to propagate in-place mutable fields from KCP.
809-
// Note: It also cleans up managed fields of all Machines so that Machines that were
810-
// created/patched before (< v1.4.0) the controller adopted Server-Side-Apply (SSA) can also work with SSA.
811-
// Note: For InfrastructureMachines and KubeadmConfigs it also drops ownership of "metadata.labels" and
812-
// "metadata.annotations" from "manager" so that "capi-kubeadmcontrolplane" can own these fields and can work with SSA.
813-
// Otherwise, fields would be co-owned by our "old" "manager" and "capi-kubeadmcontrolplane" and then we would not be
814-
// able to e.g. drop labels and annotations.
815809
func (r *KubeadmControlPlaneReconciler) syncMachines(ctx context.Context, controlPlane *internal.ControlPlane) error {
816810
patchHelpers := map[string]*patch.Helper{}
817811
for machineName := range controlPlane.Machines {

controlplane/kubeadm/internal/controllers/inplace_trigger.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/pkg/errors"
24+
corev1 "k8s.io/api/core/v1"
2425
"k8s.io/apimachinery/pkg/util/wait"
2526
"k8s.io/klog/v2"
2627
ctrl "sigs.k8s.io/controller-runtime"
@@ -100,7 +101,8 @@ func (r *KubeadmControlPlaneReconciler) triggerInPlaceUpdate(ctx context.Context
100101
// of an in-place update here, e.g. for the case where the InfraMachineTemplate was rotated.
101102
clusterv1.TemplateClonedFromNameAnnotation: desiredInfraMachine.GetAnnotations()[clusterv1.TemplateClonedFromNameAnnotation],
102103
clusterv1.TemplateClonedFromGroupKindAnnotation: desiredInfraMachine.GetAnnotations()[clusterv1.TemplateClonedFromGroupKindAnnotation],
103-
clusterv1.UpdateInProgressAnnotation: "",
104+
// Machine controller waits for this annotation to exist on Machine and related objects before starting the in-place update.
105+
clusterv1.UpdateInProgressAnnotation: "",
104106
})
105107
if err := ssa.Patch(ctx, r.Client, kcpManagerName, desiredInfraMachine); err != nil {
106108
return errors.Wrapf(err, "failed to complete triggering in-place update for Machine %s", klog.KObj(machine))
@@ -109,6 +111,7 @@ func (r *KubeadmControlPlaneReconciler) triggerInPlaceUpdate(ctx context.Context
109111
// Write KubeadmConfig without the labels & annotations that are written continuously by updateLabelsAndAnnotations.
110112
desiredKubeadmConfig.Labels = nil
111113
desiredKubeadmConfig.Annotations = map[string]string{
114+
// Machine controller waits for this annotation to exist on Machine and related objects before starting the in-place update.
112115
clusterv1.UpdateInProgressAnnotation: "",
113116
}
114117
if err := ssa.Patch(ctx, r.Client, kcpManagerName, desiredKubeadmConfig); err != nil {
@@ -134,6 +137,7 @@ func (r *KubeadmControlPlaneReconciler) triggerInPlaceUpdate(ctx context.Context
134137
}
135138

136139
log.Info("Completed triggering in-place update", "Machine", klog.KObj(machine))
140+
r.recorder.Event(machine, corev1.EventTypeNormal, "SuccessfulStartInPlaceUpdate", "Machine starting in-place update")
137141

138142
// Wait until the cache observed the Machine with PendingHooksAnnotation to ensure subsequent reconciles
139143
// will observe it as well and won't repeatedly call triggerInPlaceUpdate.

controlplane/kubeadm/internal/controllers/inplace_trigger_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
. "github.com/onsi/gomega"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
27+
"k8s.io/client-go/tools/record"
2728
"k8s.io/utils/ptr"
2829
"sigs.k8s.io/controller-runtime/pkg/client"
2930

@@ -278,7 +279,8 @@ func Test_triggerInPlaceUpdate(t *testing.T) {
278279
}
279280

280281
r := KubeadmControlPlaneReconciler{
281-
Client: env.Client,
282+
Client: env.Client,
283+
recorder: record.NewFakeRecorder(32),
282284
}
283285

284286
err := r.triggerInPlaceUpdate(ctx, currentMachineForPatch, upToDateResult)

controlplane/kubeadm/internal/desiredstate/desired_state.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func ComputeDesiredKubeadmConfig(kcp *controlplanev1.KubeadmControlPlane, cluste
225225
}
226226
DefaultFeatureGates(spec, parsedVersion)
227227

228-
return &bootstrapv1.KubeadmConfig{
228+
kubeadmConfig := &bootstrapv1.KubeadmConfig{
229229
ObjectMeta: metav1.ObjectMeta{
230230
Name: name,
231231
Namespace: kcp.Namespace,
@@ -234,7 +234,11 @@ func ComputeDesiredKubeadmConfig(kcp *controlplanev1.KubeadmControlPlane, cluste
234234
OwnerReferences: ownerReferences,
235235
},
236236
Spec: *spec,
237-
}, nil
237+
}
238+
if existingKubeadmConfig != nil {
239+
kubeadmConfig.SetUID(existingKubeadmConfig.GetUID())
240+
}
241+
return kubeadmConfig, nil
238242
}
239243

240244
// ComputeDesiredInfraMachine computes the desired InfraMachine.
@@ -279,6 +283,9 @@ func ComputeDesiredInfraMachine(ctx context.Context, c client.Client, kcp *contr
279283
if err != nil {
280284
return nil, errors.Wrap(err, "failed to compute desired InfraMachine")
281285
}
286+
if existingInfraMachine != nil {
287+
infraMachine.SetUID(existingInfraMachine.GetUID())
288+
}
282289
return infraMachine, nil
283290
}
284291

0 commit comments

Comments
 (0)