@@ -27,6 +27,7 @@ import (
27
27
"fmt"
28
28
"math/big"
29
29
"reflect"
30
+ "strings"
30
31
"time"
31
32
32
33
"github.com/blang/semver/v4"
@@ -105,13 +106,14 @@ type WorkloadCluster interface {
105
106
// Upgrade related tasks.
106
107
ReconcileKubeletRBACBinding (ctx context.Context , version semver.Version ) error
107
108
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
109
+ UpdateKubernetesVersionInKubeadmConfigMap (version semver.Version ) func (* bootstrapv1.ClusterConfiguration , * []string )
110
+ UpdateImageRepositoryInKubeadmConfigMap (imageRepository string ) func (* bootstrapv1.ClusterConfiguration , * []string )
111
+ UpdateFeatureGatesInKubeadmConfigMap (featureGates map [string ]bool ) func (* bootstrapv1.ClusterConfiguration , * []string )
112
+ UpdateEtcdVersionInKubeadmConfigMap (etcd * bootstrapv1.LocalEtcd ) func (* bootstrapv1.ClusterConfiguration , * []string )
113
+ UpdateEtcdExtraArgsInKubeadmConfigMap (etcd * bootstrapv1.LocalEtcd ) func (* bootstrapv1.ClusterConfiguration , * []string )
114
+ UpdateAPIServerInKubeadmConfigMap (apiServer bootstrapv1.APIServer ) func (* bootstrapv1.ClusterConfiguration , * []string )
115
+ UpdateControllerManagerInKubeadmConfigMap (controllerManager bootstrapv1.ControlPlaneComponent ) func (* bootstrapv1.ClusterConfiguration , * []string )
116
+ UpdateSchedulerInKubeadmConfigMap (scheduler bootstrapv1.ControlPlaneComponent ) func (* bootstrapv1.ClusterConfiguration , * []string )
115
117
UpdateKubeletConfigMap (ctx context.Context , version semver.Version ) error
116
118
UpdateKubeProxyImageInfo (ctx context.Context , kcp * controlplanev1.KubeadmControlPlane , version semver.Version ) error
117
119
UpdateCoreDNS (ctx context.Context , kcp * controlplanev1.KubeadmControlPlane , version semver.Version ) error
@@ -121,6 +123,7 @@ type WorkloadCluster interface {
121
123
ForwardEtcdLeadership (ctx context.Context , machine * clusterv1.Machine , leaderCandidate * clusterv1.Machine ) error
122
124
AllowBootstrapTokensToGetNodes (ctx context.Context ) error
123
125
AllowClusterAdminPermissions (ctx context.Context , version semver.Version ) error
126
+ UpdateClusterConfiguration (ctx context.Context , version semver.Version , mutators ... func (* bootstrapv1.ClusterConfiguration , * []string )) error
124
127
125
128
// State recovery tasks.
126
129
ReconcileEtcdMembers (ctx context.Context , nodeNames []string , version semver.Version ) ([]string , error )
@@ -173,20 +176,35 @@ func (w *Workload) getConfigMap(ctx context.Context, configMap ctrlclient.Object
173
176
}
174
177
175
178
// 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 ) {
179
+ func (w * Workload ) UpdateImageRepositoryInKubeadmConfigMap (imageRepository string ) func ( * bootstrapv1. ClusterConfiguration , * [] string ) {
180
+ return func (c * bootstrapv1.ClusterConfiguration , updatedKeys * [] string ) {
178
181
if imageRepository == "" {
179
182
return
180
183
}
184
+
181
185
c .ImageRepository = imageRepository
182
- }, version )
186
+ * updatedKeys = append (* updatedKeys , "imageRepository" )
187
+ }
188
+ }
189
+
190
+ // UpdateFeatureGatesInKubeadmConfigMap updates the feature gates in the kubeadm config map.
191
+ func (w * Workload ) UpdateFeatureGatesInKubeadmConfigMap (featureGates map [string ]bool ) func (* bootstrapv1.ClusterConfiguration , * []string ) {
192
+ return func (c * bootstrapv1.ClusterConfiguration , updatedKeys * []string ) {
193
+ if featureGates == nil {
194
+ return
195
+ }
196
+
197
+ c .FeatureGates = featureGates
198
+ * updatedKeys = append (* updatedKeys , "featureGates" )
199
+ }
183
200
}
184
201
185
202
// 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 ) {
203
+ func (w * Workload ) UpdateKubernetesVersionInKubeadmConfigMap (version semver.Version ) func ( * bootstrapv1. ClusterConfiguration , * [] string ) {
204
+ return func (c * bootstrapv1.ClusterConfiguration , updatedKeys * [] string ) {
188
205
c .KubernetesVersion = fmt .Sprintf ("v%s" , version .String ())
189
- }, version )
206
+ * updatedKeys = append (* updatedKeys , "kubernetesVersion" )
207
+ }
190
208
}
191
209
192
210
// UpdateKubeletConfigMap will create a new kubelet-config-1.x config map for a new version of the kubelet.
@@ -270,24 +288,27 @@ func (w *Workload) UpdateKubeletConfigMap(ctx context.Context, version semver.Ve
270
288
}
271
289
272
290
// 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 ) {
291
+ func (w * Workload ) UpdateAPIServerInKubeadmConfigMap (apiServer bootstrapv1.APIServer ) func ( * bootstrapv1. ClusterConfiguration , * [] string ) {
292
+ return func (c * bootstrapv1.ClusterConfiguration , updatedKeys * [] string ) {
275
293
c .APIServer = apiServer
276
- }, version )
294
+ * updatedKeys = append (* updatedKeys , "apiServer" )
295
+ }
277
296
}
278
297
279
298
// 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 ) {
299
+ func (w * Workload ) UpdateControllerManagerInKubeadmConfigMap (controllerManager bootstrapv1.ControlPlaneComponent ) func ( * bootstrapv1. ClusterConfiguration , * [] string ) {
300
+ return func (c * bootstrapv1.ClusterConfiguration , updatedKeys * [] string ) {
282
301
c .ControllerManager = controllerManager
283
- }, version )
302
+ * updatedKeys = append (* updatedKeys , "controllerManager" )
303
+ }
284
304
}
285
305
286
306
// 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 ) {
307
+ func (w * Workload ) UpdateSchedulerInKubeadmConfigMap (scheduler bootstrapv1.ControlPlaneComponent ) func ( * bootstrapv1. ClusterConfiguration , * [] string ) {
308
+ return func (c * bootstrapv1.ClusterConfiguration , updatedKeys * [] string ) {
289
309
c .Scheduler = scheduler
290
- }, version )
310
+ * updatedKeys = append (* updatedKeys , "scheduler" )
311
+ }
291
312
}
292
313
293
314
// RemoveMachineFromKubeadmConfigMap removes the entry for the machine from the kubeadm configmap.
@@ -350,11 +371,11 @@ func (w *Workload) updateClusterStatus(ctx context.Context, mutator func(status
350
371
})
351
372
}
352
373
353
- // updateClusterConfiguration gets the ClusterConfiguration kubeadm-config ConfigMap, converts it to the
374
+ // UpdateClusterConfiguration gets the ClusterConfiguration kubeadm-config ConfigMap, converts it to the
354
375
// Cluster API representation, and then applies a mutation func; if changes are detected, the
355
376
// data are converted back into the Kubeadm API version in use for the target Kubernetes version and the
356
377
// kubeadm-config ConfigMap updated.
357
- func (w * Workload ) updateClusterConfiguration (ctx context.Context , mutator func (* bootstrapv1.ClusterConfiguration ), version semver. Version ) error {
378
+ func (w * Workload ) UpdateClusterConfiguration (ctx context.Context , version semver. Version , mutators ... func (* bootstrapv1.ClusterConfiguration , * [] string ) ) error {
358
379
return retry .RetryOnConflict (retry .DefaultBackoff , func () error {
359
380
key := ctrlclient.ObjectKey {Name : kubeadmConfigKey , Namespace : metav1 .NamespaceSystem }
360
381
configMap , err := w .getConfigMap (ctx , key )
@@ -373,7 +394,10 @@ func (w *Workload) updateClusterConfiguration(ctx context.Context, mutator func(
373
394
}
374
395
375
396
updatedObj := currentObj .DeepCopy ()
376
- mutator (updatedObj )
397
+ updatedKeys := make ([]string , 0 )
398
+ for i := range mutators {
399
+ mutators [i ](updatedObj , & updatedKeys )
400
+ }
377
401
378
402
if ! reflect .DeepEqual (currentObj , updatedObj ) {
379
403
updatedData , err := kubeadmtypes .MarshalClusterConfigurationForVersion (updatedObj , version )
@@ -382,7 +406,7 @@ func (w *Workload) updateClusterConfiguration(ctx context.Context, mutator func(
382
406
}
383
407
configMap .Data [clusterConfigurationKey ] = updatedData
384
408
if err := w .Client .Update (ctx , configMap ); err != nil {
385
- return errors .Wrap (err , "failed to upgrade the kubeadmConfigMap" )
409
+ return errors .Wrapf (err , "failed to upgrade the kubeadmConfigMap with the following properties %s" , strings . Join ( updatedKeys , "," ) )
386
410
}
387
411
}
388
412
return nil
0 commit comments