@@ -46,6 +46,7 @@ import (
4646 clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
4747 "sigs.k8s.io/cluster-api/controllers/clustercache"
4848 "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal"
49+ runtimeclient "sigs.k8s.io/cluster-api/exp/runtime/client"
4950 "sigs.k8s.io/cluster-api/feature"
5051 "sigs.k8s.io/cluster-api/internal/contract"
5152 "sigs.k8s.io/cluster-api/internal/util/ssa"
@@ -80,6 +81,7 @@ const (
8081type KubeadmControlPlaneReconciler struct {
8182 Client client.Client
8283 SecretCachingClient client.Client
84+ RuntimeClient runtimeclient.Client
8385 controller controller.Controller
8486 recorder record.EventRecorder
8587 ClusterCache clustercache.ClusterCache
@@ -97,10 +99,13 @@ type KubeadmControlPlaneReconciler struct {
9799 managementClusterUncached internal.ManagementCluster
98100 ssaCache ssa.Cache
99101
100- // Only used for testing
101- overrideTryInPlaceUpdateFunc func (ctx context.Context , controlPlane * internal.ControlPlane , machineToInPlaceUpdate * clusterv1.Machine , machineUpToDateResult internal.UpToDateResult ) (bool , ctrl.Result , error )
102- overrideScaleUpControlPlaneFunc func (ctx context.Context , controlPlane * internal.ControlPlane ) (ctrl.Result , error )
103- overrideScaleDownControlPlaneFunc func (ctx context.Context , controlPlane * internal.ControlPlane , machineToDelete * clusterv1.Machine ) (ctrl.Result , error )
102+ // Only used for testing.
103+ overrideTryInPlaceUpdateFunc func (ctx context.Context , controlPlane * internal.ControlPlane , machineToInPlaceUpdate * clusterv1.Machine , machineUpToDateResult internal.UpToDateResult ) (bool , ctrl.Result , error )
104+ overrideScaleUpControlPlaneFunc func (ctx context.Context , controlPlane * internal.ControlPlane ) (ctrl.Result , error )
105+ overrideScaleDownControlPlaneFunc func (ctx context.Context , controlPlane * internal.ControlPlane , machineToDelete * clusterv1.Machine ) (ctrl.Result , error )
106+ overridePreflightChecksFunc func (ctx context.Context , controlPlane * internal.ControlPlane , excludeFor ... * clusterv1.Machine ) ctrl.Result
107+ overrideCanUpdateMachineFunc func (ctx context.Context , machine * clusterv1.Machine , machineUpToDateResult internal.UpToDateResult ) (bool , error )
108+ overrideCanExtensionsUpdateMachine func (ctx context.Context , machine * clusterv1.Machine , machineUpToDateResult internal.UpToDateResult , extensionHandlers []string ) (bool , []string , error )
104109}
105110
106111func (r * KubeadmControlPlaneReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
@@ -115,6 +120,9 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
115120 "EtcdDialTimeout and EtcdCallTimeout must not be 0 and " +
116121 "RemoteConditionsGracePeriod must not be < 2m" )
117122 }
123+ if feature .Gates .Enabled (feature .InPlaceUpdates ) && r .RuntimeClient == nil {
124+ return errors .New ("RuntimeClient must not be nil when InPlaceUpdates feature gate is enabled" )
125+ }
118126
119127 predicateLog := ctrl .LoggerFrom (ctx ).WithValues ("controller" , "kubeadmcontrolplane" )
120128 c , err := ctrl .NewControllerManagedBy (mgr ).
@@ -814,7 +822,8 @@ func (r *KubeadmControlPlaneReconciler) syncMachines(ctx context.Context, contro
814822 if err != nil {
815823 return errors .Wrapf (err , "failed to update Machine: %s" , klog .KObj (m ))
816824 }
817- // Note: Ensure ControlPlane has the latest version of the Machine.
825+ // Note: Ensure ControlPlane has the latest version of the Machine. This is required because
826+ // e.g. the in-place update code that is called later has to use the latest version of the Machine.
818827 controlPlane .Machines [machineName ] = updatedMachine
819828 if _ , ok := controlPlane .MachinesNotUpToDate [machineName ]; ok {
820829 controlPlane .MachinesNotUpToDate [machineName ] = updatedMachine
0 commit comments