Skip to content
Merged
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
6 changes: 0 additions & 6 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,6 @@ func (r *KubeadmControlPlaneReconciler) ClusterToKubeadmControlPlane(_ context.C
}

// syncMachines updates Machines, InfrastructureMachines and KubeadmConfigs to propagate in-place mutable fields from KCP.
// Note: It also cleans up managed fields of all Machines so that Machines that were
// created/patched before (< v1.4.0) the controller adopted Server-Side-Apply (SSA) can also work with SSA.
// Note: For InfrastructureMachines and KubeadmConfigs it also drops ownership of "metadata.labels" and
// "metadata.annotations" from "manager" so that "capi-kubeadmcontrolplane" can own these fields and can work with SSA.
// Otherwise, fields would be co-owned by our "old" "manager" and "capi-kubeadmcontrolplane" and then we would not be
// able to e.g. drop labels and annotations.
func (r *KubeadmControlPlaneReconciler) syncMachines(ctx context.Context, controlPlane *internal.ControlPlane) error {
patchHelpers := map[string]*patch.Helper{}
for machineName := range controlPlane.Machines {
Expand Down
6 changes: 5 additions & 1 deletion controlplane/kubeadm/internal/controllers/inplace_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

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

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

// Wait until the cache observed the Machine with PendingHooksAnnotation to ensure subsequent reconciles
// will observe it as well and won't repeatedly call triggerInPlaceUpdate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/tools/record"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -278,7 +279,8 @@ func Test_triggerInPlaceUpdate(t *testing.T) {
}

r := KubeadmControlPlaneReconciler{
Client: env.Client,
Client: env.Client,
recorder: record.NewFakeRecorder(32),
}

err := r.triggerInPlaceUpdate(ctx, currentMachineForPatch, upToDateResult)
Expand Down
11 changes: 9 additions & 2 deletions controlplane/kubeadm/internal/desiredstate/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func ComputeDesiredKubeadmConfig(kcp *controlplanev1.KubeadmControlPlane, cluste
}
DefaultFeatureGates(spec, parsedVersion)

return &bootstrapv1.KubeadmConfig{
kubeadmConfig := &bootstrapv1.KubeadmConfig{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: kcp.Namespace,
Expand All @@ -234,7 +234,11 @@ func ComputeDesiredKubeadmConfig(kcp *controlplanev1.KubeadmControlPlane, cluste
OwnerReferences: ownerReferences,
},
Spec: *spec,
}, nil
}
if existingKubeadmConfig != nil {
kubeadmConfig.SetUID(existingKubeadmConfig.GetUID())
}
return kubeadmConfig, nil
}

// ComputeDesiredInfraMachine computes the desired InfraMachine.
Expand Down Expand Up @@ -279,6 +283,9 @@ func ComputeDesiredInfraMachine(ctx context.Context, c client.Client, kcp *contr
if err != nil {
return nil, errors.Wrap(err, "failed to compute desired InfraMachine")
}
if existingInfraMachine != nil {
infraMachine.SetUID(existingInfraMachine.GetUID())
}
return infraMachine, nil
}

Expand Down
Loading