@@ -1364,7 +1364,11 @@ var _ = Describe("With a running MachineSync Reconciler", func() {
13641364
13651365		})
13661366
1367- 		FContext ("Updates to MAPI machine warns user if the Synchronized condition is set to false" , func () {
1367+ 		Context ("Updates to MAPI machine warns user if the Synchronized condition is set to false" , func () {
1368+ 			var  warnClient  client.Client 
1369+ 			var  warnSink  * admissiontestutils.WarningCollector 
1370+ 			var  warnKomega  komega.Komega 
1371+ 
13681372			BeforeEach (func () {
13691373				By ("Waiting for VAP to be ready" )
13701374				machineVap  =  & admissionregistrationv1.ValidatingAdmissionPolicy {}
@@ -1406,17 +1410,26 @@ var _ = Describe("With a running MachineSync Reconciler", func() {
14061410				sentinelMachine  :=  mapiMachineBuilder .WithName ("sentinel-machine" ).WithAuthoritativeAPI (mapiv1beta1 .MachineAuthorityClusterAPI ).Build ()
14071411				Eventually (k8sClient .Create (ctx , sentinelMachine ), timeout ).Should (Succeed ())
14081412
1409- 				capiSentinelMachine  :=  clusterv1resourcebuilder .Machine ().WithName ("sentinel-machine" ).WithNamespace (capiNamespace .Name ).Build ()
1410- 				Expect (k8sClient .Create (ctx , capiSentinelMachine )).To (Succeed ())
1413+ 				var  err  error 
1414+ 				warnClient , warnSink , err  =  admissiontestutils .SetupClientWithWarningCollector (cfg , testScheme )
1415+ 				Expect (err ).To (Not (HaveOccurred ()))
14111416
1412- 				Eventually (k .Get (capiSentinelMachine )).Should (Succeed ())
1417+ 				warnKomega  =  komega .New (warnClient )
1418+ 
1419+ 				Eventually (func (g  Gomega ) {
1420+ 					warnSink .Reset () // keep each probe self-contained 
1421+ 
1422+ 					err  :=  warnKomega .Update (sentinelMachine , func () {
1423+ 						sentinelMachine .ObjectMeta .Labels  =  map [string ]string {"test-sentinel" : "fubar" }
1424+ 					})()
1425+ 					g .Expect (err ).NotTo (HaveOccurred ())
1426+ 
1427+ 					g .Expect (warnSink .Messages ()).To (ContainElement (ContainSubstring ("policy in place" )))
1428+ 				}, timeout ).Should (Succeed ())
14131429
1414- 				Eventually (k .Update (sentinelMachine , func () {
1415- 					sentinelMachine .ObjectMeta .Labels  =  map [string ]string {"test-sentinel" : "fubar" }
1416- 				}), timeout ).Should (Succeed ())
14171430			})
14181431
1419- 			It ("warns the user when the machine is still synchronzing " , func () {
1432+ 			It ("warns the user when the machine is still synchronizing " , func () {
14201433				By ("Setting the Synchronized condition to False" )
14211434				Eventually (k .UpdateStatus (mapiMachine , func () {
14221435					mapiMachine .Status .Conditions  =  []mapiv1beta1.Condition {
@@ -1430,12 +1443,63 @@ var _ = Describe("With a running MachineSync Reconciler", func() {
14301443					}
14311444				})).Should (Succeed ())
14321445
1433- 				By ("Attempting to update the authoritativeAPI should be blocked" )
1434- 				Eventually (k .Update (mapiMachine , func () {
1435- 					mapiMachine .Spec .AuthoritativeAPI  =  mapiv1beta1 .MachineAuthorityClusterAPI 
1436- 				}), timeout ).Should (Succeed ()) // This should succeed but show a warning? 
1446+ 				By ("Attempting to update the authoritativeAPI should emit a warning" )
1447+ 				Eventually (func (g  Gomega ) {
1448+ 					warnSink .Reset () // keep each probe self-contained 
1449+ 
1450+ 					err  :=  warnKomega .Update (mapiMachine , func () {
1451+ 						mapiMachine .Spec .AuthoritativeAPI  =  mapiv1beta1 .MachineAuthorityClusterAPI 
1452+ 					})()
1453+ 					g .Expect (err ).NotTo (HaveOccurred ())
1454+ 
1455+ 					g .Expect (warnSink .Messages ()).To (ContainElement (ContainSubstring ("updating .spec.authoritativeAPI when Synchronized=false on resource means changes may not take effect" )))
1456+ 				}, timeout ).Should (Succeed ())
14371457			})
1458+ 			It ("warns the user when the machine synchronisation is unknown" , func () {
1459+ 				By ("Setting the Synchronized condition to Unknown" )
1460+ 				Eventually (k .UpdateStatus (mapiMachine , func () {
1461+ 					mapiMachine .Status .Conditions  =  []mapiv1beta1.Condition {
1462+ 						{
1463+ 							Type :               consts .SynchronizedCondition ,
1464+ 							Status :             corev1 .ConditionUnknown ,
1465+ 							Reason :             "ErrorReason" ,
1466+ 							Message :            "Error message" ,
1467+ 							LastTransitionTime : metav1 .Now (),
1468+ 						},
1469+ 					}
1470+ 				})).Should (Succeed ())
1471+ 
1472+ 				By ("Attempting to update the authoritativeAPI should emit a warning" )
1473+ 				Eventually (func (g  Gomega ) {
1474+ 					warnSink .Reset () // keep each probe self-contained 
14381475
1476+ 					err  :=  warnKomega .Update (mapiMachine , func () {
1477+ 						mapiMachine .Spec .AuthoritativeAPI  =  mapiv1beta1 .MachineAuthorityClusterAPI 
1478+ 					})()
1479+ 					g .Expect (err ).NotTo (HaveOccurred ())
1480+ 
1481+ 					g .Expect (warnSink .Messages ()).To (ContainElement (ContainSubstring ("updating .spec.authoritativeAPI when Synchronized=false on resource means changes may not take effect" )))
1482+ 				}, timeout ).Should (Succeed ())
1483+ 			})
1484+ 
1485+ 			It ("warns the user when the machine has no synchronized condition" , func () {
1486+ 				By ("Setting the conditions to empty" )
1487+ 				Eventually (k .UpdateStatus (mapiMachine , func () {
1488+ 					mapiMachine .Status .Conditions  =  []mapiv1beta1.Condition {}
1489+ 				})).Should (Succeed ())
1490+ 
1491+ 				By ("Attempting to update the authoritativeAPI should emit a warning" )
1492+ 				Eventually (func (g  Gomega ) {
1493+ 					warnSink .Reset () // keep each probe self-contained 
1494+ 
1495+ 					err  :=  warnKomega .Update (mapiMachine , func () {
1496+ 						mapiMachine .Spec .AuthoritativeAPI  =  mapiv1beta1 .MachineAuthorityClusterAPI 
1497+ 					})()
1498+ 					g .Expect (err ).NotTo (HaveOccurred ())
1499+ 
1500+ 					g .Expect (warnSink .Messages ()).To (ContainElement (ContainSubstring ("updating .spec.authoritativeAPI when Synchronized=false on resource means changes may not take effect" )))
1501+ 				}, timeout ).Should (Succeed ())
1502+ 			})
14391503		})
14401504
14411505	})
0 commit comments