@@ -385,6 +385,13 @@ var _ = Describe("Reconciler", func() {
385385 }))
386386 })
387387 })
388+ var _ = Describe ("WithPauseReconcileAnnotation" , func () {
389+ It ("should set the pauseReconcileAnnotation field to the annotation name" , func () {
390+ a := "my.domain/pause-reconcile"
391+ Expect (WithPauseReconcileAnnotation (a )(r )).To (Succeed ())
392+ Expect (r .pauseReconcileAnnotation ).To (Equal (a ))
393+ })
394+ })
388395 var _ = Describe ("WithPreHook" , func () {
389396 It ("should set a reconciler prehook" , func () {
390397 called := false
@@ -527,6 +534,7 @@ var _ = Describe("Reconciler", func() {
527534 WithInstallAnnotations (annotation.InstallDescription {}),
528535 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
529536 WithUninstallAnnotations (annotation.UninstallDescription {}),
537+ WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
530538 WithOverrideValues (map [string ]string {
531539 "image.repository" : "custom-nginx" ,
532540 }),
@@ -541,6 +549,7 @@ var _ = Describe("Reconciler", func() {
541549 WithInstallAnnotations (annotation.InstallDescription {}),
542550 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
543551 WithUninstallAnnotations (annotation.UninstallDescription {}),
552+ WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
544553 WithOverrideValues (map [string ]string {
545554 "image.repository" : "custom-nginx" ,
546555 }),
@@ -1319,6 +1328,64 @@ var _ = Describe("Reconciler", func() {
13191328 verifyNoRelease (ctx , mgr .GetClient (), obj .GetNamespace (), obj .GetName (), currentRelease )
13201329 })
13211330
1331+ By ("ensuring the finalizer is removed and the CR is deleted" , func () {
1332+ err := mgr .GetAPIReader ().Get (ctx , objKey , obj )
1333+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1334+ })
1335+ })
1336+ })
1337+ When ("pause-reconcile annotation is present" , func () {
1338+ It ("pauses reconciliation" , func () {
1339+ By ("adding the pause-reconcile annotation to the CR" , func () {
1340+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1341+ obj .SetAnnotations (map [string ]string {"my.domain/pause-reconcile" : "true" })
1342+ obj .Object ["spec" ] = map [string ]interface {}{"replicaCount" : "666" }
1343+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1344+ })
1345+
1346+ By ("deleting the CR" , func () {
1347+ Expect (mgr .GetClient ().Delete (ctx , obj )).To (Succeed ())
1348+ })
1349+
1350+ By ("successfully reconciling a request when paused" , func () {
1351+ res , err := r .Reconcile (ctx , req )
1352+ Expect (res ).To (Equal (reconcile.Result {}))
1353+ Expect (err ).To (BeNil ())
1354+ })
1355+
1356+ By ("getting the CR" , func () {
1357+ Expect (mgr .GetAPIReader ().Get (ctx , objKey , obj )).To (Succeed ())
1358+ })
1359+
1360+ By ("verifying the CR status is Paused" , func () {
1361+ objStat := & objStatus {}
1362+ Expect (runtime .DefaultUnstructuredConverter .FromUnstructured (obj .Object , objStat )).To (Succeed ())
1363+ Expect (objStat .Status .Conditions .IsTrueFor (conditions .TypePaused )).To (BeTrue ())
1364+ })
1365+
1366+ By ("verifying the release has not changed" , func () {
1367+ rel , err := ac .Get (obj .GetName ())
1368+ Expect (err ).To (BeNil ())
1369+ Expect (rel ).NotTo (BeNil ())
1370+ Expect (* rel ).To (Equal (* currentRelease ))
1371+ })
1372+
1373+ By ("removing the pause-reconcile annotation from the CR" , func () {
1374+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1375+ obj .SetAnnotations (nil )
1376+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1377+ })
1378+
1379+ By ("successfully reconciling a request" , func () {
1380+ res , err := r .Reconcile (ctx , req )
1381+ Expect (res ).To (Equal (reconcile.Result {}))
1382+ Expect (err ).To (BeNil ())
1383+ })
1384+
1385+ By ("verifying the release is uninstalled" , func () {
1386+ verifyNoRelease (ctx , mgr .GetClient (), obj .GetNamespace (), obj .GetName (), currentRelease )
1387+ })
1388+
13221389 By ("ensuring the finalizer is removed and the CR is deleted" , func () {
13231390 err := mgr .GetAPIReader ().Get (ctx , objKey , obj )
13241391 Expect (apierrors .IsNotFound (err )).To (BeTrue ())
0 commit comments