@@ -1365,6 +1365,8 @@ var _ = Describe("With a running MachineSync Reconciler", func() {
13651365 })
13661366
13671367 FContext ("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
13681370 BeforeEach (func () {
13691371 By ("Waiting for VAP to be ready" )
13701372 machineVap = & admissionregistrationv1.ValidatingAdmissionPolicy {}
@@ -1406,14 +1408,20 @@ var _ = Describe("With a running MachineSync Reconciler", func() {
14061408 sentinelMachine := mapiMachineBuilder .WithName ("sentinel-machine" ).WithAuthoritativeAPI (mapiv1beta1 .MachineAuthorityClusterAPI ).Build ()
14071409 Eventually (k8sClient .Create (ctx , sentinelMachine ), timeout ).Should (Succeed ())
14081410
1409- capiSentinelMachine := clusterv1resourcebuilder .Machine ().WithName ("sentinel-machine" ).WithNamespace (capiNamespace .Name ).Build ()
1410- Expect (k8sClient .Create (ctx , capiSentinelMachine )).To (Succeed ())
1411+ var err error
1412+ warnClient , warnSink , err = admissiontestutils .SetupClientWithWarningCollector (cfg , testScheme )
1413+ Expect (err ).To (Not (HaveOccurred ()))
14111414
1412- Eventually (k .Get (capiSentinelMachine )).Should (Succeed ())
1415+ // TODO: I don't know if doing this, or setting the komega client
1416+ // to be the warnClient (then unsetting it with DeferCleanup()) is better
1417+ Eventually (func (g Gomega ) {
1418+ warnSink .Reset () // keep each probe self-contained
14131419
1414- Eventually (k .Update (sentinelMachine , func () {
14151420 sentinelMachine .ObjectMeta .Labels = map [string ]string {"test-sentinel" : "fubar" }
1416- }), timeout ).Should (Succeed ())
1421+ g .Expect (warnClient .Update (ctx , sentinelMachine )).To (Succeed ())
1422+ g .Expect (warnSink .Messages ()).To (ContainElement (ContainSubstring ("policy in place" )))
1423+ }, timeout ).Should (Succeed ())
1424+
14171425 })
14181426
14191427 It ("warns the user when the machine is still synchronzing" , func () {
@@ -1430,10 +1438,14 @@ var _ = Describe("With a running MachineSync Reconciler", func() {
14301438 }
14311439 })).Should (Succeed ())
14321440
1433- By ("Attempting to update the authoritativeAPI should be blocked" )
1434- Eventually (k .Update (mapiMachine , func () {
1441+ By ("Attempting to update the authoritativeAPI should emit a warning" )
1442+ Eventually (func (g Gomega ) {
1443+ warnSink .Reset () // keep each probe self-contained
1444+
14351445 mapiMachine .Spec .AuthoritativeAPI = mapiv1beta1 .MachineAuthorityClusterAPI
1436- }), timeout ).Should (Succeed ()) // This should succeed but show a warning?
1446+ g .Expect (warnClient .Update (ctx , mapiMachine )).To (Succeed ())
1447+ g .Expect (warnSink .Messages ()).To (ContainElement (ContainSubstring ("updating .spec.authoritativeAPI when Synchronized=false on resource means changes may not take effect" )))
1448+ }, timeout ).Should (Succeed ())
14371449 })
14381450
14391451 })
0 commit comments