@@ -394,6 +394,13 @@ var _ = Describe("Reconciler", func() {
394394 }))
395395 })
396396 })
397+ _ = Describe ("WithPauseReconcileAnnotation" , func () {
398+ It ("should set the pauseReconcileAnnotation field to the annotation name" , func () {
399+ a := "my.domain/pause-reconcile"
400+ Expect (WithPauseReconcileAnnotation (a )(r )).To (Succeed ())
401+ Expect (r .pauseReconcileAnnotation ).To (Equal (a ))
402+ })
403+ })
397404 _ = Describe ("WithPreHook" , func () {
398405 It ("should set a reconciler prehook" , func () {
399406 called := false
@@ -535,6 +542,7 @@ var _ = Describe("Reconciler", func() {
535542 WithInstallAnnotations (annotation.InstallDescription {}),
536543 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
537544 WithUninstallAnnotations (annotation.UninstallDescription {}),
545+ WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
538546 WithOverrideValues (map [string ]string {
539547 "image.repository" : "custom-nginx" ,
540548 }),
@@ -549,6 +557,7 @@ var _ = Describe("Reconciler", func() {
549557 WithInstallAnnotations (annotation.InstallDescription {}),
550558 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
551559 WithUninstallAnnotations (annotation.UninstallDescription {}),
560+ WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
552561 WithOverrideValues (map [string ]string {
553562 "image.repository" : "custom-nginx" ,
554563 }),
@@ -1419,6 +1428,64 @@ var _ = Describe("Reconciler", func() {
14191428 verifyNoRelease (ctx , mgr .GetClient (), obj .GetNamespace (), obj .GetName (), currentRelease )
14201429 })
14211430
1431+ By ("ensuring the finalizer is removed and the CR is deleted" , func () {
1432+ err := mgr .GetAPIReader ().Get (ctx , objKey , obj )
1433+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1434+ })
1435+ })
1436+ })
1437+ When ("pause-reconcile annotation is present" , func () {
1438+ It ("pauses reconciliation" , func () {
1439+ By ("adding the pause-reconcile annotation to the CR" , func () {
1440+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1441+ obj .SetAnnotations (map [string ]string {"my.domain/pause-reconcile" : "true" })
1442+ obj .Object ["spec" ] = map [string ]interface {}{"replicaCount" : "666" }
1443+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1444+ })
1445+
1446+ By ("deleting the CR" , func () {
1447+ Expect (mgr .GetClient ().Delete (ctx , obj )).To (Succeed ())
1448+ })
1449+
1450+ By ("successfully reconciling a request when paused" , func () {
1451+ res , err := r .Reconcile (ctx , req )
1452+ Expect (res ).To (Equal (reconcile.Result {}))
1453+ Expect (err ).ToNot (HaveOccurred ())
1454+ })
1455+
1456+ By ("getting the CR" , func () {
1457+ Expect (mgr .GetAPIReader ().Get (ctx , objKey , obj )).To (Succeed ())
1458+ })
1459+
1460+ By ("verifying the CR status is Paused" , func () {
1461+ objStat := & objStatus {}
1462+ Expect (runtime .DefaultUnstructuredConverter .FromUnstructured (obj .Object , objStat )).To (Succeed ())
1463+ Expect (objStat .Status .Conditions .IsTrueFor (conditions .TypePaused )).To (BeTrue ())
1464+ })
1465+
1466+ By ("verifying the release has not changed" , func () {
1467+ rel , err := ac .Get (obj .GetName ())
1468+ Expect (err ).ToNot (HaveOccurred ())
1469+ Expect (rel ).NotTo (BeNil ())
1470+ Expect (* rel ).To (Equal (* currentRelease ))
1471+ })
1472+
1473+ By ("removing the pause-reconcile annotation from the CR" , func () {
1474+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1475+ obj .SetAnnotations (nil )
1476+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1477+ })
1478+
1479+ By ("successfully reconciling a request" , func () {
1480+ res , err := r .Reconcile (ctx , req )
1481+ Expect (res ).To (Equal (reconcile.Result {}))
1482+ Expect (err ).ToNot (HaveOccurred ())
1483+ })
1484+
1485+ By ("verifying the release is uninstalled" , func () {
1486+ verifyNoRelease (ctx , mgr .GetClient (), obj .GetNamespace (), obj .GetName (), currentRelease )
1487+ })
1488+
14221489 By ("ensuring the finalizer is removed and the CR is deleted" , func () {
14231490 err := mgr .GetAPIReader ().Get (ctx , objKey , obj )
14241491 Expect (apierrors .IsNotFound (err )).To (BeTrue ())
0 commit comments