@@ -404,6 +404,13 @@ var _ = Describe("Reconciler", func() {
404404 }))
405405 })
406406 })
407+ _ = Describe ("WithPauseReconcileAnnotation" , func () {
408+ It ("should set the pauseReconcileAnnotation field to the annotation name" , func () {
409+ a := "my.domain/pause-reconcile"
410+ Expect (WithPauseReconcileAnnotation (a )(r )).To (Succeed ())
411+ Expect (r .pauseReconcileAnnotation ).To (Equal (a ))
412+ })
413+ })
407414 _ = Describe ("WithPreHook" , func () {
408415 It ("should set a reconciler prehook" , func () {
409416 called := false
@@ -545,6 +552,7 @@ var _ = Describe("Reconciler", func() {
545552 WithInstallAnnotations (annotation.InstallDescription {}),
546553 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
547554 WithUninstallAnnotations (annotation.UninstallDescription {}),
555+ WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
548556 WithOverrideValues (map [string ]string {
549557 "image.repository" : "custom-nginx" ,
550558 }),
@@ -559,6 +567,7 @@ var _ = Describe("Reconciler", func() {
559567 WithInstallAnnotations (annotation.InstallDescription {}),
560568 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
561569 WithUninstallAnnotations (annotation.UninstallDescription {}),
570+ WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
562571 WithOverrideValues (map [string ]string {
563572 "image.repository" : "custom-nginx" ,
564573 }),
@@ -1429,6 +1438,64 @@ var _ = Describe("Reconciler", func() {
14291438 verifyNoRelease (ctx , mgr .GetClient (), obj .GetNamespace (), obj .GetName (), currentRelease )
14301439 })
14311440
1441+ By ("ensuring the finalizer is removed and the CR is deleted" , func () {
1442+ err := mgr .GetAPIReader ().Get (ctx , objKey , obj )
1443+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1444+ })
1445+ })
1446+ })
1447+ When ("pause-reconcile annotation is present" , func () {
1448+ It ("pauses reconciliation" , func () {
1449+ By ("adding the pause-reconcile annotation to the CR" , func () {
1450+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1451+ obj .SetAnnotations (map [string ]string {"my.domain/pause-reconcile" : "true" })
1452+ obj .Object ["spec" ] = map [string ]interface {}{"replicaCount" : "666" }
1453+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1454+ })
1455+
1456+ By ("deleting the CR" , func () {
1457+ Expect (mgr .GetClient ().Delete (ctx , obj )).To (Succeed ())
1458+ })
1459+
1460+ By ("successfully reconciling a request when paused" , func () {
1461+ res , err := r .Reconcile (ctx , req )
1462+ Expect (res ).To (Equal (reconcile.Result {}))
1463+ Expect (err ).ToNot (HaveOccurred ())
1464+ })
1465+
1466+ By ("getting the CR" , func () {
1467+ Expect (mgr .GetAPIReader ().Get (ctx , objKey , obj )).To (Succeed ())
1468+ })
1469+
1470+ By ("verifying the CR status is Paused" , func () {
1471+ objStat := & objStatus {}
1472+ Expect (runtime .DefaultUnstructuredConverter .FromUnstructured (obj .Object , objStat )).To (Succeed ())
1473+ Expect (objStat .Status .Conditions .IsTrueFor (conditions .TypePaused )).To (BeTrue ())
1474+ })
1475+
1476+ By ("verifying the release has not changed" , func () {
1477+ rel , err := ac .Get (obj .GetName ())
1478+ Expect (err ).ToNot (HaveOccurred ())
1479+ Expect (rel ).NotTo (BeNil ())
1480+ Expect (* rel ).To (Equal (* currentRelease ))
1481+ })
1482+
1483+ By ("removing the pause-reconcile annotation from the CR" , func () {
1484+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1485+ obj .SetAnnotations (nil )
1486+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1487+ })
1488+
1489+ By ("successfully reconciling a request" , func () {
1490+ res , err := r .Reconcile (ctx , req )
1491+ Expect (res ).To (Equal (reconcile.Result {}))
1492+ Expect (err ).ToNot (HaveOccurred ())
1493+ })
1494+
1495+ By ("verifying the release is uninstalled" , func () {
1496+ verifyNoRelease (ctx , mgr .GetClient (), obj .GetNamespace (), obj .GetName (), currentRelease )
1497+ })
1498+
14321499 By ("ensuring the finalizer is removed and the CR is deleted" , func () {
14331500 err := mgr .GetAPIReader ().Get (ctx , objKey , obj )
14341501 Expect (apierrors .IsNotFound (err )).To (BeTrue ())
0 commit comments