@@ -253,13 +253,13 @@ func TestReconcileNormalNode(t *testing.T) {
253
253
func TestReconcileNormalEtcd (t * testing.T ) {
254
254
inMemoryMachineWithNodeNotYetProvisioned := & infrav1.InMemoryMachine {
255
255
ObjectMeta : metav1.ObjectMeta {
256
- Name : "bar " ,
256
+ Name : "bar0 " ,
257
257
},
258
258
}
259
259
260
- inMemoryMachineWithNodeProvisioned := & infrav1.InMemoryMachine {
260
+ inMemoryMachineWithNodeProvisioned1 := & infrav1.InMemoryMachine {
261
261
ObjectMeta : metav1.ObjectMeta {
262
- Name : "bar " ,
262
+ Name : "bar1 " ,
263
263
},
264
264
Spec : infrav1.InMemoryMachineSpec {
265
265
Behaviour : & infrav1.InMemoryMachineBehaviour {
@@ -313,7 +313,7 @@ func TestReconcileNormalEtcd(t *testing.T) {
313
313
314
314
manager := cmanager .New (scheme )
315
315
316
- host := "127.0.0.1"
316
+ host := "127.0.0.1" //nolint:goconst
317
317
wcmux , err := server .NewWorkloadClustersMux (manager , host , server.CustomPorts {
318
318
// NOTE: make sure to use ports different than other tests, so we can run tests in parallel
319
319
MinPort : server .DefaultMinPort + 1000 ,
@@ -332,15 +332,15 @@ func TestReconcileNormalEtcd(t *testing.T) {
332
332
r .CloudManager .AddResourceGroup (klog .KObj (cluster ).String ())
333
333
c := r .CloudManager .GetResourceGroup (klog .KObj (cluster ).String ()).GetClient ()
334
334
335
- res , err := r .reconcileNormalETCD (ctx , cluster , cpMachine , inMemoryMachineWithNodeProvisioned )
335
+ res , err := r .reconcileNormalETCD (ctx , cluster , cpMachine , inMemoryMachineWithNodeProvisioned1 )
336
336
g .Expect (err ).ToNot (HaveOccurred ())
337
337
g .Expect (res .IsZero ()).To (BeFalse ())
338
- g .Expect (conditions .IsFalse (inMemoryMachineWithNodeProvisioned , infrav1 .EtcdProvisionedCondition )).To (BeTrue ())
338
+ g .Expect (conditions .IsFalse (inMemoryMachineWithNodeProvisioned1 , infrav1 .EtcdProvisionedCondition )).To (BeTrue ())
339
339
340
340
got := & corev1.Pod {
341
341
ObjectMeta : metav1.ObjectMeta {
342
342
Namespace : metav1 .NamespaceSystem ,
343
- Name : fmt .Sprintf ("etcd-%s" , inMemoryMachineWithNodeNotYetProvisioned .Name ),
343
+ Name : fmt .Sprintf ("etcd-%s" , inMemoryMachineWithNodeProvisioned1 .Name ),
344
344
},
345
345
}
346
346
err = c .Get (ctx , client .ObjectKeyFromObject (got ), got )
@@ -350,32 +350,111 @@ func TestReconcileNormalEtcd(t *testing.T) {
350
350
g := NewWithT (t )
351
351
352
352
g .Eventually (func () bool {
353
- res , err := r .reconcileNormalETCD (ctx , cluster , cpMachine , inMemoryMachineWithNodeProvisioned )
353
+ res , err := r .reconcileNormalETCD (ctx , cluster , cpMachine , inMemoryMachineWithNodeProvisioned1 )
354
354
g .Expect (err ).ToNot (HaveOccurred ())
355
355
if ! res .IsZero () {
356
356
time .Sleep (res .RequeueAfter / 100 * 90 )
357
357
}
358
358
return res .IsZero ()
359
- }, inMemoryMachineWithNodeProvisioned .Spec .Behaviour .Etcd .Provisioning .StartupDuration .Duration * 2 ).Should (BeTrue ())
359
+ }, inMemoryMachineWithNodeProvisioned1 .Spec .Behaviour .Etcd .Provisioning .StartupDuration .Duration * 2 ).Should (BeTrue ())
360
360
361
361
err = c .Get (ctx , client .ObjectKeyFromObject (got ), got )
362
362
g .Expect (err ).ToNot (HaveOccurred ())
363
363
364
- g .Expect (conditions .IsTrue (inMemoryMachineWithNodeProvisioned , infrav1 .EtcdProvisionedCondition )).To (BeTrue ())
365
- g .Expect (conditions .Get (inMemoryMachineWithNodeProvisioned , infrav1 .EtcdProvisionedCondition ).LastTransitionTime .Time ).To (BeTemporally (">" , conditions .Get (inMemoryMachineWithNodeProvisioned , infrav1 .NodeProvisionedCondition ).LastTransitionTime .Time , inMemoryMachineWithNodeProvisioned .Spec .Behaviour .Etcd .Provisioning .StartupDuration .Duration ))
364
+ g .Expect (got .Annotations ).To (HaveKey (cloudv1 .EtcdClusterIDAnnotationName ))
365
+ g .Expect (got .Annotations ).To (HaveKey (cloudv1 .EtcdMemberIDAnnotationName ))
366
+ g .Expect (got .Annotations ).To (HaveKey (cloudv1 .EtcdLeaderFromAnnotationName ))
367
+
368
+ g .Expect (conditions .IsTrue (inMemoryMachineWithNodeProvisioned1 , infrav1 .EtcdProvisionedCondition )).To (BeTrue ())
369
+ g .Expect (conditions .Get (inMemoryMachineWithNodeProvisioned1 , infrav1 .EtcdProvisionedCondition ).LastTransitionTime .Time ).To (BeTemporally (">" , conditions .Get (inMemoryMachineWithNodeProvisioned1 , infrav1 .NodeProvisionedCondition ).LastTransitionTime .Time , inMemoryMachineWithNodeProvisioned1 .Spec .Behaviour .Etcd .Provisioning .StartupDuration .Duration ))
366
370
})
367
371
368
372
t .Run ("no-op after it is provisioned" , func (t * testing.T ) {
369
373
g := NewWithT (t )
370
374
371
- res , err := r .reconcileNormalETCD (ctx , cluster , cpMachine , inMemoryMachineWithNodeProvisioned )
375
+ res , err := r .reconcileNormalETCD (ctx , cluster , cpMachine , inMemoryMachineWithNodeProvisioned1 )
372
376
g .Expect (err ).ToNot (HaveOccurred ())
373
377
g .Expect (res .IsZero ()).To (BeTrue ())
374
378
})
375
379
376
380
err = wcmux .Shutdown (ctx )
377
381
g .Expect (err ).ToNot (HaveOccurred ())
378
382
})
383
+
384
+ t .Run ("takes care of the etcd cluster annotations" , func (t * testing.T ) {
385
+ g := NewWithT (t )
386
+
387
+ inMemoryMachineWithNodeProvisioned1 := inMemoryMachineWithNodeProvisioned1 .DeepCopy ()
388
+ inMemoryMachineWithNodeProvisioned1 .Spec = infrav1.InMemoryMachineSpec {}
389
+
390
+ inMemoryMachineWithNodeProvisioned2 := inMemoryMachineWithNodeProvisioned1 .DeepCopy ()
391
+ inMemoryMachineWithNodeProvisioned2 .Name = "bar2"
392
+
393
+ manager := cmanager .New (scheme )
394
+
395
+ host := "127.0.0.1"
396
+ wcmux , err := server .NewWorkloadClustersMux (manager , host , server.CustomPorts {
397
+ // NOTE: make sure to use ports different than other tests, so we can run tests in parallel
398
+ MinPort : server .DefaultMinPort + 1200 ,
399
+ MaxPort : server .DefaultMinPort + 1299 ,
400
+ DebugPort : server .DefaultDebugPort + 20 ,
401
+ })
402
+ g .Expect (err ).ToNot (HaveOccurred ())
403
+ _ , err = wcmux .InitWorkloadClusterListener (klog .KObj (cluster ).String ())
404
+ g .Expect (err ).ToNot (HaveOccurred ())
405
+
406
+ r := InMemoryMachineReconciler {
407
+ Client : fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (createCASecret (t , cluster , secretutil .EtcdCA )).Build (),
408
+ CloudManager : manager ,
409
+ APIServerMux : wcmux ,
410
+ }
411
+ r .CloudManager .AddResourceGroup (klog .KObj (cluster ).String ())
412
+ c := r .CloudManager .GetResourceGroup (klog .KObj (cluster ).String ()).GetClient ()
413
+
414
+ // first etcd pod gets annotated with clusterID, memberID, and also set as a leader
415
+
416
+ res , err := r .reconcileNormalETCD (ctx , cluster , cpMachine , inMemoryMachineWithNodeProvisioned1 )
417
+ g .Expect (err ).ToNot (HaveOccurred ())
418
+ g .Expect (res .IsZero ()).To (BeTrue ())
419
+ g .Expect (conditions .IsTrue (inMemoryMachineWithNodeProvisioned1 , infrav1 .EtcdProvisionedCondition )).To (BeTrue ())
420
+
421
+ got1 := & corev1.Pod {
422
+ ObjectMeta : metav1.ObjectMeta {
423
+ Namespace : metav1 .NamespaceSystem ,
424
+ Name : fmt .Sprintf ("etcd-%s" , inMemoryMachineWithNodeProvisioned1 .Name ),
425
+ },
426
+ }
427
+
428
+ err = c .Get (ctx , client .ObjectKeyFromObject (got1 ), got1 )
429
+ g .Expect (err ).ToNot (HaveOccurred ())
430
+
431
+ g .Expect (got1 .Annotations ).To (HaveKey (cloudv1 .EtcdClusterIDAnnotationName ))
432
+ g .Expect (got1 .Annotations ).To (HaveKey (cloudv1 .EtcdMemberIDAnnotationName ))
433
+ g .Expect (got1 .Annotations ).To (HaveKey (cloudv1 .EtcdLeaderFromAnnotationName ))
434
+
435
+ // second etcd pod gets annotated with the same clusterID, a new memberID (but it is not set as a leader
436
+
437
+ res , err = r .reconcileNormalETCD (ctx , cluster , cpMachine , inMemoryMachineWithNodeProvisioned2 )
438
+ g .Expect (err ).ToNot (HaveOccurred ())
439
+ g .Expect (res .IsZero ()).To (BeTrue ())
440
+ g .Expect (conditions .IsTrue (inMemoryMachineWithNodeProvisioned2 , infrav1 .EtcdProvisionedCondition )).To (BeTrue ())
441
+
442
+ got2 := & corev1.Pod {
443
+ ObjectMeta : metav1.ObjectMeta {
444
+ Namespace : metav1 .NamespaceSystem ,
445
+ Name : fmt .Sprintf ("etcd-%s" , inMemoryMachineWithNodeProvisioned2 .Name ),
446
+ },
447
+ }
448
+
449
+ err = c .Get (ctx , client .ObjectKeyFromObject (got2 ), got2 )
450
+ g .Expect (err ).ToNot (HaveOccurred ())
451
+
452
+ g .Expect (got2 .Annotations ).To (HaveKey (cloudv1 .EtcdClusterIDAnnotationName ))
453
+ g .Expect (got1 .Annotations [cloudv1 .EtcdClusterIDAnnotationName ]).To (Equal (got2 .Annotations [cloudv1 .EtcdClusterIDAnnotationName ]))
454
+ g .Expect (got2 .Annotations ).To (HaveKey (cloudv1 .EtcdMemberIDAnnotationName ))
455
+ g .Expect (got1 .Annotations [cloudv1 .EtcdMemberIDAnnotationName ]).ToNot (Equal (got2 .Annotations [cloudv1 .EtcdMemberIDAnnotationName ]))
456
+ g .Expect (got2 .Annotations ).ToNot (HaveKey (cloudv1 .EtcdLeaderFromAnnotationName ))
457
+ })
379
458
}
380
459
381
460
func TestReconcileNormalApiServer (t * testing.T ) {
0 commit comments