@@ -148,6 +148,20 @@ func TestGetAdjustedKcpConfig(t *testing.T) {
148
148
}
149
149
150
150
func TestCleanupConfigFields (t * testing.T ) {
151
+ t .Run ("Format gets set to cloud-config if not set" , func (t * testing.T ) {
152
+ g := NewWithT (t )
153
+ kcpConfig := & bootstrapv1.KubeadmConfigSpec {
154
+ Format : "" ,
155
+ }
156
+ machineConfig := & bootstrapv1.KubeadmConfig {
157
+ Spec : bootstrapv1.KubeadmConfigSpec {
158
+ Format : "" ,
159
+ },
160
+ }
161
+ cleanupConfigFields (kcpConfig , machineConfig )
162
+ g .Expect (kcpConfig .Format ).To (Equal (bootstrapv1 .CloudConfig ))
163
+ g .Expect (machineConfig .Spec .Format ).To (Equal (bootstrapv1 .CloudConfig ))
164
+ })
151
165
t .Run ("ClusterConfiguration gets removed from KcpConfig and MachineConfig" , func (t * testing.T ) {
152
166
g := NewWithT (t )
153
167
kcpConfig := & bootstrapv1.KubeadmConfigSpec {
@@ -281,6 +295,52 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
281
295
kcp := & controlplanev1.KubeadmControlPlane {}
282
296
g .Expect (matchInitOrJoinConfiguration (nil , kcp )).To (BeTrue ())
283
297
})
298
+ t .Run ("returns true if one format is empty and the other one cloud-config" , func (t * testing.T ) {
299
+ g := NewWithT (t )
300
+ kcp := & controlplanev1.KubeadmControlPlane {
301
+ Spec : controlplanev1.KubeadmControlPlaneSpec {
302
+ KubeadmConfigSpec : bootstrapv1.KubeadmConfigSpec {
303
+ Format : bootstrapv1 .CloudConfig ,
304
+ },
305
+ },
306
+ }
307
+ m := & clusterv1.Machine {
308
+ TypeMeta : metav1.TypeMeta {
309
+ Kind : "KubeadmConfig" ,
310
+ APIVersion : clusterv1 .GroupVersion .String (),
311
+ },
312
+ ObjectMeta : metav1.ObjectMeta {
313
+ Namespace : "default" ,
314
+ Name : "test" ,
315
+ },
316
+ Spec : clusterv1.MachineSpec {
317
+ Bootstrap : clusterv1.Bootstrap {
318
+ ConfigRef : & corev1.ObjectReference {
319
+ Kind : "KubeadmConfig" ,
320
+ Namespace : "default" ,
321
+ Name : "test" ,
322
+ APIVersion : bootstrapv1 .GroupVersion .String (),
323
+ },
324
+ },
325
+ },
326
+ }
327
+ machineConfigs := map [string ]* bootstrapv1.KubeadmConfig {
328
+ m .Name : {
329
+ TypeMeta : metav1.TypeMeta {
330
+ Kind : "KubeadmConfig" ,
331
+ APIVersion : bootstrapv1 .GroupVersion .String (),
332
+ },
333
+ ObjectMeta : metav1.ObjectMeta {
334
+ Namespace : "default" ,
335
+ Name : "test" ,
336
+ },
337
+ Spec : bootstrapv1.KubeadmConfigSpec {
338
+ Format : "" ,
339
+ },
340
+ },
341
+ }
342
+ g .Expect (matchInitOrJoinConfiguration (machineConfigs [m .Name ], kcp )).To (BeTrue ())
343
+ })
284
344
t .Run ("returns true if InitConfiguration is equal" , func (t * testing.T ) {
285
345
g := NewWithT (t )
286
346
kcp := & controlplanev1.KubeadmControlPlane {
0 commit comments