@@ -105,13 +105,14 @@ type WorkloadCluster interface {
105
105
// Upgrade related tasks.
106
106
ReconcileKubeletRBACBinding (ctx context.Context , version semver.Version ) error
107
107
ReconcileKubeletRBACRole (ctx context.Context , version semver.Version ) error
108
- UpdateKubernetesVersionInKubeadmConfigMap (ctx context.Context , version semver.Version ) error
109
- UpdateImageRepositoryInKubeadmConfigMap (ctx context.Context , imageRepository string , version semver.Version ) error
110
- UpdateEtcdVersionInKubeadmConfigMap (ctx context.Context , imageRepository , imageTag string , version semver.Version ) error
111
- UpdateEtcdExtraArgsInKubeadmConfigMap (ctx context.Context , extraArgs map [string ]string , version semver.Version ) error
112
- UpdateAPIServerInKubeadmConfigMap (ctx context.Context , apiServer bootstrapv1.APIServer , version semver.Version ) error
113
- UpdateControllerManagerInKubeadmConfigMap (ctx context.Context , controllerManager bootstrapv1.ControlPlaneComponent , version semver.Version ) error
114
- UpdateSchedulerInKubeadmConfigMap (ctx context.Context , scheduler bootstrapv1.ControlPlaneComponent , version semver.Version ) error
108
+ UpdateKubernetesVersionInKubeadmConfigMap (version semver.Version ) func (* bootstrapv1.ClusterConfiguration )
109
+ UpdateImageRepositoryInKubeadmConfigMap (imageRepository string ) func (* bootstrapv1.ClusterConfiguration )
110
+ UpdateFeatureGatesInKubeadmConfigMap (featureGates map [string ]bool ) func (* bootstrapv1.ClusterConfiguration )
111
+ UpdateEtcdLocalInKubeadmConfigMap (localEtcd * bootstrapv1.LocalEtcd ) func (* bootstrapv1.ClusterConfiguration )
112
+ UpdateEtcdExternalInKubeadmConfigMap (externalEtcd * bootstrapv1.ExternalEtcd ) func (* bootstrapv1.ClusterConfiguration )
113
+ UpdateAPIServerInKubeadmConfigMap (apiServer bootstrapv1.APIServer ) func (* bootstrapv1.ClusterConfiguration )
114
+ UpdateControllerManagerInKubeadmConfigMap (controllerManager bootstrapv1.ControlPlaneComponent ) func (* bootstrapv1.ClusterConfiguration )
115
+ UpdateSchedulerInKubeadmConfigMap (scheduler bootstrapv1.ControlPlaneComponent ) func (* bootstrapv1.ClusterConfiguration )
115
116
UpdateKubeletConfigMap (ctx context.Context , version semver.Version ) error
116
117
UpdateKubeProxyImageInfo (ctx context.Context , kcp * controlplanev1.KubeadmControlPlane , version semver.Version ) error
117
118
UpdateCoreDNS (ctx context.Context , kcp * controlplanev1.KubeadmControlPlane , version semver.Version ) error
@@ -121,6 +122,7 @@ type WorkloadCluster interface {
121
122
ForwardEtcdLeadership (ctx context.Context , machine * clusterv1.Machine , leaderCandidate * clusterv1.Machine ) error
122
123
AllowBootstrapTokensToGetNodes (ctx context.Context ) error
123
124
AllowClusterAdminPermissions (ctx context.Context , version semver.Version ) error
125
+ UpdateClusterConfiguration (ctx context.Context , version semver.Version , mutators ... func (* bootstrapv1.ClusterConfiguration )) error
124
126
125
127
// State recovery tasks.
126
128
ReconcileEtcdMembers (ctx context.Context , nodeNames []string , version semver.Version ) ([]string , error )
@@ -173,20 +175,30 @@ func (w *Workload) getConfigMap(ctx context.Context, configMap ctrlclient.Object
173
175
}
174
176
175
177
// UpdateImageRepositoryInKubeadmConfigMap updates the image repository in the kubeadm config map.
176
- func (w * Workload ) UpdateImageRepositoryInKubeadmConfigMap (ctx context. Context , imageRepository string , version semver. Version ) error {
177
- return w . updateClusterConfiguration ( ctx , func (c * bootstrapv1.ClusterConfiguration ) {
178
+ func (w * Workload ) UpdateImageRepositoryInKubeadmConfigMap (imageRepository string ) func ( * bootstrapv1. ClusterConfiguration ) {
179
+ return func (c * bootstrapv1.ClusterConfiguration ) {
178
180
if imageRepository == "" {
179
181
return
180
182
}
183
+
181
184
c .ImageRepository = imageRepository
182
- }, version )
185
+ }
186
+ }
187
+
188
+ // UpdateFeatureGatesInKubeadmConfigMap updates the feature gates in the kubeadm config map.
189
+ func (w * Workload ) UpdateFeatureGatesInKubeadmConfigMap (featureGates map [string ]bool ) func (* bootstrapv1.ClusterConfiguration ) {
190
+ return func (c * bootstrapv1.ClusterConfiguration ) {
191
+ // Even if featureGates is nil, reset it to ClusterConfiguration
192
+ // to override any previously set feature gates.
193
+ c .FeatureGates = featureGates
194
+ }
183
195
}
184
196
185
197
// UpdateKubernetesVersionInKubeadmConfigMap updates the kubernetes version in the kubeadm config map.
186
- func (w * Workload ) UpdateKubernetesVersionInKubeadmConfigMap (ctx context. Context , version semver.Version ) error {
187
- return w . updateClusterConfiguration ( ctx , func (c * bootstrapv1.ClusterConfiguration ) {
198
+ func (w * Workload ) UpdateKubernetesVersionInKubeadmConfigMap (version semver.Version ) func ( * bootstrapv1. ClusterConfiguration ) {
199
+ return func (c * bootstrapv1.ClusterConfiguration ) {
188
200
c .KubernetesVersion = fmt .Sprintf ("v%s" , version .String ())
189
- }, version )
201
+ }
190
202
}
191
203
192
204
// UpdateKubeletConfigMap will create a new kubelet-config-1.x config map for a new version of the kubelet.
@@ -270,24 +282,24 @@ func (w *Workload) UpdateKubeletConfigMap(ctx context.Context, version semver.Ve
270
282
}
271
283
272
284
// UpdateAPIServerInKubeadmConfigMap updates api server configuration in kubeadm config map.
273
- func (w * Workload ) UpdateAPIServerInKubeadmConfigMap (ctx context. Context , apiServer bootstrapv1.APIServer , version semver. Version ) error {
274
- return w . updateClusterConfiguration ( ctx , func (c * bootstrapv1.ClusterConfiguration ) {
285
+ func (w * Workload ) UpdateAPIServerInKubeadmConfigMap (apiServer bootstrapv1.APIServer ) func ( * bootstrapv1. ClusterConfiguration ) {
286
+ return func (c * bootstrapv1.ClusterConfiguration ) {
275
287
c .APIServer = apiServer
276
- }, version )
288
+ }
277
289
}
278
290
279
291
// UpdateControllerManagerInKubeadmConfigMap updates controller manager configuration in kubeadm config map.
280
- func (w * Workload ) UpdateControllerManagerInKubeadmConfigMap (ctx context. Context , controllerManager bootstrapv1.ControlPlaneComponent , version semver. Version ) error {
281
- return w . updateClusterConfiguration ( ctx , func (c * bootstrapv1.ClusterConfiguration ) {
292
+ func (w * Workload ) UpdateControllerManagerInKubeadmConfigMap (controllerManager bootstrapv1.ControlPlaneComponent ) func ( * bootstrapv1. ClusterConfiguration ) {
293
+ return func (c * bootstrapv1.ClusterConfiguration ) {
282
294
c .ControllerManager = controllerManager
283
- }, version )
295
+ }
284
296
}
285
297
286
298
// UpdateSchedulerInKubeadmConfigMap updates scheduler configuration in kubeadm config map.
287
- func (w * Workload ) UpdateSchedulerInKubeadmConfigMap (ctx context. Context , scheduler bootstrapv1.ControlPlaneComponent , version semver. Version ) error {
288
- return w . updateClusterConfiguration ( ctx , func (c * bootstrapv1.ClusterConfiguration ) {
299
+ func (w * Workload ) UpdateSchedulerInKubeadmConfigMap (scheduler bootstrapv1.ControlPlaneComponent ) func ( * bootstrapv1. ClusterConfiguration ) {
300
+ return func (c * bootstrapv1.ClusterConfiguration ) {
289
301
c .Scheduler = scheduler
290
- }, version )
302
+ }
291
303
}
292
304
293
305
// RemoveMachineFromKubeadmConfigMap removes the entry for the machine from the kubeadm configmap.
@@ -350,11 +362,11 @@ func (w *Workload) updateClusterStatus(ctx context.Context, mutator func(status
350
362
})
351
363
}
352
364
353
- // updateClusterConfiguration gets the ClusterConfiguration kubeadm-config ConfigMap, converts it to the
365
+ // UpdateClusterConfiguration gets the ClusterConfiguration kubeadm-config ConfigMap, converts it to the
354
366
// Cluster API representation, and then applies a mutation func; if changes are detected, the
355
367
// data are converted back into the Kubeadm API version in use for the target Kubernetes version and the
356
368
// kubeadm-config ConfigMap updated.
357
- func (w * Workload ) updateClusterConfiguration (ctx context.Context , mutator func (* bootstrapv1.ClusterConfiguration ), version semver. Version ) error {
369
+ func (w * Workload ) UpdateClusterConfiguration (ctx context.Context , version semver. Version , mutators ... func (* bootstrapv1.ClusterConfiguration )) error {
358
370
return retry .RetryOnConflict (retry .DefaultBackoff , func () error {
359
371
key := ctrlclient.ObjectKey {Name : kubeadmConfigKey , Namespace : metav1 .NamespaceSystem }
360
372
configMap , err := w .getConfigMap (ctx , key )
@@ -373,7 +385,9 @@ func (w *Workload) updateClusterConfiguration(ctx context.Context, mutator func(
373
385
}
374
386
375
387
updatedObj := currentObj .DeepCopy ()
376
- mutator (updatedObj )
388
+ for i := range mutators {
389
+ mutators [i ](updatedObj )
390
+ }
377
391
378
392
if ! reflect .DeepEqual (currentObj , updatedObj ) {
379
393
updatedData , err := kubeadmtypes .MarshalClusterConfigurationForVersion (updatedObj , version )
@@ -382,7 +396,7 @@ func (w *Workload) updateClusterConfiguration(ctx context.Context, mutator func(
382
396
}
383
397
configMap .Data [clusterConfigurationKey ] = updatedData
384
398
if err := w .Client .Update (ctx , configMap ); err != nil {
385
- return errors .Wrap (err , "failed to upgrade the kubeadmConfigMap" )
399
+ return errors .Wrap (err , "failed to upgrade cluster configuration in the kubeadmConfigMap" )
386
400
}
387
401
}
388
402
return nil
0 commit comments